From 7b10c00f45b025823d74acc5ed5f5b2f734fd2b0 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 14 Aug 2020 09:55:51 +0200 Subject: [PATCH] Fixed connection pool lock --- app/src/main/java/com/sun/mail/imap/IMAPFolder.java | 3 ++- app/src/main/java/com/sun/mail/imap/IMAPStore.java | 6 +++++- app/src/main/java/eu/faircode/email/MessageHelper.java | 5 ++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/sun/mail/imap/IMAPFolder.java b/app/src/main/java/com/sun/mail/imap/IMAPFolder.java index 74f2f56b96..4e0f428feb 100644 --- a/app/src/main/java/com/sun/mail/imap/IMAPFolder.java +++ b/app/src/main/java/com/sun/mail/imap/IMAPFolder.java @@ -3963,7 +3963,8 @@ public class IMAPFolder extends Folder implements UIDFolder, ResponseHandler { protocol.noop(); } - if (keepStoreAlive && ((IMAPStore)store).hasSeparateStoreConnection()) { + if (keepStoreAlive && ((IMAPStore)store).hasSeparateStoreConnection() && + !((IMAPStore)store).isStoreConnectionInUse()) { IMAPProtocol p = null; try { p = ((IMAPStore)store).getFolderStoreProtocol(); 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 7c9e67f5f8..087e5a6f5f 100644 --- a/app/src/main/java/com/sun/mail/imap/IMAPStore.java +++ b/app/src/main/java/com/sun/mail/imap/IMAPStore.java @@ -1264,7 +1264,11 @@ public class IMAPStore extends Store return pool.separateStoreConnection; } - /** + boolean isStoreConnectionInUse() { + return pool.storeConnectionInUse; + } + + /** * Return the connection pool logger. */ MailLogger getConnectionPoolLogger() { diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index fb43918ee7..3f550a0013 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -2286,7 +2286,6 @@ public class MessageHelper { static int getMessageCount(Folder folder) throws MessagingException { // Keep alive - int total = folder.getMessageCount(); try { int count = 0; for (Message message : folder.getMessages()) @@ -2295,8 +2294,8 @@ public class MessageHelper { return count; } catch (Throwable ex) { - Log.w(ex); - return total; + Log.e(ex); + return -1; } }