Skip to content

Commit

Permalink
🔧 Use client config for debug mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nevans committed Jun 10, 2024
1 parent 080b5aa commit 8839be0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2609,8 +2609,6 @@ def remove_response_handler(handler)
PORT = 143 # :nodoc:
SSL_PORT = 993 # :nodoc:

@@debug = false

def start_imap_connection
@greeting = get_server_greeting
@capabilities = capabilities_from_resp_code @greeting
Expand Down Expand Up @@ -2755,7 +2753,7 @@ def get_response
end
end
return nil if buff.length == 0
if @@debug
if config.debug?
$stderr.print(buff.gsub(/^/n, "S: "))
end
return @parser.parse(buff)
Expand Down Expand Up @@ -2834,7 +2832,7 @@ def generate_tag

def put_string(str)
@sock.print(str)
if @@debug
if config.debug?
if @debug_output_bol
$stderr.print("C: ")
end
Expand Down
12 changes: 6 additions & 6 deletions lib/net/imap/response_parser/parser_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def accept(*args)
end

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

def peek_str?(str)
assert_no_lookahead if Net::IMAP.debug
assert_no_lookahead if config.debug?
@str[@pos, str.length] == str
end

def peek_re(re)
assert_no_lookahead if Net::IMAP.debug
assert_no_lookahead if config.debug?
re.match(@str, @pos)
end

def accept_re(re)
assert_no_lookahead if Net::IMAP.debug
assert_no_lookahead if config.debug?
re.match(@str, @pos) and @pos = $~.end(0)
$~
end

def match_re(re, name)
assert_no_lookahead if Net::IMAP.debug
assert_no_lookahead if config.debug?
if re.match(@str, @pos)
@pos = $~.end(0)
$~
Expand All @@ -212,7 +212,7 @@ def shift_token

def parse_error(fmt, *args)
msg = format(fmt, *args)
if IMAP.debug
if config.debug?
local_path = File.dirname(__dir__)
tok = @token ? "%s: %p" % [@token.symbol, @token.value] : "nil"
warn "%s %s: %s" % [self.class, __method__, msg]
Expand Down

0 comments on commit 8839be0

Please sign in to comment.