From 177d4c0637d667ca1a359541ac5edef6fddbd9ab Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 13 Jan 2021 17:53:18 +0100 Subject: [PATCH] Try all AUTH methods --- .../java/com/sun/mail/imap/IMAPStore.java | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/sun/mail/imap/IMAPStore.java b/app/src/main/java/com/sun/mail/imap/IMAPStore.java index 078c1b9645..048cb32330 100644 --- a/app/src/main/java/com/sun/mail/imap/IMAPStore.java +++ b/app/src/main/java/com/sun/mail/imap/IMAPStore.java @@ -858,6 +858,7 @@ public class IMAPStore extends Store * the mechanism and we have an authenticator for the mechanism, * and it hasn't been disabled, use it. */ + ProtocolException pex = null; StringTokenizer st = new StringTokenizer(mechs); while (st.hasMoreTokens()) { String m = st.nextToken(); @@ -888,28 +889,45 @@ public class IMAPStore extends Store } try { - if (m.equals("PLAIN")) + if (m.equals("PLAIN")) { p.authplain(authzid, user, password); - else if (m.equals("LOGIN")) + return; + } + else if (m.equals("LOGIN")) { p.authlogin(user, password); - else if (m.equals("NTLM")) + return; + } + else if (m.equals("NTLM")) { p.authntlm(authzid, user, password); - else if (m.equals("XOAUTH2")) + return; + } + else if (m.equals("XOAUTH2")) { p.authoauth2(user, password); + return; + } else { logger.log(Level.FINE, "no authenticator for mechanism {0}", m); continue; } } catch (ProtocolException ex) { + eu.faircode.email.Log.w(ex); + if (pex == null) + pex = ex; if (m.equals("PLAIN") || m.equals("LOGIN")) { - eu.faircode.email.Log.i("Falling back to classic LOGIN"); - p.authclassic(user, password); - } else - throw ex; + eu.faircode.email.Log.w("Falling back to classic LOGIN"); + try { + p.authclassic(user, password); + return; + } catch (ProtocolException exex) { + eu.faircode.email.Log.w(exex); + } + } } - return; } + if (pex != null) + throw pex; + if (!p.hasCapability("LOGINDISABLED")) { p.login(user, password); return;