1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Implement windowing for IMAP UID FETCH

Our previous implementation of UID FETCH didn't ever take into account
maximum command line lengths. When fetching, say 800 messages from a
GMail IMAP server, we could easily overflow the max line length leading
to a fetch that didn't get all the messages we wanted to and was
truncated before the description of which fields we want. That caused
K-9 to fetch complete messages, exhaust memory and ultimately fail,
even when we were just trying to get message lengths.

An equivalent fix needs to be made to seach by UID.
This commit is contained in:
Jesse Vincent 2010-08-11 03:39:29 +00:00
parent f9fd5a8e4c
commit af45eae2ce

View File

@ -70,6 +70,8 @@ public class ImapStore extends Store
private static int MAX_DELAY_TIME = 5 * 60 * 1000; // 5 minutes
private static int NORMAL_DELAY_TIME = 5000;
private static int FETCH_WINDOW_SIZE = 100;
private static final Flag[] PERMANENT_FLAGS = { Flag.DELETED, Flag.SEEN };
private static final String CAPABILITY_IDLE = "IDLE";
@ -1155,12 +1157,14 @@ public class ImapStore extends Store
return;
}
checkOpen();
String[] uids = new String[messages.length];
List<String> uids = new ArrayList<String>(messages.length);
HashMap<String, Message> messageMap = new HashMap<String, Message>();
for (int i = 0, count = messages.length; i < count; i++)
{
uids[i] = messages[i].getUid();
messageMap.put(uids[i], messages[i]);
String uid = messages[i].getUid();
uids.add(uid);
messageMap.put(uid, messages[i]);
}
/*
@ -1195,10 +1199,16 @@ public class ImapStore extends Store
fetchFields.add("BODY.PEEK[]");
}
for (int windowStart=1; windowStart <= messages.length; windowStart += (FETCH_WINDOW_SIZE +1))
{
List<String> uidWindow = uids.subList(windowStart, Math.min((windowStart+FETCH_WINDOW_SIZE),messages.length));
try
{
mConnection.sendCommand(String.format("UID FETCH %s (%s)",
Utility.combine(uids, ','),
Utility.combine(uidWindow.toArray(new String[uidWindow.size()]), ','),
Utility.combine(fetchFields.toArray(new String[fetchFields.size()]), ' ')
), false);
ImapResponse response;
@ -1292,6 +1302,7 @@ public class ImapStore extends Store
throw ioExceptionHandler(mConnection, ioe);
}
}
}
@Override