Search in sources :

Example 31 with Flag

use of com.fsck.k9.mail.Flag 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 = account.getLocalStore();
    } 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 name and UID of messages from the database
    Map<String, List<String>> folderMap;
    try {
        folderMap = localStore.getFoldersAndUids(ids, threadedList);
    } catch (MessagingException e) {
        Timber.e(e, "Couldn't get folder name and UID of messages");
        return;
    }
    // Loop over all folders
    for (Entry<String, List<String>> entry : folderMap.entrySet()) {
        String folderName = entry.getKey();
        // Notify listeners of changed folder status
        LocalFolder localFolder = localStore.getFolder(folderName);
        try {
            int unreadMessageCount = localFolder.getUnreadMessageCount();
            for (MessagingListener l : getListeners()) {
                l.folderStatusChanged(account, folderName, unreadMessageCount);
            }
        } catch (MessagingException e) {
            Timber.w(e, "Couldn't get unread count for folder: %s", folderName);
        }
        // TODO: Skip the remote part for all local-only folders
        if (account.getErrorFolderName().equals(folderName)) {
            continue;
        }
        // Send flag change to server
        queueSetFlag(account, folderName, newState, flag, entry.getValue());
        processPendingCommands(account);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) MessagingException(com.fsck.k9.mail.MessagingException) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) LocalStore(com.fsck.k9.mailstore.LocalStore) SuppressLint(android.annotation.SuppressLint)

Example 32 with Flag

use of com.fsck.k9.mail.Flag in project k-9 by k9mail.

the class MessagingController method setFlag.

/**
     * Set or remove a flag for a message referenced by message UID.
     *
     * @param account
     *         The account the folder containing the message belongs to.
     * @param folderName
     *         The name of the folder.
     * @param uid
     *         The UID of the message to change the flag for.
     * @param flag
     *         The flag to change.
     * @param newState
     *         {@code true}, if the flag should be set. {@code false} if it should be removed.
     */
public void setFlag(Account account, String folderName, String uid, Flag flag, boolean newState) {
    Folder localFolder = null;
    try {
        LocalStore localStore = account.getLocalStore();
        localFolder = localStore.getFolder(folderName);
        localFolder.open(Folder.OPEN_MODE_RW);
        Message message = localFolder.getMessage(uid);
        if (message != null) {
            setFlag(account, folderName, Collections.singletonList(message), flag, newState);
        }
    } catch (MessagingException me) {
        addErrorMessage(account, null, me);
        throw new RuntimeException(me);
    } finally {
        closeFolder(localFolder);
    }
}
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) LocalStore(com.fsck.k9.mailstore.LocalStore) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder)

Aggregations

MessagingException (com.fsck.k9.mail.MessagingException)10 Message (com.fsck.k9.mail.Message)9 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)9 LocalMessage (com.fsck.k9.mailstore.LocalMessage)9 Flag (com.fsck.k9.mail.Flag)8 LocalFolder (com.fsck.k9.mailstore.LocalFolder)8 LocalStore (com.fsck.k9.mailstore.LocalStore)8 ArrayList (java.util.ArrayList)8 Folder (com.fsck.k9.mail.Folder)7 PendingSetFlag (com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag)6 Store (com.fsck.k9.mail.Store)6 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)6 Account (com.fsck.k9.Account)5 IOException (java.io.IOException)5 SuppressLint (android.annotation.SuppressLint)4 Cursor (android.database.Cursor)4 EmailProviderCache (com.fsck.k9.cache.EmailProviderCache)4 FetchProfile (com.fsck.k9.mail.FetchProfile)4 OldPendingCommand (com.fsck.k9.mailstore.migrations.MigrationTo60.OldPendingCommand)4 Date (java.util.Date)4