Search in sources :

Example 1 with PendingCommand

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

the class MigrationTo60Test method migrateExpunge.

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

Example 2 with PendingCommand

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

the class MigrationTo60Test method migrateMoveOrCopy__withEvenOlderFormat.

@Test
public void migrateMoveOrCopy__withEvenOlderFormat() {
    OldPendingCommand command = queueMoveOrCopyEvenOlder(SOURCE_FOLDER, DEST_FOLDER, UID, IS_COPY);
    PendingMoveOrCopy pendingCommand = (PendingMoveOrCopy) MigrationTo60.migratePendingCommand(command);
    assertEquals(SOURCE_FOLDER, pendingCommand.srcFolder);
    assertEquals(DEST_FOLDER, pendingCommand.destFolder);
    assertEquals(IS_COPY, pendingCommand.isCopy);
    assertEquals(Collections.singletonList(UID), pendingCommand.uids);
    assertNull(pendingCommand.newUidMap);
}
Also used : PendingMoveOrCopy(com.fsck.k9.controller.MessagingControllerCommands.PendingMoveOrCopy) OldPendingCommand(com.fsck.k9.mailstore.migrations.MigrationTo60.OldPendingCommand) Test(org.junit.Test)

Example 3 with PendingCommand

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

the class MessagingController method deleteMessagesSynchronous.

private void deleteMessagesSynchronous(final Account account, final String folder, final List<? extends Message> messages, MessagingListener listener) {
    Folder localFolder = null;
    Folder localTrashFolder = null;
    List<String> uids = getUidsFromMessages(messages);
    try {
        //as messages get a new UID after being moved
        for (Message message : messages) {
            for (MessagingListener l : getListeners(listener)) {
                l.messageDeleted(account, folder, message);
            }
        }
        Store localStore = account.getLocalStore();
        localFolder = localStore.getFolder(folder);
        Map<String, String> uidMap = null;
        if (folder.equals(account.getTrashFolderName()) || !account.hasTrashFolder()) {
            Timber.d("Deleting messages in trash folder or trash set to -None-, not copying");
            localFolder.setFlags(messages, Collections.singleton(Flag.DELETED), true);
        } else {
            localTrashFolder = localStore.getFolder(account.getTrashFolderName());
            if (!localTrashFolder.exists()) {
                localTrashFolder.create(Folder.FolderType.HOLDS_MESSAGES);
            }
            if (localTrashFolder.exists()) {
                Timber.d("Deleting messages in normal folder, moving");
                uidMap = localFolder.moveMessages(messages, localTrashFolder);
            }
        }
        for (MessagingListener l : getListeners()) {
            l.folderStatusChanged(account, folder, localFolder.getUnreadMessageCount());
            if (localTrashFolder != null) {
                l.folderStatusChanged(account, account.getTrashFolderName(), localTrashFolder.getUnreadMessageCount());
            }
        }
        Timber.d("Delete policy for account %s is %s", account.getDescription(), account.getDeletePolicy());
        if (folder.equals(account.getOutboxFolderName())) {
            for (Message message : messages) {
                // If the message was in the Outbox, then it has been copied to local Trash, and has
                // to be copied to remote trash
                PendingCommand command = PendingAppend.create(account.getTrashFolderName(), message.getUid());
                queuePendingCommand(account, command);
            }
            processPendingCommands(account);
        } else if (account.getDeletePolicy() == DeletePolicy.ON_DELETE) {
            if (folder.equals(account.getTrashFolderName())) {
                queueSetFlag(account, folder, true, Flag.DELETED, uids);
            } else {
                queueMoveOrCopy(account, folder, account.getTrashFolderName(), false, uids, uidMap);
            }
            processPendingCommands(account);
        } else if (account.getDeletePolicy() == DeletePolicy.MARK_AS_READ) {
            queueSetFlag(account, folder, true, Flag.SEEN, uids);
            processPendingCommands(account);
        } else {
            Timber.d("Delete policy %s prevents delete from server", account.getDeletePolicy());
        }
        unsuppressMessages(account, messages);
    } catch (UnavailableStorageException e) {
        Timber.i("Failed to delete message because storage is not available - trying again later.");
        throw new UnavailableAccountException(e);
    } catch (MessagingException me) {
        addErrorMessage(account, null, me);
        throw new RuntimeException("Error deleting message from local store.", me);
    } finally {
        closeFolder(localFolder);
        closeFolder(localTrashFolder);
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MessagingException(com.fsck.k9.mail.MessagingException) UnavailableStorageException(com.fsck.k9.mailstore.UnavailableStorageException) 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) PendingCommand(com.fsck.k9.controller.MessagingControllerCommands.PendingCommand)

Example 4 with PendingCommand

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

the class MessagingController method saveDraft.

/**
     * Save a draft message.
     *
     * @param account
     *         Account we are saving for.
     * @param message
     *         Message to save.
     *
     * @return Message representing the entry in the local store.
     */
public Message saveDraft(final Account account, final Message message, long existingDraftId, boolean saveRemotely) {
    Message localMessage = null;
    try {
        LocalStore localStore = account.getLocalStore();
        LocalFolder localFolder = localStore.getFolder(account.getDraftsFolderName());
        localFolder.open(Folder.OPEN_MODE_RW);
        if (existingDraftId != INVALID_MESSAGE_ID) {
            String uid = localFolder.getMessageUidById(existingDraftId);
            message.setUid(uid);
        }
        // Save the message to the store.
        localFolder.appendMessages(Collections.singletonList(message));
        // Fetch the message back from the store.  This is the Message that's returned to the caller.
        localMessage = localFolder.getMessage(message.getUid());
        localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
        if (saveRemotely) {
            PendingCommand command = PendingAppend.create(localFolder.getName(), localMessage.getUid());
            queuePendingCommand(account, command);
            processPendingCommands(account);
        }
    } catch (MessagingException e) {
        Timber.e(e, "Unable to save message as draft.");
        addErrorMessage(account, null, e);
    }
    return localMessage;
}
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) MessagingException(com.fsck.k9.mail.MessagingException) LocalStore(com.fsck.k9.mailstore.LocalStore) PendingCommand(com.fsck.k9.controller.MessagingControllerCommands.PendingCommand)

