From da9a5e6c17ce89d2fc54cebf35c5397fd609e93d Mon Sep 17 00:00:00 2001 From: Apoorv Khatreja Date: Mon, 25 Jul 2011 06:50:26 +0530 Subject: [PATCH] Made some cosmetic changes for clarity, added debug messages for erroneous conditions. Fixed potential NPE in ImapFolder.parseSequenceSet(). --- src/com/fsck/k9/mail/store/ImapStore.java | 26 +++++++++++++++++----- src/com/fsck/k9/mail/store/LocalStore.java | 6 ++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index b4da67248..4e743e70a 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -866,15 +866,26 @@ public class ImapStore extends Store { if ((copyList.size() >= 4) && copyList.getString(0).equals("COPYUID")) { List srcUids = parseSequenceSet(copyList.getString(2)); List destUids = parseSequenceSet(copyList.getString(3)); - if (srcUids.size() == destUids.size()) { - Iterator srcUidsIterator = srcUids.iterator(); - Iterator destUidsIterator = destUids.iterator(); - uidMap = new HashMap(); - while (srcUidsIterator.hasNext() && destUidsIterator.hasNext()) { - uidMap.put(srcUidsIterator.next(), destUidsIterator.next()); + if (srcUids != null && destUids != null) { + if (srcUids.size() == destUids.size()) { + Iterator srcUidsIterator = srcUids.iterator(); + Iterator destUidsIterator = destUids.iterator(); + uidMap = new HashMap(); + while (srcUidsIterator.hasNext() && destUidsIterator.hasNext()) { + uidMap.put(srcUidsIterator.next(), destUidsIterator.next()); + } + } else { + if(K9.DEBUG) + Log.v(K9.LOG_TAG, "Parse error: size of source UIDs list is not the same as size of destination UIDs list."); } + } else { + if(K9.DEBUG) + Log.v(K9.LOG_TAG, "Parsing of the sequence set failed."); } } + } else { + if(K9.DEBUG) + Log.v(K9.LOG_TAG, "Expected COPYUID response was not found."); } return uidMap; } catch (IOException ioe) { @@ -890,6 +901,9 @@ public class ImapStore extends Store { * @return List sequenceSet */ private List parseSequenceSet(String set) { + if (set == null) { + return null; + } int index = 0; List sequenceList = new ArrayList(); String element = ""; diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 0c3647034..7a5a6b437 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -2049,11 +2049,11 @@ public class LocalStore extends Store implements Serializable { uid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString(); message.setUid(uid); } else if (copy) { - String temp = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString(); + String randomLocalUid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString(); if (uid != null) { - uidMap.put(uid, temp); + uidMap.put(uid, randomLocalUid); } - uid = temp; + uid = randomLocalUid; } else { Message oldMessage = getMessage(uid); if (oldMessage != null && !oldMessage.isSet(Flag.SEEN)) {