Search in sources :

Example 76 with LocalFolder

use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.

the class MessagingController method setFlagSynchronous.

private void setFlagSynchronous(final Account account, final List<Long> ids, final Flag flag, final boolean newState, final boolean threadedList) {
    LocalStore localStore;
    try {
        localStore = localStoreProvider.getInstance(account);
    } catch (MessagingException e) {
        Timber.e(e, "Couldn't get LocalStore instance");
        return;
    }
    // can be updated with the new state.
    try {
        if (threadedList) {
            localStore.setFlagForThreads(ids, flag, newState);
            removeFlagForThreadsFromCache(account, ids, flag);
        } else {
            localStore.setFlag(ids, flag, newState);
            removeFlagFromCache(account, ids, flag);
        }
    } catch (MessagingException e) {
        Timber.e(e, "Couldn't set flags in local database");
    }
    // Read folder ID and UID of messages from the database
    Map<Long, List<String>> folderMap;
    try {
        folderMap = localStore.getFolderIdsAndUids(ids, threadedList);
    } catch (MessagingException e) {
        Timber.e(e, "Couldn't get folder name and UID of messages");
        return;
    }
    boolean accountSupportsFlags = supportsFlags(account);
    // Loop over all folders
    for (Entry<Long, List<String>> entry : folderMap.entrySet()) {
        long folderId = entry.getKey();
        List<String> uids = entry.getValue();
        // Notify listeners of changed folder status
        for (MessagingListener l : getListeners()) {
            l.folderStatusChanged(account, folderId);
        }
        if (flag == Flag.SEEN && newState) {
            cancelNotificationsForMessages(account, folderId, uids);
        }
        if (accountSupportsFlags) {
            LocalFolder localFolder = localStore.getFolder(folderId);
            try {
                localFolder.open();
                if (!localFolder.isLocalOnly()) {
                    // Send flag change to server
                    queueSetFlag(account, folderId, newState, flag, uids);
                    processPendingCommands(account);
                }
            } catch (MessagingException e) {
                Timber.e(e, "Couldn't open folder. Account: %s, folder ID: %d", account, folderId);
            }
        }
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) MessagingException(com.fsck.k9.mail.MessagingException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 77 with LocalFolder

use of com.fsck.k9.mailstore.LocalFolder 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 78 with LocalFolder

use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.

the class MessagingController method getFolderUnreadMessageCount.

public int getFolderUnreadMessageCount(Account account, Long folderId) throws MessagingException {
    LocalStore localStore = localStoreProvider.getInstance(account);
    LocalFolder localFolder = localStore.getFolder(folderId);
    return localFolder.getUnreadMessageCount();
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 79 with LocalFolder

use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.

the class MessagingController method setFlag.

/**
 * Set or remove a flag for a message referenced by message UID.
 */
public void setFlag(Account account, long folderId, String uid, Flag flag, boolean newState) {
    try {
        LocalStore localStore = localStoreProvider.getInstance(account);
        LocalFolder localFolder = localStore.getFolder(folderId);
        localFolder.open();
        LocalMessage message = localFolder.getMessage(uid);
        if (message != null) {
            setFlag(account, folderId, Collections.singletonList(message), flag, newState);
        }
    } catch (MessagingException me) {
        throw new RuntimeException(me);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessagingException(com.fsck.k9.mail.MessagingException) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 80 with LocalFolder

use of com.fsck.k9.mailstore.LocalFolder 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

LocalFolder (com.fsck.k9.mailstore.LocalFolder)62 LocalStore (com.fsck.k9.mailstore.LocalStore)47 MessagingException (com.fsck.k9.mail.MessagingException)44 LocalMessage (com.fsck.k9.mailstore.LocalMessage)40 Message (com.fsck.k9.mail.Message)20 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)20 Folder (com.fsck.k9.mail.Folder)17 FetchProfile (com.fsck.k9.mail.FetchProfile)15 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)13 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)13 ArrayList (java.util.ArrayList)13 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)11 SuppressLint (android.annotation.SuppressLint)10 Backend (com.fsck.k9.backend.api.Backend)10 Store (com.fsck.k9.mail.Store)10 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)10 IOException (java.io.IOException)9 Date (java.util.Date)9 Test (org.junit.Test)9 Account (com.fsck.k9.Account)7