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:
parent
a9ccad8d9f
commit
0f668cc80d
@ -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> destroyMessages = new ArrayList<Message>();
|
||||
for (Message localMessage : localMessages) {
|
||||
if (remoteUidMap.get(localMessage.getUid()) == null) {
|
||||
destroyMessages.add(localMessage);
|
||||
}
|
||||
ArrayList<Message> missingMessages = new ArrayList<Message>();
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user