Search in sources :

Example 6 with LocalMessage

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

the class MessagingController method syncFlags.

private boolean syncFlags(LocalMessage localMessage, Message remoteMessage) throws MessagingException {
    boolean messageChanged = false;
    if (localMessage == null || localMessage.isSet(Flag.DELETED)) {
        return false;
    }
    if (remoteMessage.isSet(Flag.DELETED)) {
        if (localMessage.getFolder().syncRemoteDeletions()) {
            localMessage.setFlag(Flag.DELETED, true);
            messageChanged = true;
        }
    } else {
        for (Flag flag : MessagingController.SYNC_FLAGS) {
            if (remoteMessage.isSet(flag) != localMessage.isSet(flag)) {
                localMessage.setFlag(flag, remoteMessage.isSet(flag));
                messageChanged = true;
            }
        }
    }
    return messageChanged;
}
Also used : PendingSetFlag(com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag) Flag(com.fsck.k9.mail.Flag)

Example 7 with LocalMessage

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

the class MessagingController method sendMessage.

/**
     * Stores the given message in the Outbox and starts a sendPendingMessages command to
     * attempt to send the message.
     */
public void sendMessage(final Account account, final Message message, MessagingListener listener) {
    try {
        LocalStore localStore = account.getLocalStore();
        LocalFolder localFolder = localStore.getFolder(account.getOutboxFolderName());
        localFolder.open(Folder.OPEN_MODE_RW);
        localFolder.appendMessages(Collections.singletonList(message));
        Message localMessage = localFolder.getMessage(message.getUid());
        localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
        localFolder.close();
        sendPendingMessages(account, listener);
    } catch (Exception e) {
        /*
            for (MessagingListener l : getListeners())
            {
                // TODO general failed
            }
            */
        addErrorMessage(account, null, e);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) LocalStore(com.fsck.k9.mailstore.LocalStore) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) UnavailableStorageException(com.fsck.k9.mailstore.UnavailableStorageException) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Example 8 with LocalMessage

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

the class MessagingController method actOnMessageGroup.

private void actOnMessageGroup(Account account, String folderName, List<MessageReference> messageReferences, MessageActor actor) {
    try {
        LocalFolder messageFolder = account.getLocalStore().getFolder(folderName);
        List<LocalMessage> localMessages = messageFolder.getMessagesByReference(messageReferences);
        actor.act(account, messageFolder, localMessages);
    } catch (MessagingException e) {
        Timber.e(e, "Error loading account?!");
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessagingException(com.fsck.k9.mail.MessagingException)

Example 9 with LocalMessage

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

the class MessagingController method loadMessage.

public LocalMessage loadMessage(Account account, String folderName, String uid) throws MessagingException {
    LocalStore localStore = account.getLocalStore();
    LocalFolder localFolder = localStore.getFolder(folderName);
    localFolder.open(Folder.OPEN_MODE_RW);
    LocalMessage message = localFolder.getMessage(uid);
    if (message == null || message.getId() == 0) {
        throw new IllegalArgumentException("Message not found: folder=" + folderName + ", uid=" + uid);
    }
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localFolder.fetch(Collections.singletonList(message), fp, null);
    localFolder.close();
    notificationController.removeNewMailNotification(account, message.makeMessageReference());
    markMessageAsReadOnView(account, message);
    return message;
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) FetchProfile(com.fsck.k9.mail.FetchProfile) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 10 with LocalMessage

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

Aggregations

LocalMessage (com.fsck.k9.mailstore.LocalMessage)42 Test (org.junit.Test)23 FetchProfile (com.fsck.k9.mail.FetchProfile)19 Message (com.fsck.k9.mail.Message)19 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)19 MessagingException (com.fsck.k9.mail.MessagingException)15 LocalFolder (com.fsck.k9.mailstore.LocalFolder)13 LocalStore (com.fsck.k9.mailstore.LocalStore)12 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)10 ArrayList (java.util.ArrayList)9 Notification (android.app.Notification)8 Part (com.fsck.k9.mail.Part)8 MessageReference (com.fsck.k9.activity.MessageReference)7 Multipart (com.fsck.k9.mail.Multipart)7 Date (java.util.Date)7 HashMap (java.util.HashMap)7 SuppressLint (android.annotation.SuppressLint)6 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)6 IOException (java.io.IOException)6 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)5