Handle loadMore when no messages are loaded
Bug: 7129772 Change-Id: I9d2fd4f2bc488930c53e9fe44dc3fa852409b5c0
This commit is contained in:
parent
a88fb32724
commit
8580511541
@ -2032,9 +2032,19 @@ public class Imap2SyncService extends AbstractSyncService {
|
||||
* @throws IOException
|
||||
*/
|
||||
private int[] handleLoadMore(int[] serverList, int howManyMore) throws IOException {
|
||||
// User has asked for more; find the oldest message
|
||||
// Easiest case; we have no messages.. just start at the last one in the mailbox
|
||||
if (serverList.length == 0) {
|
||||
if (mLastExists > 0) {
|
||||
return loadMoreImpl(serverList, mLastExists, howManyMore);
|
||||
}
|
||||
return serverList;
|
||||
}
|
||||
|
||||
// First, sort the list
|
||||
Arrays.sort(serverList);
|
||||
// Oldest is the first in the sorted list
|
||||
int oldest = serverList[0];
|
||||
|
||||
// Get its current sequence number
|
||||
String tag = writeCommand(mWriter, "uid fetch " + oldest + " (UID)");
|
||||
// IMAP_OK if we want it to work
|
||||
@ -2042,14 +2052,21 @@ public class Imap2SyncService extends AbstractSyncService {
|
||||
String line = mImapResponse.get(0);
|
||||
Parser lp = new Parser(line.substring(2));
|
||||
// Last one we want is one before this message
|
||||
int end = lp.parseInteger() - 1;
|
||||
return loadMoreImpl(serverList, lp.parseInteger() - 1, howManyMore);
|
||||
}
|
||||
// In worst case, just return the original list
|
||||
return serverList;
|
||||
}
|
||||
|
||||
private int[] loadMoreImpl(int[] serverList, int end, int howManyMore) throws IOException {
|
||||
|
||||
int start = end - howManyMore + 1;
|
||||
if (start < 1) {
|
||||
start = 1;
|
||||
}
|
||||
if (end > 0) {
|
||||
// Get the uid's of the messages to load
|
||||
tag = writeCommand(mWriter, "uid search " + start + ":" + end);
|
||||
String tag = writeCommand(mWriter, "uid search " + start + ":" + end);
|
||||
// IMAP_OK if we want it to work
|
||||
if (readResponse(mReader, tag, "SEARCH").equals(IMAP_OK)) {
|
||||
int[] moreServerList;
|
||||
@ -2072,8 +2089,6 @@ public class Imap2SyncService extends AbstractSyncService {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// In worst case, just return the original list
|
||||
return serverList;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user