Skip to content

Commit

Permalink
Make #authenticate delegate to #auth, sometimes
Browse files Browse the repository at this point in the history
Attempting to retain backward compatibility with the v0.4.0.
  • Loading branch information
nevans committed Oct 9, 2023
1 parent 7bb1876 commit 6bc08a3
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions lib/net/smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -874,11 +874,36 @@ def open_message_stream(from_addr, *to_addrs, &block) # :yield: stream

DEFAULT_AUTH_TYPE = :plain

# Deprecated: use #auth instead.
def authenticate(user, secret, authtype = DEFAULT_AUTH_TYPE)
# warn "DEPRECATED: use Net::SMTP#auth instead"
authenticator = Authenticator.auth_class(authtype).new(self)
critical { authenticator.auth(user, secret) }
# call-seq:
# authenticate(**kwargs, &block)
# authenticate(authtype, **kwargs, &block)
# authenticate(username, secret, authtype = DEFAULT_AUTH_TYPE)
#
# If zero or one positional arguments are provided, all arguments are
# forwarded #auth.
#
# If two or three positional arguments are provided, they are +username+,
# +secret+, and an optional +authtype+. Keyword parameters cannot be
# used with this form. The +username+ and +secret+ arguments may be
# interpreted differently, based on +authtype+. This form supports
# Authenticator subclasses, for backward compatibility.
def authenticate(*args, **kwargs, &block)
case args.length
when 0 then auth(**kwargs, &block)
when 1 then auth(args.first, **kwargs, &block)
when 2..3
username, secret, authtype = *args
if kwargs.any?
kwargs = merge_auth_params(username, secret, authtype, kwargs)
auth(**kwargs, &block)
else
authenticator = Authenticator.auth_class(authtype).new(self)
critical { authenticator.auth(username, secret) }
end
else
raise ArgumentError, "wrong number of arguments " \
"(given %d, expected 1..3)" % [args.length]
end
end

# call-seq:
Expand Down

0 comments on commit 6bc08a3

Please sign in to comment.