Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Sep 28, 2023
1 parent 18f2130 commit aada00a
Showing 1 changed file with 13 additions and 36 deletions.
49 changes: 13 additions & 36 deletions lib/net/smtp/auth_net_imap_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit aada00a

Please sign in to comment.