From 35b7fce0878c2062174d5b271efcd0f0cb714397 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 10 Jul 2010 16:42:39 +0000 Subject: [PATCH] factor out downloadSmallMessages from downloadMessages --- .../k9/controller/MessagingController.java | 188 ++++++++++-------- 1 file changed, 104 insertions(+), 84 deletions(-) diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index ee8814dd2..e16e2721e 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -1619,6 +1619,108 @@ public class MessagingController implements Runnable // fp.add(FetchProfile.Item.FLAGS); // fp.add(FetchProfile.Item.ENVELOPE); + + + + downloadSmallMessages(account, remoteFolder, localFolder, smallMessages, progress, newMessages, todo, fp); + + + smallMessages.clear(); + + /* + * Now do the large messages that require more round trips. + */ + 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 downloadSmallMessages(final Account account, final Folder remoteFolder, + final LocalFolder localFolder, + ArrayList smallMessages, + 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 small messages for folder " + folder); @@ -1706,94 +1808,12 @@ public class MessagingController implements Runnable if (K9.DEBUG) Log.d(K9.LOG_TAG, "SYNC: Done fetching small messages for folder " + folder); - - smallMessages.clear(); - - /* - * Now do the large messages that require more round trips. - */ - 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,