Search in sources :

Example 61 with LocalMessage

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

the class MessagingController method loadSearchResultsSynchronous.

private void loadSearchResultsSynchronous(List<Message> messages, LocalFolder localFolder, Folder remoteFolder, MessagingListener listener) throws MessagingException {
    final FetchProfile header = new FetchProfile();
    header.add(FetchProfile.Item.FLAGS);
    header.add(FetchProfile.Item.ENVELOPE);
    final FetchProfile structure = new FetchProfile();
    structure.add(FetchProfile.Item.STRUCTURE);
    int i = 0;
    for (Message message : messages) {
        i++;
        LocalMessage localMsg = localFolder.getMessage(message.getUid());
        if (localMsg == null) {
            remoteFolder.fetch(Collections.singletonList(message), header, null);
            //fun fact: ImapFolder.fetch can't handle getting STRUCTURE at same time as headers
            remoteFolder.fetch(Collections.singletonList(message), structure, null);
            localFolder.appendMessages(Collections.singletonList(message));
            localMsg = localFolder.getMessage(message.getUid());
        }
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) FetchProfile(com.fsck.k9.mail.FetchProfile) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) SuppressLint(android.annotation.SuppressLint)

Example 62 with LocalMessage

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

the class MessagingController method downloadSmallMessages.

private <T extends Message> void downloadSmallMessages(final Account account, final Folder<T> remoteFolder, final LocalFolder localFolder, List<T> smallMessages, final AtomicInteger progress, final int unreadBeforeStart, final AtomicInteger newMessages, final int todo, FetchProfile fp) throws MessagingException {
    final String folder = remoteFolder.getName();
    final Date earliestDate = account.getEarliestPollDate();
    Timber.d("SYNC: Fetching %d small messages for folder %s", smallMessages.size(), folder);
    remoteFolder.fetch(smallMessages, fp, new MessageRetrievalListener<T>() {

        @Override
        public void messageFinished(final T message, int number, int ofTotal) {
            try {
                if (!shouldImportMessage(account, message, earliestDate)) {
                    progress.incrementAndGet();
                    return;
                }
                // Store the updated message locally
                final LocalMessage localMessage = localFolder.storeSmallMessage(message, new Runnable() {

                    @Override
                    public void run() {
                        progress.incrementAndGet();
                    }
                });
                // not marked as read.
                if (!localMessage.isSet(Flag.SEEN)) {
                    newMessages.incrementAndGet();
                }
                Timber.v("About to notify listeners that we got a new small message %s:%s:%s", account, folder, message.getUid());
                // Update the listener with what we've found
                for (MessagingListener l : getListeners()) {
                    l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
                    if (!localMessage.isSet(Flag.SEEN)) {
                        l.synchronizeMailboxNewMessage(account, folder, localMessage);
                    }
                }
                if (shouldNotifyForMessage(account, localFolder, message)) {
                    // Notify with the localMessage so that we don't have to recalculate the content preview.
                    notificationController.addNewMailNotification(account, localMessage, unreadBeforeStart);
                }
            } catch (MessagingException me) {
                addErrorMessage(account, null, me);
                Timber.e(me, "SYNC: fetch small messages");
            }
        }

        @Override
        public void messageStarted(String uid, int number, int ofTotal) {
        }

        @Override
        public void messagesFinished(int total) {
        }
    });
    Timber.d("SYNC: Done fetching small messages for folder %s", folder);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessagingException(com.fsck.k9.mail.MessagingException) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint)

Example 63 with LocalMessage

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

the class MessagingController method suppressMessages.

private void suppressMessages(Account account, List<LocalMessage> messages) {
    EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid(), context);
    cache.hideMessages(messages);
}
Also used : EmailProviderCache(com.fsck.k9.cache.EmailProviderCache)

Example 64 with LocalMessage

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

the class MessagingController method collectMessagesInThreads.

private static List<Message> collectMessagesInThreads(Account account, List<? extends Message> messages) throws MessagingException {
    LocalStore localStore = account.getLocalStore();
    List<Message> messagesInThreads = new ArrayList<>();
    for (Message message : messages) {
        LocalMessage localMessage = (LocalMessage) message;
        long rootId = localMessage.getRootId();
        long threadId = (rootId == -1) ? localMessage.getThreadId() : rootId;
        List<? extends Message> messagesInThread = localStore.getMessagesInThread(threadId);
        messagesInThreads.addAll(messagesInThread);
    }
    return messagesInThreads;
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) 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)

Example 65 with LocalMessage

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

the class MessageCompose method processDraftMessage.

private void processDraftMessage(MessageViewInfo messageViewInfo) {
    Message message = messageViewInfo.message;
    draftId = MessagingController.getInstance(getApplication()).getId(message);
    subjectView.setText(message.getSubject());
    recipientPresenter.initFromDraftMessage(message);
    // Read In-Reply-To header from draft
    final String[] inReplyTo = message.getHeader("In-Reply-To");
    if (inReplyTo.length >= 1) {
        repliedToMessageId = inReplyTo[0];
    }
    // Read References header from draft
    final String[] references = message.getHeader("References");
    if (references.length >= 1) {
        referencedMessageIds = references[0];
    }
    if (!relatedMessageProcessed) {
        attachmentPresenter.loadNonInlineAttachments(messageViewInfo);
    }
    // Decode the identity header when loading a draft.
    // See buildIdentityHeader(TextBody) for a detailed description of the composition of this blob.
    Map<IdentityField, String> k9identity = new HashMap<>();
    String[] identityHeaders = message.getHeader(K9.IDENTITY_HEADER);
    if (identityHeaders.length > 0 && identityHeaders[0] != null) {
        k9identity = IdentityHeaderParser.parse(identityHeaders[0]);
    }
    Identity newIdentity = new Identity();
    if (k9identity.containsKey(IdentityField.SIGNATURE)) {
        newIdentity.setSignatureUse(true);
        newIdentity.setSignature(k9identity.get(IdentityField.SIGNATURE));
        signatureChanged = true;
    } else {
        if (message instanceof LocalMessage) {
            newIdentity.setSignatureUse(((LocalMessage) message).getFolder().getSignatureUse());
        }
        newIdentity.setSignature(identity.getSignature());
    }
    if (k9identity.containsKey(IdentityField.NAME)) {
        newIdentity.setName(k9identity.get(IdentityField.NAME));
        identityChanged = true;
    } else {
        newIdentity.setName(identity.getName());
    }
    if (k9identity.containsKey(IdentityField.EMAIL)) {
        newIdentity.setEmail(k9identity.get(IdentityField.EMAIL));
        identityChanged = true;
    } else {
        newIdentity.setEmail(identity.getEmail());
    }
    if (k9identity.containsKey(IdentityField.ORIGINAL_MESSAGE)) {
        relatedMessageReference = null;
        String originalMessage = k9identity.get(IdentityField.ORIGINAL_MESSAGE);
        MessageReference messageReference = MessageReference.parse(originalMessage);
        if (messageReference != null) {
            // Check if this is a valid account in our database
            Preferences prefs = Preferences.getPreferences(getApplicationContext());
            Account account = prefs.getAccount(messageReference.getAccountUuid());
            if (account != null) {
                relatedMessageReference = messageReference;
            }
        }
    }
    identity = newIdentity;
    updateSignature();
    updateFrom();
    quotedMessagePresenter.processDraftMessage(messageViewInfo, k9identity);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) Account(com.fsck.k9.Account) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) HashMap(java.util.HashMap) Identity(com.fsck.k9.Identity) Preferences(com.fsck.k9.Preferences) IdentityField(com.fsck.k9.message.IdentityField)

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