From 102c6153a122a173a3253d9a7cf08ef8e333e610 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Tue, 19 Jun 2012 16:11:30 -0400 Subject: [PATCH] Issue 4359: IMAP message UIDs are 32 bit unsigned values and cannot be stored in int, so we now parse them as long. --- .../k9/mail/store/ImapResponseParser.java | 4 ++ src/com/fsck/k9/mail/store/ImapStore.java | 38 +++++++++---------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/com/fsck/k9/mail/store/ImapResponseParser.java b/src/com/fsck/k9/mail/store/ImapResponseParser.java index c73324753..4a8c8cc2e 100644 --- a/src/com/fsck/k9/mail/store/ImapResponseParser.java +++ b/src/com/fsck/k9/mail/store/ImapResponseParser.java @@ -384,6 +384,10 @@ public class ImapResponseParser { return (String)get(index); } + public long getLong(int index) { + return Long.parseLong(getString(index)); + } + public int getNumber(int index) { return Integer.parseInt(getString(index)); } diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index 77251333b..4376d7d85 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -811,12 +811,12 @@ public class ImapStore extends Store { class ImapFolder extends Folder { private String mName; protected volatile int mMessageCount = -1; - protected volatile int uidNext = -1; + protected volatile long uidNext = -1L; protected volatile ImapConnection mConnection; private OpenMode mMode; private volatile boolean mExists; private ImapStore store = null; - Map msgSeqUidMap = new ConcurrentHashMap(); + Map msgSeqUidMap = new ConcurrentHashMap(); public ImapFolder(ImapStore nStore, String name) { @@ -1305,7 +1305,7 @@ public class ImapStore extends Store { return search(searcher, listener); } - protected Message[] getMessages(final List mesgSeqs, final boolean includeDeleted, final MessageRetrievalListener listener) + protected Message[] getMessages(final List mesgSeqs, final boolean includeDeleted, final MessageRetrievalListener listener) throws MessagingException { ImapSearcher searcher = new ImapSearcher() { public List search() throws IOException, MessagingException { @@ -1472,7 +1472,7 @@ public class ImapStore extends Store { if (response.mTag == null && ImapResponseParser.equalsIgnoreCase(response.get(1), "FETCH")) { ImapList fetchList = (ImapList)response.getKeyedValue("FETCH"); String uid = fetchList.getKeyedString("UID"); - int msgSeq = response.getNumber(0); + long msgSeq = response.getLong(0); if (uid != null) { try { msgSeqUidMap.put(msgSeq, uid); @@ -1699,7 +1699,7 @@ public class ImapStore extends Store { if (keyObj instanceof String) { String key = (String)keyObj; if ("UIDNEXT".equalsIgnoreCase(key)) { - uidNext = bracketed.getNumber(1); + uidNext = bracketed.getLong(1); if (K9.DEBUG) Log.d(K9.LOG_TAG, "Got UidNext = " + uidNext + " for " + getLogId()); } @@ -2828,9 +2828,9 @@ public class ImapStore extends Store { if (stop.get()) { continue; } - int startUid = oldUidNext; + long startUid = oldUidNext; - int newUidNext = uidNext; + long newUidNext = uidNext; if (newUidNext == -1) { if (K9.DEBUG) { @@ -2858,7 +2858,7 @@ public class ImapStore extends Store { if (K9.DEBUG) Log.i(K9.LOG_TAG, "Needs sync from uid " + startUid + " to " + newUidNext + " for " + getLogId()); List messages = new ArrayList(); - for (int uid = startUid; uid < newUidNext; uid++) { + for (long uid = startUid; uid < newUidNext; uid++) { ImapMessage message = new ImapMessage("" + uid, ImapFolderPusher.this); messages.add(message); } @@ -2958,7 +2958,7 @@ public class ImapStore extends Store { if (oldMessageCount == -1) { skipSync = true; } - List flagSyncMsgSeqs = new ArrayList(); + List flagSyncMsgSeqs = new ArrayList(); List removeMsgUids = new LinkedList(); for (ImapResponse response : responses) { @@ -3023,7 +3023,7 @@ public class ImapStore extends Store { } } - private void syncMessages(List flagSyncMsgSeqs) { + private void syncMessages(List flagSyncMsgSeqs) { try { Message[] messageArray = null; @@ -3066,7 +3066,7 @@ public class ImapStore extends Store { } - protected int processUntaggedResponse(int oldMessageCount, ImapResponse response, List flagSyncMsgSeqs, List removeMsgUids) { + protected int processUntaggedResponse(long oldMessageCount, ImapResponse response, List flagSyncMsgSeqs, List removeMsgUids) { super.handleUntaggedResponse(response); int messageCountDelta = 0; if (response.mTag == null && response.size() > 1) { @@ -3074,7 +3074,7 @@ public class ImapStore extends Store { Object responseType = response.get(1); if (ImapResponseParser.equalsIgnoreCase(responseType, "FETCH")) { Log.i(K9.LOG_TAG, "Got FETCH " + response); - int msgSeq = response.getNumber(0); + long msgSeq = response.getLong(0); if (K9.DEBUG) Log.d(K9.LOG_TAG, "Got untagged FETCH for msgseq " + msgSeq + " for " + getLogId()); @@ -3084,17 +3084,17 @@ public class ImapStore extends Store { } } if (ImapResponseParser.equalsIgnoreCase(responseType, "EXPUNGE")) { - int msgSeq = response.getNumber(0); + long msgSeq = response.getLong(0); if (msgSeq <= oldMessageCount) { messageCountDelta = -1; } if (K9.DEBUG) Log.d(K9.LOG_TAG, "Got untagged EXPUNGE for msgseq " + msgSeq + " for " + getLogId()); - List newSeqs = new ArrayList(); - Iterator flagIter = flagSyncMsgSeqs.iterator(); + List newSeqs = new ArrayList(); + Iterator flagIter = flagSyncMsgSeqs.iterator(); while (flagIter.hasNext()) { - Integer flagMsg = flagIter.next(); + Long flagMsg = flagIter.next(); if (flagMsg >= msgSeq) { flagIter.remove(); if (flagMsg > msgSeq) { @@ -3105,14 +3105,14 @@ public class ImapStore extends Store { flagSyncMsgSeqs.addAll(newSeqs); - List msgSeqs = new ArrayList(msgSeqUidMap.keySet()); + List msgSeqs = new ArrayList(msgSeqUidMap.keySet()); Collections.sort(msgSeqs); // Have to do comparisons in order because of msgSeq reductions - for (Integer msgSeqNumI : msgSeqs) { + for (long msgSeqNumI : msgSeqs) { if (K9.DEBUG) { Log.v(K9.LOG_TAG, "Comparing EXPUNGEd msgSeq " + msgSeq + " to " + msgSeqNumI); } - int msgSeqNum = msgSeqNumI; + long msgSeqNum = msgSeqNumI; if (msgSeqNum == msgSeq) { String uid = msgSeqUidMap.get(msgSeqNum); if (K9.DEBUG) {