Search in sources :

Example 11 with Backend

use of com.fsck.k9.backend.api.Backend in project k-9 by k9mail.

the class MessagingController method processPendingEmptyTrash.

void processPendingEmptyTrash(Account account) throws MessagingException {
    if (!account.hasTrashFolder()) {
        return;
    }
    long trashFolderId = account.getTrashFolderId();
    LocalStore localStore = localStoreProvider.getInstance(account);
    LocalFolder folder = localStore.getFolder(trashFolderId);
    folder.open();
    String trashFolderServerId = folder.getServerId();
    Backend backend = getBackend(account);
    backend.deleteAllMessages(trashFolderServerId);
    if (account.getExpungePolicy() == Expunge.EXPUNGE_IMMEDIATELY && backend.getSupportsExpunge()) {
        backend.expunge(trashFolderServerId);
    }
    // Remove all messages marked as deleted
    folder.destroyDeletedMessages();
    compact(account, null);
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) Backend(com.fsck.k9.backend.api.Backend) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 12 with Backend

use of com.fsck.k9.backend.api.Backend in project k-9 by k9mail.

the class MessagingControllerTest method sendPendingMessagesSynchronous_shouldSetAndRemoveSendInProgressFlag.

@Test
public void sendPendingMessagesSynchronous_shouldSetAndRemoveSendInProgressFlag() throws MessagingException {
    setupAccountWithMessageToSend();
    controller.sendPendingMessagesSynchronous(account);
    InOrder ordering = inOrder(localMessageToSend1, backend);
    ordering.verify(localMessageToSend1).setFlag(Flag.X_SEND_IN_PROGRESS, true);
    ordering.verify(backend).sendMessage(localMessageToSend1);
    ordering.verify(localMessageToSend1).setFlag(Flag.X_SEND_IN_PROGRESS, false);
}
Also used : InOrder(org.mockito.InOrder) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) Test(org.junit.Test)

Example 13 with Backend

use of com.fsck.k9.backend.api.Backend in project k-9 by k9mail.

the class MessagingController method loadSearchResultsSynchronous.

private void loadSearchResultsSynchronous(Account account, List<String> messageServerIds, LocalFolder localFolder) throws MessagingException {
    Backend backend = getBackend(account);
    String folderServerId = localFolder.getServerId();
    for (String messageServerId : messageServerIds) {
        LocalMessage localMessage = localFolder.getMessage(messageServerId);
        if (localMessage == null) {
            backend.downloadMessageStructure(folderServerId, messageServerId);
        }
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) Backend(com.fsck.k9.backend.api.Backend)

Example 14 with Backend

use of com.fsck.k9.backend.api.Backend in project k-9 by k9mail.

the class MessagingController method sendMessageBlocking.

public void sendMessageBlocking(Account account, Message message) throws MessagingException {
    Backend backend = getBackend(account);
    backend.sendMessage(message);
}
Also used : Backend(com.fsck.k9.backend.api.Backend)

Example 15 with Backend

use of com.fsck.k9.backend.api.Backend in project k-9 by k9mail.

the class MessagingController method processPendingMoveOrCopy.

@VisibleForTesting
void processPendingMoveOrCopy(Account account, long srcFolderId, long destFolderId, List<String> uids, MoveOrCopyFlavor operation, Map<String, String> newUidMap) throws MessagingException {
    checkNotNull(newUidMap);
    LocalStore localStore = localStoreProvider.getInstance(account);
    LocalFolder localSourceFolder = localStore.getFolder(srcFolderId);
    localSourceFolder.open();
    String srcFolderServerId = localSourceFolder.getServerId();
    LocalFolder localDestFolder = localStore.getFolder(destFolderId);
    localDestFolder.open();
    String destFolderServerId = localDestFolder.getServerId();
    Backend backend = getBackend(account);
    Map<String, String> remoteUidMap;
    switch(operation) {
        case COPY:
            remoteUidMap = backend.copyMessages(srcFolderServerId, destFolderServerId, uids);
            break;
        case MOVE:
            remoteUidMap = backend.moveMessages(srcFolderServerId, destFolderServerId, uids);
            break;
        case MOVE_AND_MARK_AS_READ:
            remoteUidMap = backend.moveMessagesAndMarkAsRead(srcFolderServerId, destFolderServerId, uids);
            break;
        default:
            throw new RuntimeException("Unsupported messaging operation");
    }
    if (operation != MoveOrCopyFlavor.COPY) {
        if (backend.getSupportsExpunge() && account.getExpungePolicy() == Expunge.EXPUNGE_IMMEDIATELY) {
            Timber.i("processingPendingMoveOrCopy expunging folder %s:%s", account, srcFolderServerId);
            backend.expungeMessages(srcFolderServerId, uids);
        }
        destroyPlaceholderMessages(localSourceFolder, uids);
    }
    // TODO: Change Backend interface to ensure we never receive null for remoteUidMap
    if (remoteUidMap == null) {
        remoteUidMap = Collections.emptyMap();
    }
    // Update local messages (that currently have local UIDs) with new server IDs
    for (String uid : uids) {
        String localUid = newUidMap.get(uid);
        String newUid = remoteUidMap.get(uid);
        LocalMessage localMessage = localDestFolder.getMessage(localUid);
        if (localMessage == null) {
            // Local message no longer exists
            continue;
        }
        if (newUid != null) {
            // Update local message with new server ID
            localMessage.setUid(newUid);
            localDestFolder.changeUid(localMessage);
            for (MessagingListener l : getListeners()) {
                l.messageUidChanged(account, destFolderId, localUid, newUid);
            }
        } else {
            // New server ID wasn't provided. Remove local message.
            localMessage.destroy();
        }
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) Backend(com.fsck.k9.backend.api.Backend) LocalStore(com.fsck.k9.mailstore.LocalStore) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

Backend (com.fsck.k9.backend.api.Backend)15 LocalFolder (com.fsck.k9.mailstore.LocalFolder)10 LocalStore (com.fsck.k9.mailstore.LocalStore)10 LocalMessage (com.fsck.k9.mailstore.LocalMessage)7 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)6 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)6 MessagingException (com.fsck.k9.mail.MessagingException)6 VisibleForTesting (androidx.annotation.VisibleForTesting)3 K9RobolectricTest (com.fsck.k9.K9RobolectricTest)3 ServerSettings (com.fsck.k9.mail.ServerSettings)3 Test (org.junit.Test)3 SuppressLint (android.annotation.SuppressLint)2 SyncConfig (com.fsck.k9.backend.api.SyncConfig)2 FetchProfile (com.fsck.k9.mail.FetchProfile)2 MessageStore (com.fsck.k9.mailstore.MessageStore)2 ArrayList (java.util.ArrayList)2 Account (com.fsck.k9.Account)1 PendingCommand (com.fsck.k9.controller.MessagingControllerCommands.PendingCommand)1 ExceptionHelper.getRootCauseMessage (com.fsck.k9.helper.ExceptionHelper.getRootCauseMessage)1 Message (com.fsck.k9.mail.Message)1