From f2eccd4edad27f19a539aca0b6db7b7b3602ab5b Mon Sep 17 00:00:00 2001
From: M66B <M66B@users.noreply.github.com>
Date: Tue, 14 Jul 2020 20:22:46 +0200
Subject: [PATCH] Revert "Added support for old style login command"

This reverts commit 15a17d33d05fed6080c4f675fa4b86d0fb2c03a8.
---
 .../java/com/sun/mail/imap/IMAPStore.java     | 16 +---
 .../sun/mail/imap/protocol/IMAPProtocol.java  | 54 -----------
 patches/scarlet.patch                         | 93 -------------------
 3 files changed, 2 insertions(+), 161 deletions(-)
 delete mode 100644 patches/scarlet.patch

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 80f2d8371a..929e82d331 100644
--- a/app/src/main/java/com/sun/mail/imap/IMAPStore.java
+++ b/app/src/main/java/com/sun/mail/imap/IMAPStore.java
@@ -888,21 +888,9 @@ public class IMAPStore extends Store
 	    }
 
 	    if (m.equals("PLAIN"))
-			try {
-				p.authplain(authzid, user, password);
-			} catch (ProtocolException ex) {
-				if (mechs.indexOf("LOGIN") > mechs.indexOf("PLAIN"))
-					continue;
-				else
-					throw ex;
-			}
+		p.authplain(authzid, user, password);
 	    else if (m.equals("LOGIN"))
-			try {
-				p.authlogin(user, password);
-			} catch (ProtocolException ex) {
-				eu.faircode.email.Log.w(ex);
-				p.authloginold(user, password);
-			}
+		p.authlogin(user, password);
 	    else if (m.equals("NTLM"))
 		p.authntlm(authzid, user, password);
 	    else if (m.equals("XOAUTH2"))
diff --git a/app/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java b/app/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java
index 57a2ee924a..a8a88b6c01 100644
--- a/app/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java
+++ b/app/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java
@@ -628,60 +628,6 @@ public class IMAPProtocol extends Protocol {
     }
 
 
-	public synchronized void authloginold(String u, String p)
-			throws ProtocolException {
-		List<Response> v = new ArrayList<>();
-		String tag = null;
-		Response r = null;
-		boolean done = false;
-
-		try {
-
-			if (noauthdebug && isTracing()) {
-				logger.fine("LOGIN command trace suppressed");
-				suspendTracing();
-			}
-
-			try {
-				Argument arg = new Argument();
-				arg.writeNString(u);
-				arg.writeNString(p);
-				tag = writeCommand("LOGIN", arg);
-			} catch (Exception ex) {
-				r = Response.byeResponse(ex);
-				done = true;
-			}
-
-			while (!done) {
-				try {
-					r = readResponse();
-					if (r.isTagged() && r.getTag().equals(tag))
-						done = true;
-					else if (r.isBYE()) // outta here
-						done = true;
-				} catch (Exception ioex) {
-					r = Response.byeResponse(ioex);
-					done = true;
-				}
-				v.add(r);
-			}
-
-		} finally {
-			resumeTracing();
-		}
-
-		Response[] responses = v.toArray(new Response[v.size()]);
-
-		handleCapabilityResponse(responses);
-		notifyResponseHandlers(responses);
-
-		if (noauthdebug && isTracing())
-			logger.fine("LOGIN command result: " + r);
-		handleLoginResult(r);
-		setCapabilities(r);
-		authenticated = true;
-	}
-
     /**
      * The AUTHENTICATE command with AUTH=PLAIN authentication scheme.
      * This is based heavly on the {@link #authlogin} method.
diff --git a/patches/scarlet.patch b/patches/scarlet.patch
deleted file mode 100644
index 811c155c6d..0000000000
--- a/patches/scarlet.patch
+++ /dev/null
@@ -1,93 +0,0 @@
-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 929e82d33..5dcf8ae67 100644
---- a/app/src/main/java/com/sun/mail/imap/IMAPStore.java
-+++ b/app/src/main/java/com/sun/mail/imap/IMAPStore.java
-@@ -888,9 +905,21 @@ public class IMAPStore extends Store
- 	    }
- 
- 	    if (m.equals("PLAIN"))
--		p.authplain(authzid, user, password);
-+			try {
-+				p.authplain(authzid, user, password);
-+			} catch (ProtocolException ex) {
-+				if (mechs.indexOf("LOGIN") > mechs.indexOf("PLAIN"))
-+					continue;
-+				else
-+					throw ex;
-+			}
- 	    else if (m.equals("LOGIN"))
--		p.authlogin(user, password);
-+			try {
-+				p.authlogin(user, password);
-+			} catch (ProtocolException ex) {
-+				eu.faircode.email.Log.w(ex);
-+				p.authloginold(user, password);
-+			}
- 	    else if (m.equals("NTLM"))
- 		p.authntlm(authzid, user, password);
- 	    else if (m.equals("XOAUTH2"))
-diff --git a/app/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java b/app/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java
-index a8a88b6c0..57a2ee924 100644
---- a/app/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java
-+++ b/app/src/main/java/com/sun/mail/imap/protocol/IMAPProtocol.java
-@@ -628,6 +628,60 @@ public class IMAPProtocol extends Protocol {
-     }
- 
- 
-+	public synchronized void authloginold(String u, String p)
-+			throws ProtocolException {
-+		List<Response> v = new ArrayList<>();
-+		String tag = null;
-+		Response r = null;
-+		boolean done = false;
-+
-+		try {
-+
-+			if (noauthdebug && isTracing()) {
-+				logger.fine("LOGIN command trace suppressed");
-+				suspendTracing();
-+			}
-+
-+			try {
-+				Argument arg = new Argument();
-+				arg.writeNString(u);
-+				arg.writeNString(p);
-+				tag = writeCommand("LOGIN", arg);
-+			} catch (Exception ex) {
-+				r = Response.byeResponse(ex);
-+				done = true;
-+			}
-+
-+			while (!done) {
-+				try {
-+					r = readResponse();
-+					if (r.isTagged() && r.getTag().equals(tag))
-+						done = true;
-+					else if (r.isBYE()) // outta here
-+						done = true;
-+				} catch (Exception ioex) {
-+					r = Response.byeResponse(ioex);
-+					done = true;
-+				}
-+				v.add(r);
-+			}
-+
-+		} finally {
-+			resumeTracing();
-+		}
-+
-+		Response[] responses = v.toArray(new Response[v.size()]);
-+
-+		handleCapabilityResponse(responses);
-+		notifyResponseHandlers(responses);
-+
-+		if (noauthdebug && isTracing())
-+			logger.fine("LOGIN command result: " + r);
-+		handleLoginResult(r);
-+		setCapabilities(r);
-+		authenticated = true;
-+	}
-+
-     /**
-      * The AUTHENTICATE command with AUTH=PLAIN authentication scheme.
-      * This is based heavly on the {@link #authlogin} method.