Search in sources :

Example 6 with MessageRetrievalListener

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

the class MessagingController method fetchUnsyncedMessages.

private <T extends Message> void fetchUnsyncedMessages(final Account account, final Folder<T> remoteFolder, List<T> unsyncedMessages, final List<Message> smallMessages, final List<Message> largeMessages, final AtomicInteger progress, final int todo, FetchProfile fp) throws MessagingException {
    final String folder = remoteFolder.getName();
    final Date earliestDate = account.getEarliestPollDate();
    remoteFolder.fetch(unsyncedMessages, fp, new MessageRetrievalListener<T>() {

        @Override
        public void messageFinished(T message, int number, int ofTotal) {
            try {
                if (message.isSet(Flag.DELETED) || message.olderThan(earliestDate)) {
                    if (K9.isDebug()) {
                        if (message.isSet(Flag.DELETED)) {
                            Timber.v("Newly downloaded message %s:%s:%s was marked deleted on server, " + "skipping", account, folder, message.getUid());
                        } else {
                            Timber.d("Newly downloaded message %s is older than %s, skipping", message.getUid(), earliestDate);
                        }
                    }
                    progress.incrementAndGet();
                    for (MessagingListener l : getListeners()) {
                        //TODO: This might be the source of poll count errors in the UI. Is todo always the same as ofTotal
                        l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
                    }
                    return;
                }
                if (account.getMaximumAutoDownloadMessageSize() > 0 && message.getSize() > account.getMaximumAutoDownloadMessageSize()) {
                    largeMessages.add(message);
                } else {
                    smallMessages.add(message);
                }
            } catch (Exception e) {
                Timber.e(e, "Error while storing downloaded message.");
                addErrorMessage(account, null, e);
            }
        }

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

        @Override
        public void messagesFinished(int total) {
        // FIXME this method is almost never invoked by various Stores! Don't rely on it unless fixed!!
        }
    });
}
Also used : Date(java.util.Date) SuppressLint(android.annotation.SuppressLint) 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)

Aggregations

MessagingException (com.fsck.k9.mail.MessagingException)6 IOException (java.io.IOException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 SuppressLint (android.annotation.SuppressLint)2 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)2 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)2 LocalMessage (com.fsck.k9.mailstore.LocalMessage)2 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 VisibleForTesting (android.support.annotation.VisibleForTesting)1 Account (com.fsck.k9.Account)1 AccountStats (com.fsck.k9.AccountStats)1 Body (com.fsck.k9.mail.Body)1 Message (com.fsck.k9.mail.Message)1 MessageRetrievalListener (com.fsck.k9.mail.MessageRetrievalListener)1 LocalStore (com.fsck.k9.mailstore.LocalStore)1 SearchAccount (com.fsck.k9.search.SearchAccount)1 BufferedReader (java.io.BufferedReader)1