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 2, 2023
1 parent 2ea4086 commit a6d81a7
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 @@ -1037,11 +1037,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 a6d81a7

Please sign in to comment.