Merge pull request #3961 from k9mail/add_delete_method_to_backend
Add deleteMessages() method to Backend interface
This commit is contained in:
commit
e1e473592c
10 changed files with 107 additions and 2 deletions
|
@ -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<String> 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);
|
||||
|
|
|
@ -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<String> uids;
|
||||
|
||||
|
||||
public static PendingDelete create(String folder, List<String> uids) {
|
||||
return new PendingDelete(folder, uids);
|
||||
}
|
||||
|
||||
private PendingDelete(String folder, List<String> 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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import timber.log.Timber;
|
|||
|
||||
|
||||
class StoreSchemaDefinition implements SchemaDefinition {
|
||||
static final int DB_VERSION = 68;
|
||||
static final int DB_VERSION = 69;
|
||||
|
||||
private final MigrationsHelper migrationsHelper;
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package com.fsck.k9.storage.migrations
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import com.fsck.k9.controller.MessagingControllerCommands.PendingDelete
|
||||
import com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag
|
||||
import com.fsck.k9.controller.PendingCommandSerializer
|
||||
import com.fsck.k9.mail.Flag
|
||||
|
||||
|
||||
internal class MigrationTo69(private val db: SQLiteDatabase) {
|
||||
private val serializer: PendingCommandSerializer = PendingCommandSerializer.getInstance()
|
||||
|
||||
|
||||
fun createPendingDelete() {
|
||||
val pendingSetFlagsToConvert = mutableListOf<PendingSetFlag>()
|
||||
|
||||
db.rawQuery("SELECT id, command, data FROM pending_commands WHERE command = 'set_flag'", null).use { cursor ->
|
||||
while (cursor.moveToNext()) {
|
||||
val databaseId = cursor.getLong(0)
|
||||
val commandName = cursor.getString(1)
|
||||
val data = cursor.getString(2)
|
||||
|
||||
val pendingSetFlag = serializer.unserialize(databaseId, commandName, data) as PendingSetFlag
|
||||
if (pendingSetFlag.flag == Flag.DELETED && pendingSetFlag.newState) {
|
||||
pendingSetFlagsToConvert.add(pendingSetFlag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (pendingSetFlag in pendingSetFlagsToConvert) {
|
||||
val pendingDelete = PendingDelete.create(pendingSetFlag.folder, pendingSetFlag.uids)
|
||||
val contentValues = ContentValues().apply {
|
||||
put("command", "delete")
|
||||
put("data", serializer.serialize(pendingDelete))
|
||||
}
|
||||
|
||||
db.update("pending_commands", contentValues, "id = ?", arrayOf(pendingSetFlag.databaseId.toString()))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -94,6 +94,8 @@ public class Migrations {
|
|||
MigrationTo67.addTypeColumnToFoldersTable(db, migrationsHelper);
|
||||
case 67:
|
||||
MigrationTo68.addOutboxStateTable(db);
|
||||
case 68:
|
||||
new MigrationTo69(db).createPendingDelete();
|
||||
}
|
||||
|
||||
if (shouldBuildFtsTable) {
|
||||
|
|
|
@ -44,6 +44,9 @@ interface Backend {
|
|||
@Throws(MessagingException::class)
|
||||
fun expungeMessages(folderServerId: String, messageServerIds: List<String>)
|
||||
|
||||
@Throws(MessagingException::class)
|
||||
fun deleteMessages(folderServerId: String, messageServerIds: List<String>)
|
||||
|
||||
@Throws(MessagingException::class)
|
||||
fun deleteAllMessages(folderServerId: String)
|
||||
|
||||
|
|
|
@ -146,6 +146,12 @@ public class ImapBackend implements Backend {
|
|||
commandExpunge.expungeMessages(folderServerId, messageServerIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMessages(@NotNull String folderServerId, @NotNull List<String> messageServerIds)
|
||||
throws MessagingException {
|
||||
commandSetFlag.setFlag(folderServerId, messageServerIds, Flag.DELETED, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllMessages(@NotNull String folderServerId) throws MessagingException {
|
||||
commandDeleteAll.deleteAll(folderServerId);
|
||||
|
|
|
@ -65,6 +65,10 @@ class Pop3Backend(
|
|||
throw UnsupportedOperationException("not supported")
|
||||
}
|
||||
|
||||
override fun deleteMessages(folderServerId: String, messageServerIds: List<String>) {
|
||||
commandSetFlag.setFlag(folderServerId, messageServerIds, Flag.DELETED, true)
|
||||
}
|
||||
|
||||
override fun deleteAllMessages(folderServerId: String) {
|
||||
commandDeleteAll.deleteAll(folderServerId)
|
||||
}
|
||||
|
|
|
@ -70,6 +70,10 @@ class WebDavBackend(
|
|||
throw UnsupportedOperationException("not supported")
|
||||
}
|
||||
|
||||
override fun deleteMessages(folderServerId: String, messageServerIds: List<String>) {
|
||||
commandSetFlag.setFlag(folderServerId, messageServerIds, Flag.DELETED, true)
|
||||
}
|
||||
|
||||
override fun deleteAllMessages(folderServerId: String) {
|
||||
commandDeleteAll.deleteAll(folderServerId)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue