From c2d9d0e15d9abfd801537fd2566e0c474f3ad0b2 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 10 Jul 2010 16:42:54 +0000 Subject: [PATCH] extract "sync local message flags" from downloadMessages --- .../k9/controller/MessagingController.java | 106 ++++++++++-------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index e16e2721e..2f37e2eaa 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -1642,54 +1642,9 @@ public class MessagingController implements Runnable * 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); + refreshLocalMessageFlags(account,remoteFolder,localFolder,syncFlagMessages,progress,todo); - 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"); @@ -1946,6 +1901,65 @@ public class MessagingController implements Runnable } + private void refreshLocalMessageFlags(final Account account, final Folder remoteFolder, + final LocalFolder localFolder, + ArrayList syncFlagMessages, + final AtomicInteger progress, + final int todo + ) throws MessagingException + { + + final String folder = remoteFolder.getName(); + if (remoteFolder.supportsFetchingFlags()) + { + if (K9.DEBUG) + Log.d(K9.LOG_TAG, "SYNC: About to sync flags for " + + syncFlagMessages.size() + " remote messages for folder " + folder); + + FetchProfile fp = new FetchProfile(); + 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); + } + } + } + } + private boolean syncFlags(Message localMessage, Message remoteMessage) throws MessagingException { boolean messageChanged = false;