From 625c5f18745b7cf2975a33ebc8b4ee1d0c4c318a Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 10 Mar 2013 21:45:36 +0100 Subject: [PATCH] Fix "Empty trash" functionality for POP3 accounts Previously messages in the local Trash folder were marked as deleted, then deleted from the server. During the next sync the placeholders for deleted messages are removed from the database. Obviously this doesn't work for POP3 accounts because the Trash folder can't be synchronized with the server. So, for POP3, we now immediately clear out all messages in that folder. --- .../k9/controller/MessagingController.java | 43 ++++++++++++++++--- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 88ae84191..50ebc3616 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -80,6 +80,7 @@ import com.fsck.k9.mail.store.LocalStore; import com.fsck.k9.mail.store.LocalStore.LocalFolder; import com.fsck.k9.mail.store.LocalStore.LocalMessage; import com.fsck.k9.mail.store.LocalStore.PendingCommand; +import com.fsck.k9.mail.store.Pop3Store; import com.fsck.k9.mail.store.UnavailableAccountException; import com.fsck.k9.mail.store.UnavailableStorageException; import com.fsck.k9.provider.EmailProvider; @@ -4176,17 +4177,26 @@ public class MessagingController implements Runnable { Store localStore = account.getLocalStore(); localFolder = (LocalFolder) localStore.getFolder(account.getTrashFolderName()); localFolder.open(OpenMode.READ_WRITE); - localFolder.setFlags(new Flag[] { Flag.DELETED }, true); + + boolean isTrashLocalOnly = isTrashLocalOnly(account); + if (isTrashLocalOnly) { + localFolder.clearAllMessages(); + } else { + localFolder.setFlags(new Flag[] { Flag.DELETED }, true); + } for (MessagingListener l : getListeners()) { l.emptyTrashCompleted(account); } - List args = new ArrayList(); - PendingCommand command = new PendingCommand(); - command.command = PENDING_COMMAND_EMPTY_TRASH; - command.arguments = args.toArray(EMPTY_STRING_ARRAY); - queuePendingCommand(account, command); - processPendingCommands(account); + + if (!isTrashLocalOnly) { + List args = new ArrayList(); + PendingCommand command = new PendingCommand(); + command.command = PENDING_COMMAND_EMPTY_TRASH; + command.arguments = args.toArray(EMPTY_STRING_ARRAY); + queuePendingCommand(account, command); + processPendingCommands(account); + } } catch (UnavailableStorageException e) { Log.i(K9.LOG_TAG, "Failed to empty trash because storage is not available - trying again later."); throw new UnavailableAccountException(e); @@ -4200,6 +4210,25 @@ public class MessagingController implements Runnable { }); } + /** + * Find out whether the account type only supports a local Trash folder. + * + *

Note: Currently this is only the case for POP3 accounts.

+ * + * @param account + * The account to check. + * + * @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); + } + public void sendAlternate(final Context context, Account account, Message message) { if (K9.DEBUG) Log.d(K9.LOG_TAG, "About to load message " + account.getDescription() + ":" + message.getFolder().getName()