Skip to content

Commit

Permalink
Reimplement #authenticate using #auth
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Oct 11, 2023
1 parent 7f2ff25 commit 6cf07a4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/net/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,9 @@ def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
DEFAULT_AUTH_TYPE = :plain

# call-seq:
# authenticate(type: DEFAULT_AUTH_TYPE, **, &)
# authenticate(type = DEFAULT_AUTH_TYPE, **, &)
# authenticate(username, secret, type: DEFAULT_AUTH_TYPE, **, &)
# authenticate(username, secret, type = DEFAULT_AUTH_TYPE, **, &)
#
# Authenticates with the server, using the "AUTH" command.
Expand All @@ -849,11 +852,17 @@ def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream
# All arguments—other than +type+—are forwarded to the authenticator.
# Different authenticators may interpret the +username+ and +secret+
# arguments differently.
def authenticate(user, secret, authtype = DEFAULT_AUTH_TYPE)
check_auth_method authtype
check_auth_args user, secret
authenticator = Authenticator.auth_class(authtype).new(self)
critical { authenticator.auth(user, secret) }
#
# #authenticate always sends either two positional arguments to the
# authenticator or none. Use #auth to send a different number of arguments.
def authenticate(*args, **kwargs, &block)
case args.length
when 1, 3 then authtype = args.pop
when (4..)
raise ArgumentError, "wrong number of arguments " \
"(given %d, expected 0..3)" % [args.length]
end
auth(authtype, *args, **kwargs, &block)
end

# call-seq:
Expand Down

0 comments on commit 6cf07a4

Please sign in to comment.