Skip to content

Commit 11c1106

Browse files
committed
Use ruby2_keywords for authenticator forwarding
Without this, authenticators need to accept keywords for compatibility with older ruby versions. Ruby 2.6 will send an empty hash for `**properties`, and that can crash (or be interpreted as an optional argument) if the authenticator doesn't accept keyword arguments. Actually... is that a bad thing? Maybe the error will motivate people to upgrade to ruby 2.7+ or contribute their custom authenticators to net-imap? 😉 It's easy to stay compatible with `ruby2_keywords`, so let's do that.
1 parent 174e35c commit 11c1106

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

lib/net/imap.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
require "socket"
1717
require "monitor"
18+
require "ruby2_keywords"
1819
require 'net/protocol'
1920
begin
2021
require "openssl"
@@ -409,9 +410,9 @@ def starttls(options = {}, verify = true)
409410
#
410411
# See +Net::IMAP::Authenticators+ for more information on plugging in your
411412
# own authenticator.
412-
def authenticate(auth_type, *args)
413-
authenticator = self.class.authenticator(auth_type, *args)
414-
send_command("AUTHENTICATE", auth_type) do |resp|
413+
def authenticate(mechanism, *args)
414+
authenticator = self.class.authenticator(mechanism, *args)
415+
send_command("AUTHENTICATE", mechanism) do |resp|
415416
if resp.instance_of?(ContinuationRequest)
416417
data = authenticator.process(resp.data.text.unpack("m")[0])
417418
s = [data].pack("m0")
@@ -420,6 +421,7 @@ def authenticate(auth_type, *args)
420421
end
421422
end
422423
end
424+
ruby2_keywords :authenticate
423425

424426
# Sends a LOGIN command to identify the client and carries
425427
# the plaintext +password+ authenticating this +user+. Note

lib/net/imap/authenticators.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require "ruby2_keywords"
4+
35
# Registry for SASL authenticators used by Net::IMAP.
46
module Net::IMAP::Authenticators
57

@@ -13,22 +15,24 @@ module Net::IMAP::Authenticators
1315
#
1416
# If +auth_type+ refers to an existing authenticator, it will be
1517
# replaced by the new one.
18+
#
1619
def add_authenticator(auth_type, authenticator)
1720
authenticators[auth_type] = authenticator
1821
end
1922

2023
# Builds an authenticator for Net::IMAP#authenticate. +args+ will be passed
2124
# directly to the chosen authenticator's +#initialize+.
22-
def authenticator(mechanism, *authargs, **properties, &callback)
23-
authenticator = authenticators.fetch(mechanism.upcase) do
25+
def authenticator(mechanism, *authargs, &callback)
26+
authenticator = authenticators.fetch(mechanism.to_s.upcase) do
2427
raise ArgumentError, 'unknown auth type - "%s"' % mechanism
2528
end
2629
if authenticator.respond_to?(:new)
27-
authenticator.new(*authargs, **properties, &callback)
30+
authenticator.new(*authargs, &callback)
2831
else
29-
authenticator.call(*authargs, **properties, &callback)
32+
authenticator.call(*authargs, &callback)
3033
end
3134
end
35+
ruby2_keywords :authenticator
3236

3337
private
3438

net-imap.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Gem::Specification.new do |spec|
3232
spec.require_paths = ["lib"]
3333

3434
spec.add_dependency "net-protocol"
35+
spec.add_dependency "ruby2_keywords"
36+
3537
spec.add_development_dependency "digest"
3638
spec.add_development_dependency "strscan"
3739
end

0 commit comments

Comments
 (0)