From 8839be08c55fe7e4f65f892ca4dd24e62e30671d Mon Sep 17 00:00:00 2001 From: nick evans Date: Sat, 25 May 2024 08:57:11 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Use=20client=20config=20for=20de?= =?UTF-8?q?bug=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lib/net/imap.rb | 6 ++---- lib/net/imap/response_parser/parser_utils.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/net/imap.rb b/lib/net/imap.rb index 2940fff2a..d57c2e652 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -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 @@ -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) @@ -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 diff --git a/lib/net/imap/response_parser/parser_utils.rb b/lib/net/imap/response_parser/parser_utils.rb index d458ede7c..bc84bed99 100644 --- a/lib/net/imap/response_parser/parser_utils.rb +++ b/lib/net/imap/response_parser/parser_utils.rb @@ -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", @@ -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) $~ @@ -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]