Search in sources :

Example 1 with PendingMarkAllAsRead

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

the class MigrationTo60Test method migrateMarkAllMessagesRead.

@Test
public void migrateMarkAllMessagesRead() {
    OldPendingCommand command = queueMarkAllMessagesRead(SOURCE_FOLDER);
    PendingMarkAllAsRead pendingCommand = (PendingMarkAllAsRead) MigrationTo60.migratePendingCommand(command);
    assertEquals(SOURCE_FOLDER, pendingCommand.folder);
}
Also used : PendingMarkAllAsRead(com.fsck.k9.controller.MessagingControllerCommands.PendingMarkAllAsRead) OldPendingCommand(com.fsck.k9.mailstore.migrations.MigrationTo60.OldPendingCommand) Test(org.junit.Test)

Example 2 with PendingMarkAllAsRead

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

the class MessagingController method processPendingMarkAllAsRead.

void processPendingMarkAllAsRead(PendingMarkAllAsRead command, Account account) throws MessagingException {
    String folder = command.folder;
    Folder remoteFolder = null;
    LocalFolder localFolder = null;
    try {
        Store localStore = account.getLocalStore();
        localFolder = (LocalFolder) localStore.getFolder(folder);
        localFolder.open(Folder.OPEN_MODE_RW);
        List<? extends Message> messages = localFolder.getMessages(null, false);
        for (Message message : messages) {
            if (!message.isSet(Flag.SEEN)) {
                message.setFlag(Flag.SEEN, true);
            }
        }
        for (MessagingListener l : getListeners()) {
            l.folderStatusChanged(account, folder, 0);
        }
        if (account.getErrorFolderName().equals(folder)) {
            return;
        }
        Store remoteStore = account.getRemoteStore();
        remoteFolder = remoteStore.getFolder(folder);
        if (!remoteFolder.exists() || !remoteFolder.isFlagSupported(Flag.SEEN)) {
            return;
        }
        remoteFolder.open(Folder.OPEN_MODE_RW);
        if (remoteFolder.getMode() != Folder.OPEN_MODE_RW) {
            return;
        }
        remoteFolder.setFlags(Collections.singleton(Flag.SEEN), true);
        remoteFolder.close();
    } catch (UnsupportedOperationException uoe) {
        Timber.w(uoe, "Could not mark all server-side as read because store doesn't support operation");
    } finally {
        closeFolder(localFolder);
        closeFolder(remoteFolder);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) 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)

Aggregations

PendingMarkAllAsRead (com.fsck.k9.controller.MessagingControllerCommands.PendingMarkAllAsRead)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 OldPendingCommand (com.fsck.k9.mailstore.migrations.MigrationTo60.OldPendingCommand)1 Test (org.junit.Test)1