Move code to empty the trash folder to Backend implementations
This commit is contained in:
parent
3b393964e2
commit
d7558a1313
8 changed files with 118 additions and 20 deletions
|
@ -28,6 +28,9 @@ interface Backend {
|
|||
@Throws(MessagingException::class)
|
||||
fun expungeMessages(folderServerId: String, messageServerIds: List<String>)
|
||||
|
||||
@Throws(MessagingException::class)
|
||||
fun deleteAllMessages(folderServerId: String)
|
||||
|
||||
@Throws(MessagingException::class)
|
||||
fun moveMessages(
|
||||
sourceFolderServerId: String,
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.fsck.k9.backend.imap
|
||||
|
||||
|
||||
import com.fsck.k9.mail.Flag
|
||||
import com.fsck.k9.mail.Folder
|
||||
import com.fsck.k9.mail.MessagingException
|
||||
import com.fsck.k9.mail.store.imap.ImapStore
|
||||
|
||||
|
||||
internal class CommandDeleteAll(private val imapStore: ImapStore) {
|
||||
|
||||
@Throws(MessagingException::class)
|
||||
fun deleteAll(folderServerId: String) {
|
||||
val remoteFolder = imapStore.getFolder(folderServerId)
|
||||
if (!remoteFolder.exists()) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
remoteFolder.open(Folder.OPEN_MODE_RW)
|
||||
remoteFolder.setFlags(setOf(Flag.DELETED), true)
|
||||
} finally {
|
||||
remoteFolder.close()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ public class ImapBackend implements Backend {
|
|||
private final CommandMarkAllAsRead commandMarkAllAsRead;
|
||||
private final CommandExpunge commandExpunge;
|
||||
private final CommandMoveOrCopyMessages commandMoveOrCopyMessages;
|
||||
private final CommandDeleteAll commandDeleteAll;
|
||||
|
||||
|
||||
public ImapBackend(String accountName, BackendStorage backendStorage, ImapStore imapStore) {
|
||||
|
@ -33,6 +34,7 @@ public class ImapBackend implements Backend {
|
|||
commandExpunge = new CommandExpunge(imapStore);
|
||||
commandMoveOrCopyMessages = new CommandMoveOrCopyMessages(imapStore);
|
||||
commandGetFolders = new CommandGetFolders(imapStore);
|
||||
commandDeleteAll = new CommandDeleteAll(imapStore);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,6 +81,11 @@ public class ImapBackend implements Backend {
|
|||
commandExpunge.expungeMessages(folderServerId, messageServerIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllMessages(@NotNull String folderServerId) throws MessagingException {
|
||||
commandDeleteAll.deleteAll(folderServerId);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<String, String> moveMessages(@NotNull String sourceFolderServerId, @NotNull String targetFolderServerId,
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.fsck.k9.backend.pop3
|
||||
|
||||
|
||||
import com.fsck.k9.mail.Flag
|
||||
import com.fsck.k9.mail.Folder
|
||||
import com.fsck.k9.mail.MessagingException
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Store
|
||||
|
||||
|
||||
internal class CommandDeleteAll(private val pop3Store: Pop3Store) {
|
||||
|
||||
@Throws(MessagingException::class)
|
||||
fun deleteAll(folderServerId: String) {
|
||||
val remoteFolder = pop3Store.getFolder(folderServerId)
|
||||
if (!remoteFolder.exists()) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
remoteFolder.open(Folder.OPEN_MODE_RW)
|
||||
remoteFolder.setFlags(setOf(Flag.DELETED), true)
|
||||
} finally {
|
||||
remoteFolder.close()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ class Pop3Backend(accountName: String, backendStorage: BackendStorage, pop3Store
|
|||
private val pop3Sync: Pop3Sync = Pop3Sync(accountName, backendStorage, pop3Store)
|
||||
private val commandGetFolders = CommandGetFolders()
|
||||
private val commandSetFlag = CommandSetFlag(pop3Store)
|
||||
private val commandDeleteAll = CommandDeleteAll(pop3Store)
|
||||
|
||||
override val supportsSeenFlag: Boolean = false
|
||||
override val supportsExpunge: Boolean = false
|
||||
|
@ -41,6 +42,10 @@ class Pop3Backend(accountName: String, backendStorage: BackendStorage, pop3Store
|
|||
throw UnsupportedOperationException("not supported")
|
||||
}
|
||||
|
||||
override fun deleteAllMessages(folderServerId: String) {
|
||||
commandDeleteAll.deleteAll(folderServerId)
|
||||
}
|
||||
|
||||
override fun moveMessages(
|
||||
sourceFolderServerId: String,
|
||||
targetFolderServerId: String,
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.fsck.k9.backend.webdav
|
||||
|
||||
|
||||
import com.fsck.k9.mail.Flag
|
||||
import com.fsck.k9.mail.Folder
|
||||
import com.fsck.k9.mail.MessagingException
|
||||
import com.fsck.k9.mail.store.webdav.WebDavStore
|
||||
|
||||
|
||||
internal class CommandDeleteAll(private val webDavStore: WebDavStore) {
|
||||
|
||||
@Throws(MessagingException::class)
|
||||
fun deleteAll(folderServerId: String) {
|
||||
val remoteFolder = webDavStore.getFolder(folderServerId)
|
||||
if (!remoteFolder.exists()) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
remoteFolder.open(Folder.OPEN_MODE_RW)
|
||||
remoteFolder.setFlags(setOf(Flag.DELETED), true)
|
||||
} finally {
|
||||
remoteFolder.close()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ class WebDavBackend(accountName: String, backendStorage: BackendStorage, webDavS
|
|||
private val commandSetFlag = CommandSetFlag(webDavStore)
|
||||
private val commandMarkAllAsRead = CommandMarkAllAsRead(webDavStore)
|
||||
private val commandMoveOrCopyMessages = CommandMoveOrCopyMessages(webDavStore)
|
||||
private val commandDeleteAll = CommandDeleteAll(webDavStore)
|
||||
|
||||
override val supportsSeenFlag: Boolean = true
|
||||
override val supportsExpunge: Boolean = true
|
||||
|
@ -46,6 +47,10 @@ class WebDavBackend(accountName: String, backendStorage: BackendStorage, webDavS
|
|||
throw UnsupportedOperationException("not supported")
|
||||
}
|
||||
|
||||
override fun deleteAllMessages(folderServerId: String) {
|
||||
commandDeleteAll.deleteAll(folderServerId)
|
||||
}
|
||||
|
||||
override fun moveMessages(
|
||||
sourceFolderServerId: String,
|
||||
targetFolderServerId: String,
|
||||
|
|
|
@ -2877,27 +2877,27 @@ public class MessagingController {
|
|||
}
|
||||
|
||||
void processPendingEmptyTrash(Account account) throws MessagingException {
|
||||
RemoteStore remoteStore = account.getRemoteStore();
|
||||
if (!account.hasTrashFolder()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Folder remoteFolder = remoteStore.getFolder(account.getTrashFolder());
|
||||
try {
|
||||
if (remoteFolder.exists()) {
|
||||
remoteFolder.open(Folder.OPEN_MODE_RW);
|
||||
remoteFolder.setFlags(Collections.singleton(Flag.DELETED), true);
|
||||
if (Expunge.EXPUNGE_IMMEDIATELY == account.getExpungePolicy()) {
|
||||
remoteFolder.expunge();
|
||||
Backend backend = getBackend(account);
|
||||
|
||||
String trashFolderServerId = account.getTrashFolder();
|
||||
backend.deleteAllMessages(trashFolderServerId);
|
||||
|
||||
if (account.getExpungePolicy() == Expunge.EXPUNGE_IMMEDIATELY) {
|
||||
backend.expunge(trashFolderServerId);
|
||||
}
|
||||
|
||||
// When we empty trash, we need to actually synchronize the folder
|
||||
// or local deletes will never get cleaned up
|
||||
synchronizeFolder(account, remoteFolder, true, 0, null);
|
||||
LocalStore localStore = account.getLocalStore();
|
||||
LocalFolder folder = localStore.getFolder(trashFolderServerId);
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
synchronizeFolder(account, folder, true, 0, null);
|
||||
|
||||
compact(account, null);
|
||||
|
||||
|
||||
}
|
||||
} finally {
|
||||
closeFolder(remoteFolder);
|
||||
}
|
||||
}
|
||||
|
||||
public void emptyTrash(final Account account, MessagingListener listener) {
|
||||
|
|
Loading…
Reference in a new issue