Skip to content

Commit

Permalink
✨ Add very basic SASL-IR support to #authenticate [🚧 WIP]
Browse files Browse the repository at this point in the history
WIP: No tests.  And I'd prefer that it works automatically (by reading
cached capabilities).
  • Loading branch information
nevans committed Jan 9, 2023
1 parent 0304ca3 commit 02d9b46
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1032,11 +1032,17 @@ def starttls(options = {}, verify = true)
# imap.login username, password
# end
#
def authenticate(mechanism, ...)
authenticator = self.class.authenticator(mechanism, ...)
send_command("AUTHENTICATE", mechanism) do |resp|
def authenticate(mechanism, *creds, sasl_ir: false, **props, &callback)
authenticator = self.class.authenticator(mechanism,
*creds, **props, &callback)
cmdargs = ["AUTHENTICATE", mechanism]
if sasl_ir && sasl.respond_to?(:initial_response?) && sasl.initial_response?
data = authenticator.process(nil)
cmdargs << [data].pack("m0")
end
send_command(*cmdargs) do |resp|
if resp.instance_of?(ContinuationRequest)
data = authenticator.process(resp.data.text.unpack("m")[0])
data = authenticator.process(resp.data.text.unpack1("m"))
s = [data].pack("m0")
send_string_data(s)
put_string(CRLF)
Expand Down

0 comments on commit 02d9b46

Please sign in to comment.