Skip to content

Commit 31f36d9

Browse files
committed
💩🚧 More complete SASL error handling
1 parent 82fe814 commit 31f36d9

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

lib/net/imap.rb

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,14 +1255,28 @@ def authenticate(mechanism, *creds, sasl_ir: true, **props, &callback)
12551255
response = authenticator.process(nil)
12561256
cmdargs << sasl_encode_ir(response)
12571257
end
1258-
result = send_command(*cmdargs) do |resp|
1259-
if resp.instance_of?(ContinuationRequest)
1260-
challenge = sasl_decode resp.data.text
1261-
response = sasl_encode authenticator.process challenge
1262-
put_string(response + CRLF)
1258+
begin
1259+
error = false
1260+
result = send_command(*cmdargs) do |resp|
1261+
if resp.instance_of?(ContinuationRequest)
1262+
unless error
1263+
begin
1264+
challenge = sasl_decode resp.data.text
1265+
response = sasl_encode authenticator.process(challenge)
1266+
rescue DataFormatError, ResponseParseError, SASL::Error => error
1267+
end
1268+
end
1269+
put_string(error ? "*\r\n" : response + CRLF)
1270+
end
12631271
end
1272+
rescue ResponseError => ex
1273+
ex.cause ||= error if error
1274+
raise
12641275
end
1265-
unless SASL.done?(authenticator)
1276+
if error
1277+
logout!
1278+
raise error
1279+
elsif !SASL.done?(authenticator)
12661280
logout!
12671281
raise SASL::AuthenticationFailed, "authentication ended prematurely"
12681282
end

0 commit comments

Comments
 (0)