diff --git a/lib/net/imap/authenticators.rb b/lib/net/imap/authenticators.rb index 3659274b..e7a3af2f 100644 --- a/lib/net/imap/authenticators.rb +++ b/lib/net/imap/authenticators.rb @@ -7,6 +7,9 @@ module Net::IMAP::Authenticators # {SASL mechanism}[https://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml] # implemented by +authenticator+ (for instance, "PLAIN"). # + # If +mechanism+ refers to an existing authenticator, a warning will be + # printed and the old authenticator will be replaced. + # # The +authenticator+ must respond to +#new+ (or #call), receiving the # authenticator configuration and return a configured authentication session. # The authenticator session must respond to +#process+, receiving the server's @@ -14,8 +17,12 @@ module Net::IMAP::Authenticators # # See PlainAuthenticator, XOauth2Authenticator, and DigestMD5Authenticator for # examples. - def add_authenticator(auth_type, authenticator) - authenticators[auth_type] = authenticator + def add_authenticator(mechanism, authenticator, warn_overwrite: true) + if warn_overwrite && (original = authenticators[mechanism]) + warn("%p: replacing %p authenticator: %p" % [ self, mechanism, original], + uplevel: 1) + end + authenticators[mechanism] = authenticator end # :call-seq: