From 0f668cc80d831cdb5456a38579cfc1e64ae5af67 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 26 Jan 2012 03:33:33 +0100 Subject: [PATCH] Don't delete local messages when synchronizing a folder When "sync remote deletions" is disabled, we convert the messages that were deleted from the server to proper local messages by changing the UID. --- .../k9/controller/MessagingController.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index ae5a14d2c..4511c1015 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -1012,24 +1012,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 destroyMessages = new ArrayList(); - for (Message localMessage : localMessages) { - if (remoteUidMap.get(localMessage.getUid()) == null) { - destroyMessages.add(localMessage); - } + ArrayList missingMessages = new ArrayList(); + for (Message localMessage : localMessages) { + String uid = localMessage.getUid(); + 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 : destroyMessages) { + for (Message destroyMessage : missingMessages) { for (MessagingListener l : getListeners(listener)) { 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;