Search in sources :

Example 11 with Message

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

the class MessagingController method unsuppressMessages.

private void unsuppressMessages(Account account, List<? extends Message> messages) {
    EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid(), context);
    cache.unhideMessages(messages);
}
Also used : EmailProviderCache(com.fsck.k9.cache.EmailProviderCache)

Example 12 with Message

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

the class MessagingController method processPendingSetFlag.

/**
     * Processes a pending mark read or unread command.
     */
void processPendingSetFlag(PendingSetFlag command, Account account) throws MessagingException {
    String folder = command.folder;
    if (account.getErrorFolderName().equals(folder) || account.getOutboxFolderName().equals(folder)) {
        return;
    }
    boolean newState = command.newState;
    Flag flag = command.flag;
    Store remoteStore = account.getRemoteStore();
    Folder remoteFolder = remoteStore.getFolder(folder);
    if (!remoteFolder.exists() || !remoteFolder.isFlagSupported(flag)) {
        return;
    }
    try {
        remoteFolder.open(Folder.OPEN_MODE_RW);
        if (remoteFolder.getMode() != Folder.OPEN_MODE_RW) {
            return;
        }
        List<Message> messages = new ArrayList<>();
        for (String uid : command.uids) {
            if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) {
                messages.add(remoteFolder.getMessage(uid));
            }
        }
        if (messages.isEmpty()) {
            return;
        }
        remoteFolder.setFlags(messages, Collections.singleton(flag), newState);
    } finally {
        closeFolder(remoteFolder);
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) 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) PendingSetFlag(com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag) Flag(com.fsck.k9.mail.Flag)

Example 13 with Message

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

the class MessagingController method evaluateMessageForDownload.

private void evaluateMessageForDownload(final Message message, final String folder, final LocalFolder localFolder, final Folder remoteFolder, final Account account, final List<Message> unsyncedMessages, final List<Message> syncFlagMessages, boolean flagSyncOnly) throws MessagingException {
    if (message.isSet(Flag.DELETED)) {
        Timber.v("Message with uid %s is marked as deleted", message.getUid());
        syncFlagMessages.add(message);
        return;
    }
    Message localMessage = localFolder.getMessage(message.getUid());
    if (localMessage == null) {
        if (!flagSyncOnly) {
            if (!message.isSet(Flag.X_DOWNLOADED_FULL) && !message.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
                Timber.v("Message with uid %s has not yet been downloaded", message.getUid());
                unsyncedMessages.add(message);
            } else {
                Timber.v("Message with uid %s is partially or fully downloaded", message.getUid());
                // Store the updated message locally
                localFolder.appendMessages(Collections.singletonList(message));
                localMessage = localFolder.getMessage(message.getUid());
                localMessage.setFlag(Flag.X_DOWNLOADED_FULL, message.isSet(Flag.X_DOWNLOADED_FULL));
                localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, message.isSet(Flag.X_DOWNLOADED_PARTIAL));
                for (MessagingListener l : getListeners()) {
                    if (!localMessage.isSet(Flag.SEEN)) {
                        l.synchronizeMailboxNewMessage(account, folder, localMessage);
                    }
                }
            }
        }
    } else if (!localMessage.isSet(Flag.DELETED)) {
        Timber.v("Message with uid %s is present in the local store", message.getUid());
        if (!localMessage.isSet(Flag.X_DOWNLOADED_FULL) && !localMessage.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
            Timber.v("Message with uid %s is not downloaded, even partially; trying again", message.getUid());
            unsyncedMessages.add(message);
        } else {
            String newPushState = remoteFolder.getNewPushState(localFolder.getPushState(), message);
            if (newPushState != null) {
                localFolder.setPushState(newPushState);
            }
            syncFlagMessages.add(message);
        }
    } else {
        Timber.v("Local copy of message with uid %s is marked as deleted", message.getUid());
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message)

Example 14 with Message

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

the class MessageListFragment method changeSort.

/**
     * Change the sort type and sort order used for the message list.
     *
     * @param sortType
     *         Specifies which field to use for sorting the message list.
     * @param sortAscending
     *         Specifies the sort order. If this argument is {@code null} the default search order
     *         for the sort type is used.
     */
// FIXME: Don't save the changes in the UI thread
private void changeSort(SortType sortType, Boolean sortAscending) {
    this.sortType = sortType;
    Account account = this.account;
    if (account != null) {
        account.setSortType(this.sortType);
        if (sortAscending == null) {
            this.sortAscending = account.isSortAscending(this.sortType);
        } else {
            this.sortAscending = sortAscending;
        }
        account.setSortAscending(this.sortType, this.sortAscending);
        sortDateAscending = account.isSortAscending(SortType.SORT_DATE);
        account.save(preferences);
    } else {
        K9.setSortType(this.sortType);
        if (sortAscending == null) {
            this.sortAscending = K9.isSortAscending(this.sortType);
        } else {
            this.sortAscending = sortAscending;
        }
        K9.setSortAscending(this.sortType, this.sortAscending);
        sortDateAscending = K9.isSortAscending(SortType.SORT_DATE);
        StorageEditor editor = preferences.getStorage().edit();
        K9.save(editor);
        editor.commit();
    }
    reSort();
}
Also used : Account(com.fsck.k9.Account) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 15 with Message

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

the class MessageListFragment method getCheckedMessages.

private List<MessageReference> getCheckedMessages() {
    List<MessageReference> messages = new ArrayList<>(selected.size());
    for (int position = 0, end = adapter.getCount(); position < end; position++) {
        Cursor cursor = (Cursor) adapter.getItem(position);
        long uniqueId = cursor.getLong(uniqueIdColumn);
        if (selected.contains(uniqueId)) {
            MessageReference message = getMessageAtPosition(position);
            if (message != null) {
                messages.add(message);
            }
        }
    }
    return messages;
}
Also used : ArrayList(java.util.ArrayList) MessageReference(com.fsck.k9.activity.MessageReference) Cursor(android.database.Cursor)

Aggregations

Test (org.junit.Test)127 Message (com.fsck.k9.mail.Message)111 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)102 Part (com.fsck.k9.mail.Part)47 LocalMessage (com.fsck.k9.mailstore.LocalMessage)46 MessagingException (com.fsck.k9.mail.MessagingException)41 ArrayList (java.util.ArrayList)41 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)33 BodyPart (com.fsck.k9.mail.BodyPart)32 Account (com.fsck.k9.Account)27 LocalFolder (com.fsck.k9.mailstore.LocalFolder)24 TextBody (com.fsck.k9.mail.internet.TextBody)23 IOException (java.io.IOException)22 Address (com.fsck.k9.mail.Address)21 LocalStore (com.fsck.k9.mailstore.LocalStore)21 Date (java.util.Date)20 MessageReference (com.fsck.k9.activity.MessageReference)16 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)16 Folder (com.fsck.k9.mail.Folder)14 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)13