1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-17 06:55:03 -05:00

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.
This commit is contained in:
cketti 2012-01-26 03:33:33 +01:00
parent a9ccad8d9f
commit 0f668cc80d

View File

@ -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<Message> missingMessages = new ArrayList<Message>();
ArrayList<Message> destroyMessages = new ArrayList<Message>(); for (Message localMessage : localMessages) {
for (Message localMessage : localMessages) { String uid = localMessage.getUid();
if (remoteUidMap.get(localMessage.getUid()) == null) { if (!uid.startsWith(K9.LOCAL_UID_PREFIX) && !remoteUidMap.containsKey(uid)) {
destroyMessages.add(localMessage); // 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;