Example 5 with PendingCommand

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

the class MessagingController method queueMoveOrCopy.

private void queueMoveOrCopy(Account account, String srcFolder, String destFolder, boolean isCopy, List<String> uids, Map<String, String> uidMap) {
    if (uidMap == null || uidMap.isEmpty()) {
        queueMoveOrCopy(account, srcFolder, destFolder, isCopy, uids);
    } else {
        if (account.getErrorFolderName().equals(srcFolder)) {
            return;
        }
        PendingCommand command = PendingMoveOrCopy.create(srcFolder, destFolder, isCopy, uidMap);
        queuePendingCommand(account, command);
    }
}
Also used : PendingCommand(com.fsck.k9.controller.MessagingControllerCommands.PendingCommand)

Aggregations

PendingCommand (com.fsck.k9.controller.MessagingControllerCommands.PendingCommand)21 Test (org.junit.Test)14 OldPendingCommand (com.fsck.k9.mailstore.migrations.MigrationTo60.OldPendingCommand)10 PendingMoveOrCopy (com.fsck.k9.controller.MessagingControllerCommands.PendingMoveOrCopy)5 MessagingException (com.fsck.k9.mail.MessagingException)5 LocalFolder (com.fsck.k9.mailstore.LocalFolder)5 LocalStore (com.fsck.k9.mailstore.LocalStore)5 PendingSetFlag (com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag)4 LocalMessage (com.fsck.k9.mailstore.LocalMessage)3 ArrayList (java.util.ArrayList)3 PendingAppend (com.fsck.k9.controller.MessagingControllerCommands.PendingAppend)2 PendingEmptyTrash (com.fsck.k9.controller.MessagingControllerCommands.PendingEmptyTrash)2 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)2 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)2 Flag (com.fsck.k9.mail.Flag)2 Message (com.fsck.k9.mail.Message)2 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)2 MessageStore (com.fsck.k9.mailstore.MessageStore)2 ContentValues (android.content.ContentValues)1 Backend (com.fsck.k9.backend.api.Backend)1