From a6280b6f9f430632031933bb88fd273887a2da79 Mon Sep 17 00:00:00 2001 From: nick evans Date: Sat, 14 Oct 2023 16:13:58 -0400 Subject: [PATCH] Add `type` keyword arg to `#authenticate` This is convenient for `smtp.start auth: {type:, **etc}`. --- lib/net/smtp.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb index 917bc5e..0d7020a 100644 --- a/lib/net/smtp.rb +++ b/lib/net/smtp.rb @@ -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+ @@ -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 #