From aada00a87b4750f4c15fd679c1cb199dd7b6abe4 Mon Sep 17 00:00:00 2001 From: nick evans Date: Wed, 27 Sep 2023 21:34:48 -0400 Subject: [PATCH] WIP --- lib/net/smtp/auth_net_imap_adapter.rb | 49 +++++++-------------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/lib/net/smtp/auth_net_imap_adapter.rb b/lib/net/smtp/auth_net_imap_adapter.rb index c1bc57f..ad2772b 100644 --- a/lib/net/smtp/auth_net_imap_adapter.rb +++ b/lib/net/smtp/auth_net_imap_adapter.rb @@ -8,6 +8,15 @@ class Authenticator # # Initialize with a block that runs a command, yielding for continuations. class SASLAdapter < SASL::ClientAdapter + COMMAND_NAME = "AUTH" + RESPONSE_ERRORS = [ + SMTPAuthenticationError, + SMTPServerBusy, + SMTPSyntaxError, + SMTPFatalError, + SMTPUnsupportedCommand + ].freeze + def self.authenticate(client, mechanism, *args, **kwargs, &block) sasl = SASL.authenticator(mechanism, *args, **kwargs, &block) adapter = new(client, mechanism, sasl) @@ -17,45 +26,13 @@ def self.authenticate(client, mechanism, *args, **kwargs, &block) def initialize(...) super @send_command_proc ||= client - .method(:send_command_yielding_continuations) - end - - def server_supports_initial_response?; true end - def server_supports_mechanism? - client.__send__(:auth_capable?, mechanism) + .method(:send_command_yielding_continuations) end - def auth_command_args(initial_response = nil) - ["AUTH", mechanism, initial_response].compact - end + def supports_initial_response?; true end - # Logs out for any error, except for SMTP failure codes. - def around_authenticate - res = yield - rescue SASL::AuthenticationFailed => ex - # The server failed authentication. - if res - raise res.exception_class.new(res) - else - raise ex - end - rescue SMTPAuthenticationError, - SMTPServerBusy, - SMTPSyntaxError, - SMTPFatalError, - SMTPUnsupportedCommand - # An error occurred, but the connection should be okay to try again. - raise - rescue - # Either: - # * The server says we're OK without completing the exchange. - # * The server sent invalid challenges. - # * The server failed to authenticate itself to us. - # * An unknown and unhandled error occurred. - # - # The connection may not be safe to continue using. - client.finish - raise + def supports_mechanism? + client.__send__(:auth_capable?, mechanism) end def handle_incomplete(res)