From 3fcca67ae504ee43e59492593fa9ece16fa5e415 Mon Sep 17 00:00:00 2001 From: Andrew Chen Date: Wed, 4 May 2011 23:33:22 -0700 Subject: [PATCH] Preserve legacy SMTP authentication behavior for PLAIN by trying LOGIN if supported. --- .../fsck/k9/mail/transport/SmtpTransport.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/com/fsck/k9/mail/transport/SmtpTransport.java b/src/com/fsck/k9/mail/transport/SmtpTransport.java index bb31409be..45f218191 100644 --- a/src/com/fsck/k9/mail/transport/SmtpTransport.java +++ b/src/com/fsck/k9/mail/transport/SmtpTransport.java @@ -273,7 +273,22 @@ public class SmtpTransport extends Transport { Log.d(K9.LOG_TAG, "Using PLAIN as authentication method although the " + "server didn't advertise support for it in EHLO response."); } - saslAuthPlain(mUsername, mPassword); + try { + saslAuthPlain(mUsername, mPassword); + } catch(MessagingException ex) { + // PLAIN is a special case. Historically, PLAIN has represented both PLAIN and LOGIN; only the + // protocol being advertised by the server would be used, with PLAIN taking precedence. Instead + // of using only the requested protocol, we'll try PLAIN and then try LOGIN. + if (useAuthPlain && authLoginSupported) { + if (K9.DEBUG && K9.DEBUG_PROTOCOL_SMTP) { + Log.d(K9.LOG_TAG, "Using legacy PLAIN authentication behavior and trying LOGIN."); + } + saslAuthLogin(mUsername, mPassword); + } else { + // If it was auto detected and failed, continue throwing the exception back up. + throw ex; + } + } } else if (useAuthLogin || (useAutomaticAuth && authLoginSupported)) { if (!authPlainSupported && K9.DEBUG && K9.DEBUG_PROTOCOL_SMTP) { Log.d(K9.LOG_TAG, "Using LOGIN as authentication method although the " +