diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb index d06eda2..f774381 100644 --- a/lib/net/smtp.rb +++ b/lib/net/smtp.rb @@ -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. @@ -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: