mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-13 21:15:08 -05:00
factor "downloadLargeMessages" out of "downloadMessages"
This commit is contained in:
parent
ab8cdb3522
commit
9dc3f09068
@ -1715,6 +1715,94 @@ public class MessagingController implements Runnable
|
|||||||
fp.clear();
|
fp.clear();
|
||||||
fp.add(FetchProfile.Item.STRUCTURE);
|
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<Message> undeletedMessages = new LinkedList<Message>();
|
||||||
|
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<Message> 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)
|
if (K9.DEBUG)
|
||||||
Log.d(K9.LOG_TAG, "SYNC: Fetching large messages for folder " + folder);
|
Log.d(K9.LOG_TAG, "SYNC: Fetching large messages for folder " + folder);
|
||||||
|
|
||||||
@ -1836,79 +1924,8 @@ public class MessagingController implements Runnable
|
|||||||
if (K9.DEBUG)
|
if (K9.DEBUG)
|
||||||
Log.d(K9.LOG_TAG, "SYNC: Done fetching large messages for folder " + folder);
|
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<Message> undeletedMessages = new LinkedList<Message>();
|
|
||||||
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
|
private boolean syncFlags(Message localMessage, Message remoteMessage) throws MessagingException
|
||||||
{
|
{
|
||||||
boolean messageChanged = false;
|
boolean messageChanged = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user