Skip to content

Commit 5c633a4

Browse files
committed
♻️ Use experimental SASL::ClientAdapter
✨ Adds `registry` option to `#authenticate`. This allows authenticator lookup and creation to be overridden, rather than be forced to depend on global defaults.
1 parent 81bc4d3 commit 5c633a4

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

lib/net/imap.rb

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,29 +1339,9 @@ def starttls(**options)
13391339
# Previously cached #capabilities will be cleared when this method
13401340
# completes. If the TaggedResponse to #authenticate includes updated
13411341
# capabilities, they will be cached.
1342-
def authenticate(mechanism, *creds,
1343-
sasl_ir: config.sasl_ir,
1344-
**props, &callback)
1345-
mechanism = SASL::Authenticators.normalize_name(mechanism)
1346-
authenticator = SASL.authenticator(mechanism, *creds, **props, &callback)
1347-
cmdargs = ["AUTHENTICATE", mechanism]
1348-
if sasl_ir && capable?("SASL-IR") && auth_capable?(mechanism) &&
1349-
authenticator.respond_to?(:initial_response?) &&
1350-
authenticator.initial_response?
1351-
response = authenticator.process(nil)
1352-
cmdargs << (response.empty? ? "=" : [response].pack("m0"))
1353-
end
1354-
result = send_command_with_continuations(*cmdargs) {|data|
1355-
challenge = data.unpack1("m")
1356-
response = authenticator.process challenge
1357-
[response].pack("m0")
1358-
}
1359-
if authenticator.respond_to?(:done?) && !authenticator.done?
1360-
logout!
1361-
raise SASL::AuthenticationIncomplete, result
1362-
end
1363-
@capabilities = capabilities_from_resp_code result
1364-
result
1342+
def authenticate(*args, sasl_ir: config.sasl_ir, **props, &callback)
1343+
sasl_adapter.authenticate(*args, sasl_ir: sasl_ir, **props, &callback)
1344+
.tap { @capabilities = capabilities_from_resp_code _1 }
13651345
end
13661346

13671347
# Sends a {LOGIN command [IMAP4rev1 §6.2.3]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.2.3]

0 commit comments

Comments
 (0)