From 9dc3f0906867d45191ccfced7fcb7fbddd33beb6 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 10 Jul 2010 16:42:12 +0000 Subject: [PATCH] factor "downloadLargeMessages" out of "downloadMessages" --- .../k9/controller/MessagingController.java | 159 ++++++++++-------- 1 file changed, 88 insertions(+), 71 deletions(-) diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 9dabd225a..ee8814dd2 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -1715,6 +1715,94 @@ public class MessagingController implements Runnable fp.clear(); fp.add(FetchProfile.Item.STRUCTURE); + + + downloadLargeMessages(account, remoteFolder, localFolder, largeMessages, progress, newMessages, todo, fp); + largeMessages.clear(); + + /* + * Refresh the flags for any messages in the local store that we didn't just + * download. + */ + if (remoteFolder.supportsFetchingFlags()) + { + if (K9.DEBUG) + Log.d(K9.LOG_TAG, "SYNC: About to sync flags for " + + syncFlagMessages.size() + " remote messages for folder " + folder); + + fp.clear(); + fp.add(FetchProfile.Item.FLAGS); + + List undeletedMessages = new LinkedList(); + for (Message message : syncFlagMessages) + { + if (message.isSet(Flag.DELETED) == false) + { + undeletedMessages.add(message); + } + } + + remoteFolder.fetch(undeletedMessages.toArray(new Message[0]), fp, null); + for (Message remoteMessage : syncFlagMessages) + { + Message localMessage = localFolder.getMessage(remoteMessage.getUid()); + boolean messageChanged = syncFlags(localMessage, remoteMessage); + if (messageChanged) + { + if (localMessage.isSet(Flag.DELETED) || isMessageSuppressed(account, folder, localMessage)) + { + for (MessagingListener l : getListeners()) + { + l.synchronizeMailboxRemovedMessage(account, folder, localMessage); + } + } + else + { + for (MessagingListener l : getListeners()) + { + l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage); + } + } + + } + progress.incrementAndGet(); + for (MessagingListener l : getListeners()) + { + l.synchronizeMailboxProgress(account, folder, progress.get(), todo); + } + } + } + if (K9.DEBUG) + Log.d(K9.LOG_TAG, "SYNC: Synced remote messages for folder " + folder + ", " + newMessages.get() + " new messages"); + + localFolder.purgeToVisibleLimit(new MessageRemovalListener() + { + public void messageRemoved(Message message) + { + for (MessagingListener l : getListeners()) + { + l.synchronizeMailboxRemovedMessage(account, folder, message); + } + } + + }); + + return newMessages.get(); + } + + private void downloadLargeMessages(final Account account, final Folder remoteFolder, + final LocalFolder localFolder, + + + ArrayList largeMessages, + final AtomicInteger progress, + final AtomicInteger newMessages, + final int todo, + FetchProfile fp) throws MessagingException + { + final String folder = remoteFolder.getName(); + + final Date earliestDate = account.getEarliestPollDate(); if (K9.DEBUG) Log.d(K9.LOG_TAG, "SYNC: Fetching large messages for folder " + folder); @@ -1836,79 +1924,8 @@ public class MessagingController implements Runnable if (K9.DEBUG) Log.d(K9.LOG_TAG, "SYNC: Done fetching large messages for folder " + folder); - largeMessages.clear(); - - /* - * Refresh the flags for any messages in the local store that we didn't just - * download. - */ - if (remoteFolder.supportsFetchingFlags()) - { - if (K9.DEBUG) - Log.d(K9.LOG_TAG, "SYNC: About to sync flags for " - + syncFlagMessages.size() + " remote messages for folder " + folder); - - fp.clear(); - fp.add(FetchProfile.Item.FLAGS); - - List undeletedMessages = new LinkedList(); - for (Message message : syncFlagMessages) - { - if (message.isSet(Flag.DELETED) == false) - { - undeletedMessages.add(message); - } - } - - remoteFolder.fetch(undeletedMessages.toArray(new Message[0]), fp, null); - for (Message remoteMessage : syncFlagMessages) - { - Message localMessage = localFolder.getMessage(remoteMessage.getUid()); - boolean messageChanged = syncFlags(localMessage, remoteMessage); - if (messageChanged) - { - if (localMessage.isSet(Flag.DELETED) || isMessageSuppressed(account, folder, localMessage)) - { - for (MessagingListener l : getListeners()) - { - l.synchronizeMailboxRemovedMessage(account, folder, localMessage); - } - } - else - { - for (MessagingListener l : getListeners()) - { - l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage); - } - } - - } - progress.incrementAndGet(); - for (MessagingListener l : getListeners()) - { - l.synchronizeMailboxProgress(account, folder, progress.get(), todo); - } - } - } - if (K9.DEBUG) - Log.d(K9.LOG_TAG, "SYNC: Synced remote messages for folder " + folder + ", " + newMessages.get() + " new messages"); - - localFolder.purgeToVisibleLimit(new MessageRemovalListener() - { - public void messageRemoved(Message message) - { - for (MessagingListener l : getListeners()) - { - l.synchronizeMailboxRemovedMessage(account, folder, message); - } - } - - }); - - return newMessages.get(); } - private boolean syncFlags(Message localMessage, Message remoteMessage) throws MessagingException { boolean messageChanged = false;