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 5590b3cc4..8c0b1c91c 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 @@ -8,6 +8,7 @@ import com.fsck.k9.mail.MessagingException interface Backend { val supportsSeenFlag: Boolean + val supportsExpunge: Boolean // TODO: Add a way to cancel the sync process fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener, providedRemoteFolder: Folder<*>?) @@ -17,4 +18,7 @@ interface Backend { @Throws(MessagingException::class) fun markAllAsRead(folderServerId: String) + + @Throws(MessagingException::class) + fun expunge(folderServerId: String) } diff --git a/backend/imap/src/main/java/com/fsck/k9/backend/imap/CommandExpunge.java b/backend/imap/src/main/java/com/fsck/k9/backend/imap/CommandExpunge.java new file mode 100644 index 000000000..ba0a9fb6d --- /dev/null +++ b/backend/imap/src/main/java/com/fsck/k9/backend/imap/CommandExpunge.java @@ -0,0 +1,38 @@ +package com.fsck.k9.backend.imap; + + +import com.fsck.k9.mail.Folder; +import com.fsck.k9.mail.MessagingException; +import com.fsck.k9.mail.store.imap.ImapStore; +import org.jetbrains.annotations.NotNull; +import timber.log.Timber; + + +class CommandExpunge { + private final ImapStore imapStore; + + + CommandExpunge(ImapStore imapStore) { + this.imapStore = imapStore; + } + + void expunge(@NotNull String folderServerId) throws MessagingException { + Timber.d("processPendingExpunge: folder = %s", folderServerId); + + Folder remoteFolder = imapStore.getFolder(folderServerId); + try { + if (!remoteFolder.exists()) { + return; + } + remoteFolder.open(Folder.OPEN_MODE_RW); + if (remoteFolder.getMode() != Folder.OPEN_MODE_RW) { + return; + } + remoteFolder.expunge(); + + Timber.d("processPendingExpunge: complete for folder = %s", folderServerId); + } finally { + remoteFolder.close(); + } + } +} 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 3755c77db..331111aee 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 @@ -18,12 +18,14 @@ public class ImapBackend implements Backend { private final ImapSync imapSync; private final CommandSetFlag commandSetFlag; private final CommandMarkAllAsRead commandMarkAllAsRead; + private final CommandExpunge commandExpunge; public ImapBackend(String accountName, BackendStorage backendStorage, ImapStore imapStore) { imapSync = new ImapSync(accountName, backendStorage, imapStore); commandSetFlag = new CommandSetFlag(imapStore); commandMarkAllAsRead = new CommandMarkAllAsRead(imapStore); + commandExpunge = new CommandExpunge(imapStore); } @Override @@ -31,6 +33,11 @@ public class ImapBackend implements Backend { return true; } + @Override + public boolean getSupportsExpunge() { + return true; + } + @Override public void sync(@NotNull String folder, @NotNull SyncConfig syncConfig, @NotNull SyncListener listener, Folder providedRemoteFolder) { @@ -47,4 +54,9 @@ public class ImapBackend implements Backend { public void markAllAsRead(@NotNull String folderServerId) throws MessagingException { commandMarkAllAsRead.markAllAsRead(folderServerId); } + + @Override + public void expunge(@NotNull String folderServerId) throws MessagingException { + commandExpunge.expunge(folderServerId); + } } 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 a7b70e5ef..c95325c8a 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 @@ -13,6 +13,7 @@ class Pop3Backend(accountName: String, backendStorage: BackendStorage, pop3Store private val commandSetFlag = CommandSetFlag(pop3Store) override val supportsSeenFlag: Boolean = false + override val supportsExpunge: Boolean = false override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener, providedRemoteFolder: Folder<*>?) { pop3Sync.sync(folder, syncConfig, listener) @@ -25,4 +26,8 @@ class Pop3Backend(accountName: String, backendStorage: BackendStorage, pop3Store override fun markAllAsRead(folderServerId: String) { throw UnsupportedOperationException("not supported") } + + override fun expunge(folderServerId: String) { + throw UnsupportedOperationException("not supported") + } } 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 92da5d07a..b36b030b5 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 @@ -15,6 +15,7 @@ class WebDavBackend(accountName: String, backendStorage: BackendStorage, webDavS private val commandMarkAllAsRead = CommandMarkAllAsRead(webDavStore) override val supportsSeenFlag: Boolean = true + override val supportsExpunge: Boolean = true override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener, providedRemoteFolder: Folder<*>?) { @@ -29,4 +30,8 @@ class WebDavBackend(accountName: String, backendStorage: BackendStorage, webDavS override fun markAllAsRead(folderServerId: String) { commandMarkAllAsRead.markAllAsRead(folderServerId) } + + override fun expunge(folderServerId: String) { + throw UnsupportedOperationException("not supported") + } } 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 9b99746e0..056b3326e 100644 --- a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -1723,26 +1723,8 @@ public class MessagingController { } void processPendingExpunge(PendingExpunge command, Account account) throws MessagingException { - String folder = command.folder; - - Timber.d("processPendingExpunge: folder = %s", folder); - - RemoteStore remoteStore = account.getRemoteStore(); - Folder remoteFolder = remoteStore.getFolder(folder); - try { - if (!remoteFolder.exists()) { - return; - } - remoteFolder.open(Folder.OPEN_MODE_RW); - if (remoteFolder.getMode() != Folder.OPEN_MODE_RW) { - return; - } - remoteFolder.expunge(); - - Timber.d("processPendingExpunge: complete for folder = %s", folder); - } finally { - closeFolder(remoteFolder); - } + Backend backend = getBackend(account); + backend.expunge(command.folder); } void processPendingMarkAllAsRead(PendingMarkAllAsRead command, Account account) throws MessagingException {