Search in sources :

Example 1 with PendingMoveOrCopy

use of com.fsck.k9.controller.MessagingControllerCommands.PendingMoveOrCopy 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 2 with PendingMoveOrCopy

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

the class MessagingController method processPendingMoveOrCopy.

void processPendingMoveOrCopy(PendingMoveOrCopy command, Account account) throws MessagingException {
    Folder remoteSrcFolder = null;
    Folder remoteDestFolder = null;
    LocalFolder localDestFolder;
    try {
        String srcFolder = command.srcFolder;
        if (account.getErrorFolderName().equals(srcFolder)) {
            return;
        }
        String destFolder = command.destFolder;
        boolean isCopy = command.isCopy;
        Store remoteStore = account.getRemoteStore();
        remoteSrcFolder = remoteStore.getFolder(srcFolder);
        Store localStore = account.getLocalStore();
        localDestFolder = (LocalFolder) localStore.getFolder(destFolder);
        List<Message> messages = new ArrayList<>();
        Collection<String> uids = command.newUidMap != null ? command.newUidMap.keySet() : command.uids;
        for (String uid : uids) {
            if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) {
                messages.add(remoteSrcFolder.getMessage(uid));
            }
        }
        if (!remoteSrcFolder.exists()) {
            throw new MessagingException("processingPendingMoveOrCopy: remoteFolder " + srcFolder + " does not exist", true);
        }
        remoteSrcFolder.open(Folder.OPEN_MODE_RW);
        if (remoteSrcFolder.getMode() != Folder.OPEN_MODE_RW) {
            throw new MessagingException("processingPendingMoveOrCopy: could not open remoteSrcFolder " + srcFolder + " read/write", true);
        }
        Timber.d("processingPendingMoveOrCopy: source folder = %s, %d messages, destination folder = %s, " + "isCopy = %s", srcFolder, messages.size(), destFolder, isCopy);
        Map<String, String> remoteUidMap = null;
        if (!isCopy && destFolder.equals(account.getTrashFolderName())) {
            Timber.d("processingPendingMoveOrCopy doing special case for deleting message");
            String destFolderName = destFolder;
            if (K9.FOLDER_NONE.equals(destFolderName)) {
                destFolderName = null;
            }
            remoteSrcFolder.delete(messages, destFolderName);
        } else {
            remoteDestFolder = remoteStore.getFolder(destFolder);
            if (isCopy) {
                remoteUidMap = remoteSrcFolder.copyMessages(messages, remoteDestFolder);
            } else {
                remoteUidMap = remoteSrcFolder.moveMessages(messages, remoteDestFolder);
            }
        }
        if (!isCopy && Expunge.EXPUNGE_IMMEDIATELY == account.getExpungePolicy()) {
            Timber.i("processingPendingMoveOrCopy expunging folder %s:%s", account.getDescription(), srcFolder);
            remoteSrcFolder.expunge();
        }
        /*
             * This next part is used to bring the local UIDs of the local destination folder
             * upto speed with the remote UIDs of remote destination folder.
             */
        if (command.newUidMap != null && remoteUidMap != null && !remoteUidMap.isEmpty()) {
            for (Map.Entry<String, String> entry : remoteUidMap.entrySet()) {
                String remoteSrcUid = entry.getKey();
                String newUid = entry.getValue();
                String localDestUid = command.newUidMap.get(remoteSrcUid);
                if (localDestUid == null) {
                    continue;
                }
                Message localDestMessage = localDestFolder.getMessage(localDestUid);
                if (localDestMessage != null) {
                    localDestMessage.setUid(newUid);
                    localDestFolder.changeUid((LocalMessage) localDestMessage);
                    for (MessagingListener l : getListeners()) {
                        l.messageUidChanged(account, destFolder, localDestUid, newUid);
                    }
                }
            }
        }
    } finally {
        closeFolder(remoteSrcFolder);
        closeFolder(remoteDestFolder);
    }
}
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) 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) LocalFolder(com.fsck.k9.mailstore.LocalFolder) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 3 with PendingMoveOrCopy

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

the class MigrationTo60Test method migrateMoveOrCopy_withUidArray.

@Test
public void migrateMoveOrCopy_withUidArray() {
    OldPendingCommand command = queueMoveOrCopy(SOURCE_FOLDER, DEST_FOLDER, IS_COPY, UID_ARRAY);
    PendingMoveOrCopy pendingCommand = (PendingMoveOrCopy) MigrationTo60.migratePendingCommand(command);
    assertEquals(SOURCE_FOLDER, pendingCommand.srcFolder);
    assertEquals(DEST_FOLDER, pendingCommand.destFolder);
    assertEquals(IS_COPY, pendingCommand.isCopy);
    assertEquals(asList(UID_ARRAY), 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 4 with PendingMoveOrCopy

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

the class MigrationTo60Test method migrateMoveOrCopy_withOldFormat.

@Test
public void migrateMoveOrCopy_withOldFormat() {
    OldPendingCommand command = queueMoveOrCopyOld(SOURCE_FOLDER, DEST_FOLDER, IS_COPY, UID_ARRAY);
    PendingMoveOrCopy pendingCommand = (PendingMoveOrCopy) MigrationTo60.migratePendingCommand(command);
    assertEquals(SOURCE_FOLDER, pendingCommand.srcFolder);
    assertEquals(DEST_FOLDER, pendingCommand.destFolder);
    assertEquals(IS_COPY, pendingCommand.isCopy);
    assertEquals(asList(UID_ARRAY), 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 5 with PendingMoveOrCopy

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

the class MigrationTo60Test method migrateMoveOrCopy_withUidMap.

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

Aggregations

PendingMoveOrCopy (com.fsck.k9.controller.MessagingControllerCommands.PendingMoveOrCopy)5 Test (org.junit.Test)5 OldPendingCommand (com.fsck.k9.mailstore.migrations.MigrationTo60.OldPendingCommand)4 PendingCommand (com.fsck.k9.controller.MessagingControllerCommands.PendingCommand)1 Folder (com.fsck.k9.mail.Folder)1 Message (com.fsck.k9.mail.Message)1 MessagingException (com.fsck.k9.mail.MessagingException)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 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1