diff --git a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java index b3d0d3686..02c5312f5 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -50,6 +50,7 @@ import com.fsck.k9.cache.EmailProviderCache; import com.fsck.k9.controller.ControllerExtension.ControllerInternals; import com.fsck.k9.controller.MessagingControllerCommands.PendingAppend; import com.fsck.k9.controller.MessagingControllerCommands.PendingCommand; +import com.fsck.k9.controller.MessagingControllerCommands.PendingDelete; import com.fsck.k9.controller.MessagingControllerCommands.PendingEmptyTrash; import com.fsck.k9.controller.MessagingControllerCommands.PendingExpunge; import com.fsck.k9.controller.MessagingControllerCommands.PendingMarkAllAsRead; @@ -1033,6 +1034,22 @@ public class MessagingController { backend.setFlag(command.folder, command.uids, command.flag, command.newState); } + private void queueDelete(final Account account, final String folderServerId, final List uids) { + putBackground("queueDelete " + account.getDescription() + ":" + folderServerId, null, new Runnable() { + @Override + public void run() { + PendingCommand command = PendingDelete.create(folderServerId, uids); + queuePendingCommand(account, command); + processPendingCommands(account); + } + }); + } + + void processPendingDelete(PendingDelete command, Account account) throws MessagingException { + Backend backend = getBackend(account); + backend.deleteMessages(command.folder, command.uids); + } + private void queueExpunge(final Account account, final String folderServerId) { putBackground("queueExpunge " + account.getDescription() + ":" + folderServerId, null, new Runnable() { @Override @@ -2221,7 +2238,7 @@ public class MessagingController { } else if (!syncedMessageUids.isEmpty()) { if (account.getDeletePolicy() == DeletePolicy.ON_DELETE) { if (folder.equals(account.getTrashFolder()) || !backend.isDeleteMoveToTrash()) { - queueSetFlag(account, folder, true, Flag.DELETED, syncedMessageUids); + queueDelete(account, folder, syncedMessageUids); } else { queueMoveOrCopy(account, folder, account.getTrashFolder(), false, syncedMessageUids, uidMap); diff --git a/app/core/src/main/java/com/fsck/k9/controller/MessagingControllerCommands.java b/app/core/src/main/java/com/fsck/k9/controller/MessagingControllerCommands.java index 9ac655054..e4475f111 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/MessagingControllerCommands.java +++ b/app/core/src/main/java/com/fsck/k9/controller/MessagingControllerCommands.java @@ -13,6 +13,7 @@ public class MessagingControllerCommands { static final String COMMAND_APPEND = "append"; static final String COMMAND_MARK_ALL_AS_READ = "mark_all_as_read"; static final String COMMAND_SET_FLAG = "set_flag"; + static final String COMMAND_DELETE = "delete"; static final String COMMAND_EXPUNGE = "expunge"; static final String COMMAND_MOVE_OR_COPY = "move_or_copy"; static final String COMMAND_EMPTY_TRASH = "empty_trash"; @@ -158,6 +159,31 @@ public class MessagingControllerCommands { } } + public static class PendingDelete extends PendingCommand { + public final String folder; + public final List uids; + + + public static PendingDelete create(String folder, List uids) { + return new PendingDelete(folder, uids); + } + + private PendingDelete(String folder, List uids) { + this.folder = folder; + this.uids = uids; + } + + @Override + public String getCommandName() { + return COMMAND_DELETE; + } + + @Override + public void execute(MessagingController controller, Account account) throws MessagingException { + controller.processPendingDelete(this, account); + } + } + public static class PendingExpunge extends PendingCommand { public final String folder; diff --git a/app/core/src/main/java/com/fsck/k9/controller/PendingCommandSerializer.java b/app/core/src/main/java/com/fsck/k9/controller/PendingCommandSerializer.java index 27beff3d7..0427e7e9f 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/PendingCommandSerializer.java +++ b/app/core/src/main/java/com/fsck/k9/controller/PendingCommandSerializer.java @@ -9,6 +9,7 @@ import java.util.Map; import com.fsck.k9.controller.MessagingControllerCommands.PendingAppend; import com.fsck.k9.controller.MessagingControllerCommands.PendingCommand; +import com.fsck.k9.controller.MessagingControllerCommands.PendingDelete; import com.fsck.k9.controller.MessagingControllerCommands.PendingEmptyTrash; import com.fsck.k9.controller.MessagingControllerCommands.PendingExpunge; import com.fsck.k9.controller.MessagingControllerCommands.PendingMarkAllAsRead; @@ -35,6 +36,7 @@ public class PendingCommandSerializer { adapters.put(MessagingControllerCommands.COMMAND_EXPUNGE, moshi.adapter(PendingExpunge.class)); adapters.put(MessagingControllerCommands.COMMAND_MARK_ALL_AS_READ, moshi.adapter(PendingMarkAllAsRead.class)); adapters.put(MessagingControllerCommands.COMMAND_SET_FLAG, moshi.adapter(PendingSetFlag.class)); + adapters.put(MessagingControllerCommands.COMMAND_DELETE, moshi.adapter(PendingDelete.class)); this.adapters = Collections.unmodifiableMap(adapters); }