Skip to content

Commit

Permalink
Add type keyword arg to #authenticate
Browse files Browse the repository at this point in the history
This is convenient for `smtp.start auth: {type:, **etc}`.
  • Loading branch information
nevans committed Apr 9, 2024
1 parent 54ae43d commit a47a7c3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/net/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -879,12 +879,14 @@ 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, **, &)
# 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.
#
# +authtype+ is the name of a SASL authentication mechanism.
# +type+ 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+
Expand All @@ -896,19 +898,19 @@ def authenticate(*args, **kwargs, &block)
raise ArgumentError, "wrong number of arguments " \
"(given %d, expected 0..3)" % [args.length]
end
authtype ||= DEFAULT_AUTH_TYPE
check_auth_args authtype, *args, **kwargs
authtype, args, kwargs = check_auth_args authtype, *args, **kwargs
authenticator = Authenticator.auth_class(authtype).new(self)
authenticator.auth(*args, **kwargs, &block)
end

private

def check_auth_args(type, *args, **kwargs)
type ||= DEFAULT_AUTH_TYPE
def check_auth_args(type_arg = nil, *args, type: nil, **kwargs)
type ||= type_arg || DEFAULT_AUTH_TYPE
klass = Authenticator.auth_class(type) or
raise ArgumentError, "wrong authentication type #{type}"
klass.check_args(*args, **kwargs)
[type, args, kwargs]
end

#
Expand Down

0 comments on commit a47a7c3

Please sign in to comment.