1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-10 05:08:18 -05:00

Merge branch 'issue-162' of https://github.com/cketti/k-9 into issue-162

This commit is contained in:
ashley willis 2012-01-28 00:58:18 -06:00
commit 2e3a95825f

View File

@ -1011,24 +1011,38 @@ public class MessagingController implements Runnable {
} }
/* /*
* Remove any messages that are in the local store but no longer on the remote store or are too old * Remove any messages that are in the local store but no longer on the remote store
*/ */
if (account.syncRemoteDeletions()) { ArrayList<Message> missingMessages = new ArrayList<Message>();
ArrayList<Message> destroyMessages = new ArrayList<Message>();
for (Message localMessage : localMessages) { for (Message localMessage : localMessages) {
if (remoteUidMap.get(localMessage.getUid()) == null) { String uid = localMessage.getUid();
destroyMessages.add(localMessage); if (!uid.startsWith(K9.LOCAL_UID_PREFIX) && !remoteUidMap.containsKey(uid)) {
// This message used to be on the server
missingMessages.add(localMessage);
} }
} }
if (account.syncRemoteDeletions()) {
// Delete the messages that were deleted from the server from our local store
localFolder.destroyMessages(missingMessages.toArray(EMPTY_MESSAGE_ARRAY));
localFolder.destroyMessages(destroyMessages.toArray(EMPTY_MESSAGE_ARRAY)); for (Message destroyMessage : missingMessages) {
for (Message destroyMessage : destroyMessages) {
for (MessagingListener l : getListeners(listener)) { for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxRemovedMessage(account, folder, destroyMessage); l.synchronizeMailboxRemovedMessage(account, folder, destroyMessage);
} }
} }
} else {
// We do not sync remote deletions, so these messages are now only present in our
// local store. To mark them as local-only messages we give them local UIDs.
for (Message message : missingMessages) {
String oldUid = message.getUid();
String newUid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString();
message.setUid(newUid);
for (MessagingListener l : getListeners(listener)) {
l.messageUidChanged(account, folder, oldUid, newUid);
}
}
} }
localMessages = null; localMessages = null;