From d2dd21de9796384bbac0a836ab375067e7d08195 Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 18 Jun 2018 02:44:05 +0200 Subject: [PATCH] Move protocol capability flags to Backend implementations --- .../java/com/fsck/k9/backend/api/Backend.kt | 3 ++ .../com/fsck/k9/backend/imap/ImapBackend.java | 15 +++++++++ .../com/fsck/k9/backend/pop3/Pop3Backend.kt | 7 ++-- .../fsck/k9/backend/webdav/WebDavBackend.kt | 8 +++-- .../k9/controller/MessagingController.java | 32 ++++--------------- 5 files changed, 35 insertions(+), 30 deletions(-) diff --git a/backend/api/src/main/java/com/fsck/k9/backend/api/Backend.kt b/backend/api/src/main/java/com/fsck/k9/backend/api/Backend.kt index b74902721..d9491fa6a 100644 --- a/backend/api/src/main/java/com/fsck/k9/backend/api/Backend.kt +++ b/backend/api/src/main/java/com/fsck/k9/backend/api/Backend.kt @@ -13,6 +13,9 @@ import com.fsck.k9.mail.Part interface Backend { val supportsSeenFlag: Boolean val supportsExpunge: Boolean + val supportsMove: Boolean + val supportsCopy: Boolean + val supportsTrashFolder: Boolean @Throws(MessagingException::class) fun getFolders(forceListAll: Boolean): List diff --git a/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapBackend.java b/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapBackend.java index 5030b19a7..64b033e9d 100644 --- a/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapBackend.java +++ b/backend/imap/src/main/java/com/fsck/k9/backend/imap/ImapBackend.java @@ -60,6 +60,21 @@ public class ImapBackend implements Backend { return true; } + @Override + public boolean getSupportsMove() { + return true; + } + + @Override + public boolean getSupportsCopy() { + return true; + } + + @Override + public boolean getSupportsTrashFolder() { + return true; + } + @NotNull @Override public List getFolders(boolean forceListAll) { diff --git a/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/Pop3Backend.kt b/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/Pop3Backend.kt index ebd37d2a3..60ef0e956 100644 --- a/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/Pop3Backend.kt +++ b/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/Pop3Backend.kt @@ -20,8 +20,11 @@ class Pop3Backend(accountName: String, backendStorage: BackendStorage, pop3Store private val commandDeleteAll = CommandDeleteAll(pop3Store) private val commandFetchMessage = CommandFetchMessage(pop3Store) - override val supportsSeenFlag: Boolean = false - override val supportsExpunge: Boolean = false + override val supportsSeenFlag = false + override val supportsExpunge = false + override val supportsMove = false + override val supportsCopy = false + override val supportsTrashFolder = false override fun getFolders(forceListAll: Boolean): List { return commandGetFolders.getFolders() diff --git a/backend/webdav/src/main/java/com/fsck/k9/backend/webdav/WebDavBackend.kt b/backend/webdav/src/main/java/com/fsck/k9/backend/webdav/WebDavBackend.kt index f9b21ccd1..1a503cfb7 100644 --- a/backend/webdav/src/main/java/com/fsck/k9/backend/webdav/WebDavBackend.kt +++ b/backend/webdav/src/main/java/com/fsck/k9/backend/webdav/WebDavBackend.kt @@ -24,9 +24,11 @@ class WebDavBackend(accountName: String, backendStorage: BackendStorage, webDavS private val commandFetchMessage = CommandFetchMessage(webDavStore) private val commandUploadMessage = CommandUploadMessage(webDavStore) - override val supportsSeenFlag: Boolean = true - override val supportsExpunge: Boolean = true - + override val supportsSeenFlag = true + override val supportsExpunge = true + override val supportsMove = true + override val supportsCopy = true + override val supportsTrashFolder = true override fun getFolders(forceListAll: Boolean): List { return commandGetFolders.getFolders(forceListAll) diff --git a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java index 0db1e3f66..10cc5e1e8 100644 --- a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -86,7 +86,6 @@ import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.mail.power.TracingPowerManager; import com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock; import com.fsck.k9.mail.store.RemoteStore; -import com.fsck.k9.mail.store.pop3.Pop3Store; import com.fsck.k9.mailstore.LocalFolder; import com.fsck.k9.mailstore.LocalMessage; import com.fsck.k9.mailstore.LocalStore; @@ -2372,24 +2371,11 @@ public class MessagingController { } public boolean isMoveCapable(final Account account) { - try { - RemoteStore remoteStore = account.getRemoteStore(); - return remoteStore.isMoveCapable(); - } catch (MessagingException me) { - - Timber.e(me, "Exception while ascertaining move capability"); - return false; - } + return getBackend(account).getSupportsMove(); } public boolean isCopyCapable(final Account account) { - try { - RemoteStore remoteStore = account.getRemoteStore(); - return remoteStore.isCopyCapable(); - } catch (MessagingException me) { - Timber.e(me, "Exception while ascertaining copy capability"); - return false; - } + return getBackend(account).getSupportsCopy(); } public void moveMessages(final Account srcAccount, final String srcFolder, @@ -2483,11 +2469,10 @@ public class MessagingController { try { LocalStore localStore = account.getLocalStore(); - RemoteStore remoteStore = account.getRemoteStore(); - if (!isCopy && !remoteStore.isMoveCapable()) { + if (!isCopy && !isMoveCapable(account)) { return; } - if (isCopy && !remoteStore.isCopyCapable()) { + if (isCopy && !isCopyCapable(account)) { return; } @@ -2899,13 +2884,10 @@ public class MessagingController { * * @return {@code true} if the account only has a local Trash folder that is not synchronized * with a folder on the server. {@code false} otherwise. - * - * @throws MessagingException - * In case of an error. */ - private boolean isTrashLocalOnly(Account account) throws MessagingException { - // TODO: Get rid of the tight coupling once we properly support local folders - return (account.getRemoteStore() instanceof Pop3Store); + private boolean isTrashLocalOnly(Account account) { + Backend backend = getBackend(account); + return !backend.getSupportsTrashFolder(); } public void sendAlternate(Context context, Account account, LocalMessage message) {