Move code to expunge messages from a folder to Backend implementations
This commit is contained in:
parent
0ee775c95c
commit
34616a954b
6 changed files with 66 additions and 20 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue