Skip to content

Use ruby2_keywords for authenticator forwarding #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

require "socket"
require "monitor"
require "ruby2_keywords"
require 'net/protocol'
begin
require "openssl"
Expand Down Expand Up @@ -409,9 +410,9 @@ def starttls(options = {}, verify = true)
#
# See +Net::IMAP::Authenticators+ for more information on plugging in your
# own authenticator.
def authenticate(auth_type, *args)
authenticator = self.class.authenticator(auth_type, *args)
send_command("AUTHENTICATE", auth_type) do |resp|
def authenticate(mechanism, *args)
authenticator = self.class.authenticator(mechanism, *args)
send_command("AUTHENTICATE", mechanism) do |resp|
if resp.instance_of?(ContinuationRequest)
data = authenticator.process(resp.data.text.unpack("m")[0])
s = [data].pack("m0")
Expand All @@ -420,6 +421,7 @@ def authenticate(auth_type, *args)
end
end
end
ruby2_keywords :authenticate

# Sends a LOGIN command to identify the client and carries
# the plaintext +password+ authenticating this +user+. Note
Expand Down
12 changes: 8 additions & 4 deletions lib/net/imap/authenticators.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "ruby2_keywords"

# Registry for SASL authenticators used by Net::IMAP.
module Net::IMAP::Authenticators

Expand All @@ -13,22 +15,24 @@ module Net::IMAP::Authenticators
#
# If +auth_type+ refers to an existing authenticator, it will be
# replaced by the new one.
#
def add_authenticator(auth_type, authenticator)
authenticators[auth_type] = authenticator
end

# Builds an authenticator for Net::IMAP#authenticate. +args+ will be passed
# directly to the chosen authenticator's +#initialize+.
def authenticator(mechanism, *authargs, **properties, &callback)
authenticator = authenticators.fetch(mechanism.upcase) do
def authenticator(mechanism, *authargs, &callback)
authenticator = authenticators.fetch(mechanism.to_s.upcase) do
raise ArgumentError, 'unknown auth type - "%s"' % mechanism
end
if authenticator.respond_to?(:new)
authenticator.new(*authargs, **properties, &callback)
authenticator.new(*authargs, &callback)
else
authenticator.call(*authargs, **properties, &callback)
authenticator.call(*authargs, &callback)
end
end
ruby2_keywords :authenticator

private

Expand Down
2 changes: 2 additions & 0 deletions net-imap.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "net-protocol"
spec.add_dependency "ruby2_keywords"

spec.add_development_dependency "digest"
spec.add_development_dependency "strscan"
end