Search in sources :

Example 1 with PendingSetFlag

use of com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag in project k-9 by k9mail.

the class MessagingController method processPendingSetFlag.

/**
     * Processes a pending mark read or unread command.
     */
void processPendingSetFlag(PendingSetFlag command, Account account) throws MessagingException {
    String folder = command.folder;
    if (account.getErrorFolderName().equals(folder) || account.getOutboxFolderName().equals(folder)) {
        return;
    }
    boolean newState = command.newState;
    Flag flag = command.flag;
    Store remoteStore = account.getRemoteStore();
    Folder remoteFolder = remoteStore.getFolder(folder);
    if (!remoteFolder.exists() || !remoteFolder.isFlagSupported(flag)) {
        return;
    }
    try {
        remoteFolder.open(Folder.OPEN_MODE_RW);
        if (remoteFolder.getMode() != Folder.OPEN_MODE_RW) {
            return;
        }
        List<Message> messages = new ArrayList<>();
        for (String uid : command.uids) {
            if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) {
                messages.add(remoteFolder.getMessage(uid));
            }
        }
        if (messages.isEmpty()) {
            return;
        }
        remoteFolder.setFlags(messages, Collections.singleton(flag), newState);
    } finally {
        closeFolder(remoteFolder);
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) ArrayList(java.util.ArrayList) LocalStore(com.fsck.k9.mailstore.LocalStore) Store(com.fsck.k9.mail.Store) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) PendingSetFlag(com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag) Flag(com.fsck.k9.mail.Flag)

Example 2 with PendingSetFlag

use of com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag in project k-9 by k9mail.

the class MigrationTo60Test method migrateSetFlag_oldFormat.

@Test
public void migrateSetFlag_oldFormat() {
    OldPendingCommand command = queueSetFlagOld(SOURCE_FOLDER, FLAG_STATE, FLAG, UID);
    PendingSetFlag pendingCommand = (PendingSetFlag) MigrationTo60.migratePendingCommand(command);
    assertEquals(SOURCE_FOLDER, pendingCommand.folder);
    assertEquals(FLAG_STATE, pendingCommand.newState);
    assertEquals(FLAG, pendingCommand.flag);
    assertEquals(Collections.singletonList(UID), pendingCommand.uids);
}
Also used : PendingSetFlag(com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag) OldPendingCommand(com.fsck.k9.mailstore.migrations.MigrationTo60.OldPendingCommand) Test(org.junit.Test)

Example 3 with PendingSetFlag

use of com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag in project k-9 by k9mail.

the class MigrationTo60Test method migrateSetFlag.

@Test
public void migrateSetFlag() {
    OldPendingCommand command = queueSetFlagBulk(SOURCE_FOLDER, FLAG_STATE, FLAG, UID_ARRAY);
    PendingSetFlag pendingCommand = (PendingSetFlag) MigrationTo60.migratePendingCommand(command);
    assertEquals(SOURCE_FOLDER, pendingCommand.folder);
    assertEquals(FLAG_STATE, pendingCommand.newState);
    assertEquals(FLAG, pendingCommand.flag);
    assertEquals(asList(UID_ARRAY), pendingCommand.uids);
}
Also used : PendingSetFlag(com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag) OldPendingCommand(com.fsck.k9.mailstore.migrations.MigrationTo60.OldPendingCommand) Test(org.junit.Test)

Aggregations

PendingSetFlag (com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag)3 OldPendingCommand (com.fsck.k9.mailstore.migrations.MigrationTo60.OldPendingCommand)2 Test (org.junit.Test)2 Flag (com.fsck.k9.mail.Flag)1 Folder (com.fsck.k9.mail.Folder)1 Message (com.fsck.k9.mail.Message)1 Store (com.fsck.k9.mail.Store)1 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)1 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)1 LocalFolder (com.fsck.k9.mailstore.LocalFolder)1 LocalMessage (com.fsck.k9.mailstore.LocalMessage)1 LocalStore (com.fsck.k9.mailstore.LocalStore)1 ArrayList (java.util.ArrayList)1