mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
extract "fetch unsyncced messages" from downloadMessages
This commit is contained in:
parent
c2d9d0e15d
commit
44f161fc7f
@ -1490,6 +1490,101 @@ public class MessagingController implements Runnable
|
||||
if (K9.DEBUG)
|
||||
Log.d(K9.LOG_TAG, "SYNC: About to fetch " + unsyncedMessages.size() + " unsynced messages for folder " + folder);
|
||||
|
||||
|
||||
fetchUnsyncedMessages(account, remoteFolder, localFolder, unsyncedMessages, smallMessages,largeMessages, progress, todo, fp);
|
||||
|
||||
// If a message didn't exist, messageFinished won't be called, but we shouldn't try again
|
||||
// If we got here, nothing failed
|
||||
for (Message message : unsyncedMessages)
|
||||
{
|
||||
String newPushState = remoteFolder.getNewPushState(localFolder.getPushState(), message);
|
||||
if (newPushState != null)
|
||||
{
|
||||
localFolder.setPushState(newPushState);
|
||||
}
|
||||
}
|
||||
if (K9.DEBUG)
|
||||
{
|
||||
Log.d(K9.LOG_TAG, "SYNC: Synced unsynced messages for folder " + folder);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (K9.DEBUG)
|
||||
Log.d(K9.LOG_TAG, "SYNC: Have "
|
||||
+ largeMessages.size() + " large messages and "
|
||||
+ smallMessages.size() + " small messages out of "
|
||||
+ unsyncedMessages.size() + " unsynced messages");
|
||||
|
||||
unsyncedMessages.clear();
|
||||
|
||||
/*
|
||||
* Grab the content of the small messages first. This is going to
|
||||
* be very fast and at very worst will be a single up of a few bytes and a single
|
||||
* download of 625k.
|
||||
*/
|
||||
FetchProfile fp = new FetchProfile();
|
||||
fp.add(FetchProfile.Item.BODY);
|
||||
// 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.
|
||||
*/
|
||||
|
||||
refreshLocalMessageFlags(account,remoteFolder,localFolder,syncFlagMessages,progress,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 fetchUnsyncedMessages(final Account account, final Folder remoteFolder,
|
||||
final LocalFolder localFolder,
|
||||
List<Message> unsyncedMessages,
|
||||
final ArrayList<Message> smallMessages,
|
||||
final ArrayList<Message> largeMessages,
|
||||
final AtomicInteger progress,
|
||||
final int todo,
|
||||
FetchProfile fp) throws MessagingException
|
||||
{
|
||||
final String folder = remoteFolder.getName();
|
||||
|
||||
final Date earliestDate = account.getEarliestPollDate();
|
||||
remoteFolder.fetch(unsyncedMessages.toArray(new Message[0]), fp,
|
||||
new MessageRetrievalListener()
|
||||
{
|
||||
@ -1583,84 +1678,6 @@ public class MessagingController implements Runnable
|
||||
|
||||
public void messagesFinished(int total) {}
|
||||
});
|
||||
// If a message didn't exist, messageFinished won't be called, but we shouldn't try again
|
||||
// If we got here, nothing failed
|
||||
for (Message message : unsyncedMessages)
|
||||
{
|
||||
String newPushState = remoteFolder.getNewPushState(localFolder.getPushState(), message);
|
||||
if (newPushState != null)
|
||||
{
|
||||
localFolder.setPushState(newPushState);
|
||||
}
|
||||
}
|
||||
if (K9.DEBUG)
|
||||
{
|
||||
Log.d(K9.LOG_TAG, "SYNC: Synced unsynced messages for folder " + folder);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (K9.DEBUG)
|
||||
Log.d(K9.LOG_TAG, "SYNC: Have "
|
||||
+ largeMessages.size() + " large messages and "
|
||||
+ smallMessages.size() + " small messages out of "
|
||||
+ unsyncedMessages.size() + " unsynced messages");
|
||||
|
||||
unsyncedMessages.clear();
|
||||
|
||||
/*
|
||||
* Grab the content of the small messages first. This is going to
|
||||
* be very fast and at very worst will be a single up of a few bytes and a single
|
||||
* download of 625k.
|
||||
*/
|
||||
FetchProfile fp = new FetchProfile();
|
||||
fp.add(FetchProfile.Item.BODY);
|
||||
// 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.
|
||||
*/
|
||||
|
||||
refreshLocalMessageFlags(account,remoteFolder,localFolder,syncFlagMessages,progress,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,
|
||||
|
Loading…
Reference in New Issue
Block a user