Search in sources :

Example 11 with WebDavFolder

use of com.fsck.k9.mail.store.webdav.WebDavFolder in project k-9 by k9mail.

the class WebDavSync method fetchUnsyncedMessages.

private void fetchUnsyncedMessages(final SyncConfig syncConfig, final WebDavFolder remoteFolder, List<WebDavMessage> unsyncedMessages, final List<WebDavMessage> smallMessages, final List<WebDavMessage> largeMessages, final AtomicInteger progress, final int todo, FetchProfile fp, final SyncListener listener) throws MessagingException {
    final String folder = remoteFolder.getServerId();
    final Date earliestDate = syncConfig.getEarliestPollDate();
    remoteFolder.fetch(unsyncedMessages, fp, new MessageRetrievalListener<WebDavMessage>() {

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

        @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!!
        }
    }, syncConfig.getMaximumAutoDownloadMessageSize());
}
Also used : WebDavMessage(com.fsck.k9.mail.store.webdav.WebDavMessage) Date(java.util.Date) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Aggregations

WebDavMessage (com.fsck.k9.mail.store.webdav.WebDavMessage)7 ArrayList (java.util.ArrayList)4 FetchProfile (com.fsck.k9.mail.FetchProfile)3 WebDavFolder (com.fsck.k9.mail.store.webdav.WebDavFolder)3 Date (java.util.Date)3 MoreMessages (com.fsck.k9.backend.api.BackendFolder.MoreMessages)2 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)2 MessagingException (com.fsck.k9.mail.MessagingException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 BackendFolder (com.fsck.k9.backend.api.BackendFolder)1 Flag (com.fsck.k9.mail.Flag)1 Folder (com.fsck.k9.mail.Folder)1 FolderType (com.fsck.k9.mail.FolderType)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1