mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-13 21:15:08 -05:00
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.
This commit is contained in:
parent
0319ee4a5d
commit
625c5f1874
@ -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.LocalFolder;
|
||||||
import com.fsck.k9.mail.store.LocalStore.LocalMessage;
|
import com.fsck.k9.mail.store.LocalStore.LocalMessage;
|
||||||
import com.fsck.k9.mail.store.LocalStore.PendingCommand;
|
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.UnavailableAccountException;
|
||||||
import com.fsck.k9.mail.store.UnavailableStorageException;
|
import com.fsck.k9.mail.store.UnavailableStorageException;
|
||||||
import com.fsck.k9.provider.EmailProvider;
|
import com.fsck.k9.provider.EmailProvider;
|
||||||
@ -4176,17 +4177,26 @@ public class MessagingController implements Runnable {
|
|||||||
Store localStore = account.getLocalStore();
|
Store localStore = account.getLocalStore();
|
||||||
localFolder = (LocalFolder) localStore.getFolder(account.getTrashFolderName());
|
localFolder = (LocalFolder) localStore.getFolder(account.getTrashFolderName());
|
||||||
localFolder.open(OpenMode.READ_WRITE);
|
localFolder.open(OpenMode.READ_WRITE);
|
||||||
|
|
||||||
|
boolean isTrashLocalOnly = isTrashLocalOnly(account);
|
||||||
|
if (isTrashLocalOnly) {
|
||||||
|
localFolder.clearAllMessages();
|
||||||
|
} else {
|
||||||
localFolder.setFlags(new Flag[] { Flag.DELETED }, true);
|
localFolder.setFlags(new Flag[] { Flag.DELETED }, true);
|
||||||
|
}
|
||||||
|
|
||||||
for (MessagingListener l : getListeners()) {
|
for (MessagingListener l : getListeners()) {
|
||||||
l.emptyTrashCompleted(account);
|
l.emptyTrashCompleted(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isTrashLocalOnly) {
|
||||||
List<String> args = new ArrayList<String>();
|
List<String> args = new ArrayList<String>();
|
||||||
PendingCommand command = new PendingCommand();
|
PendingCommand command = new PendingCommand();
|
||||||
command.command = PENDING_COMMAND_EMPTY_TRASH;
|
command.command = PENDING_COMMAND_EMPTY_TRASH;
|
||||||
command.arguments = args.toArray(EMPTY_STRING_ARRAY);
|
command.arguments = args.toArray(EMPTY_STRING_ARRAY);
|
||||||
queuePendingCommand(account, command);
|
queuePendingCommand(account, command);
|
||||||
processPendingCommands(account);
|
processPendingCommands(account);
|
||||||
|
}
|
||||||
} catch (UnavailableStorageException e) {
|
} catch (UnavailableStorageException e) {
|
||||||
Log.i(K9.LOG_TAG, "Failed to empty trash because storage is not available - trying again later.");
|
Log.i(K9.LOG_TAG, "Failed to empty trash because storage is not available - trying again later.");
|
||||||
throw new UnavailableAccountException(e);
|
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.
|
||||||
|
*
|
||||||
|
* <p>Note: Currently this is only the case for POP3 accounts.</p>
|
||||||
|
*
|
||||||
|
* @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) {
|
public void sendAlternate(final Context context, Account account, Message message) {
|
||||||
if (K9.DEBUG)
|
if (K9.DEBUG)
|
||||||
Log.d(K9.LOG_TAG, "About to load message " + account.getDescription() + ":" + message.getFolder().getName()
|
Log.d(K9.LOG_TAG, "About to load message " + account.getDescription() + ":" + message.getFolder().getName()
|
||||||
|
Loading…
Reference in New Issue
Block a user