Skip to content

Commit

Permalink
Do not require positional args for #authenticate
Browse files Browse the repository at this point in the history
This API is a little bit confusing, IMO.  But it does preserve backward
compatibility, while allowing authenticators that don't allow positional
parameters to work without crashing.  But, authenticators that require
only one parameter—or more than three—will still be inaccessible.
  • Loading branch information
nevans committed Nov 7, 2023
1 parent c933c3e commit 6be96ea
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/net/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -878,17 +878,28 @@ def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream

DEFAULT_AUTH_TYPE = :plain

# call-seq:
# authenticate(authtype = DEFAULT_AUTH_TYPE, **, &)
# authenticate(username, secret, authtype = DEFAULT_AUTH_TYPE, **, &)
#
# Authenticates with the server, using the "AUTH" command.
#
# +authtype+ is the name of a SASL authentication mechanism.
#
# All arguments—other than +authtype+—are forwarded to the authenticator.
# Different authenticators may interpret the +username+ and +secret+
# arguments differently.
def authenticate(username, secret, authtype = DEFAULT_AUTH_TYPE, **kwargs, &block)
check_auth_args authtype, username, secret, **kwargs
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
authtype ||= DEFAULT_AUTH_TYPE
check_auth_args authtype, *args, **kwargs
authenticator = Authenticator.auth_class(authtype).new(self)
authenticator.auth(username, secret, **kwargs, &block)
authenticator.auth(*args, **kwargs, &block)
end

private
Expand Down

0 comments on commit 6be96ea

Please sign in to comment.