From 7bb187fbd4e40b0386e1fbbbf4ee9fa3c055b209 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 19 Oct 2022 21:14:55 +0200 Subject: [PATCH] Reduced check open frequency --- app/src/main/java/eu/faircode/email/Core.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 60152b09fa..487a740403 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -215,10 +215,21 @@ class Core { if (!Objects.equals(folder.id, op.folder)) throw new IllegalArgumentException("Invalid folder=" + folder.id + "/" + op.folder); - if (account.protocol == EntityAccount.TYPE_IMAP && - !folder.local && - ifolder != null && !ifolder.isOpen()) - throw new FolderClosedException(ifolder, account.name + "/" + folder.name + " unexpectedly closed"); + if (account.protocol == EntityAccount.TYPE_IMAP && !folder.local && ifolder != null) { + try { + ((IMAPFolder) ifolder).doCommand(new IMAPFolder.ProtocolCommand() { + @Override + public Object doCommand(IMAPProtocol protocol) throws ProtocolException { + long ago = System.currentTimeMillis() - protocol.getTimestamp(); + if (ago > 20000) + protocol.noop(); + return null; + } + }); + } catch (MessagingException ex) { + throw new FolderClosedException(ifolder, account.name + "/" + folder.name + " unexpectedly closed", ex); + } + } if (account.protocol == EntityAccount.TYPE_POP && EntityFolder.INBOX.equals(folder.type) &&