From 52a3d16d2624509a2a39fea79b9b32a5b3567f63 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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb index aaff382..97abdff 100644 --- a/lib/net/smtp.rb +++ b/lib/net/smtp.rb @@ -864,7 +864,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. @@ -881,19 +883,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) critical { 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 #