From c3885bc475f95dc655d3adbc706749c3d78d0add Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 16 Feb 2012 23:52:44 +0100 Subject: [PATCH] Cleaned up LocalFolder.appendMessages() a bit --- src/com/fsck/k9/mail/store/LocalStore.java | 23 ++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index c36350dfa..bf797ebfe 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -2090,16 +2090,27 @@ public class LocalStore extends Store implements Serializable { long oldMessageId = -1; String uid = message.getUid(); - if (uid == null && !copy) { - uid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString(); - message.setUid(uid); - } else if (copy) { - String randomLocalUid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString(); - if (uid != null) { + if (uid == null || copy) { + /* + * Create a new message in the database + */ + String randomLocalUid = K9.LOCAL_UID_PREFIX + + UUID.randomUUID().toString(); + + if (copy) { + // Save mapping: source UID -> target UID uidMap.put(uid, randomLocalUid); + } else { + // Modify the Message instance to reference the new UID + message.setUid(randomLocalUid); } + + // The message will be saved with the newly generated UID uid = randomLocalUid; } else { + /* + * Replace an existing message in the database + */ LocalMessage oldMessage = (LocalMessage) getMessage(uid); if (oldMessage != null) {