Skip to content

Commit f971c6c

Browse files
committed
🔧 Use client config for debug mode
In Net::IMAP, the `@@debug` cvar is replaced by `config.debug?`. And in ResponseParser, references to the global `Net::IMAP.debug` is replaced by `config.debug?`. By default, the client's own config won't have a value set for `debug`, so it will still inherit from the global `Net::IMAP.config.debug?`. Since the parser "belongs" to a client, it uses the client's configuration rather than simply following the global debug mode.
1 parent f49c3cf commit f971c6c

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

lib/net/imap.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,8 +2609,6 @@ def remove_response_handler(handler)
26092609
PORT = 143 # :nodoc:
26102610
SSL_PORT = 993 # :nodoc:
26112611

2612-
@@debug = false
2613-
26142612
def start_imap_connection
26152613
@greeting = get_server_greeting
26162614
@capabilities = capabilities_from_resp_code @greeting
@@ -2755,7 +2753,7 @@ def get_response
27552753
end
27562754
end
27572755
return nil if buff.length == 0
2758-
if @@debug
2756+
if config.debug?
27592757
$stderr.print(buff.gsub(/^/n, "S: "))
27602758
end
27612759
return @parser.parse(buff)
@@ -2834,7 +2832,7 @@ def generate_tag
28342832

28352833
def put_string(str)
28362834
@sock.print(str)
2837-
if @@debug
2835+
if config.debug?
28382836
if @debug_output_bol
28392837
$stderr.print("C: ")
28402838
end

lib/net/imap/response_parser/parser_utils.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def accept(*args)
154154
end
155155

156156
# To be used conditionally:
157-
# assert_no_lookahead if Net::IMAP.debug
157+
# assert_no_lookahead if config.debug?
158158
def assert_no_lookahead
159159
@token.nil? or
160160
parse_error("assertion failed: expected @token.nil?, actual %s: %p",
@@ -181,23 +181,23 @@ def lookahead!(*args)
181181
end
182182

183183
def peek_str?(str)
184-
assert_no_lookahead if Net::IMAP.debug
184+
assert_no_lookahead if config.debug?
185185
@str[@pos, str.length] == str
186186
end
187187

188188
def peek_re(re)
189-
assert_no_lookahead if Net::IMAP.debug
189+
assert_no_lookahead if config.debug?
190190
re.match(@str, @pos)
191191
end
192192

193193
def accept_re(re)
194-
assert_no_lookahead if Net::IMAP.debug
194+
assert_no_lookahead if config.debug?
195195
re.match(@str, @pos) and @pos = $~.end(0)
196196
$~
197197
end
198198

199199
def match_re(re, name)
200-
assert_no_lookahead if Net::IMAP.debug
200+
assert_no_lookahead if config.debug?
201201
if re.match(@str, @pos)
202202
@pos = $~.end(0)
203203
$~
@@ -212,7 +212,7 @@ def shift_token
212212

213213
def parse_error(fmt, *args)
214214
msg = format(fmt, *args)
215-
if IMAP.debug
215+
if config.debug?
216216
local_path = File.dirname(__dir__)
217217
tok = @token ? "%s: %p" % [@token.symbol, @token.value] : "nil"
218218
warn "%s %s: %s" % [self.class, __method__, msg]

0 commit comments

Comments
 (0)