IMAP: fix bug 2835529 FETCH with unordered range

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@704 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-09-07 11:42:07 +00:00
parent 679d7f55d9
commit e0b1d6c954
1 changed files with 56 additions and 14 deletions

View File

@ -1020,18 +1020,21 @@ public class ImapConnection extends AbstractConnection {
}
}
protected void skipToStartUid() {
protected void skipToNextRangeStartUid() {
if (currentRangeIndex < ranges.length) {
String currentRange = ranges[currentRangeIndex++];
int colonIndex = currentRange.indexOf(':');
if (colonIndex > 0) {
startUid = convertToLong(currentRange.substring(0, colonIndex));
endUid = convertToLong(currentRange.substring(colonIndex + 1));
if (endUid < startUid) {
long swap = endUid;
endUid = startUid;
startUid = swap;
}
} else {
startUid = endUid = convertToLong(currentRange);
}
// Need to reset index for Palm pre
currentIndex = 0;
while (currentIndex < currentFolder.count() && currentFolder.getImapUid(currentIndex) < startUid) {
currentIndex++;
}
@ -1040,13 +1043,31 @@ public class ImapConnection extends AbstractConnection {
}
}
public boolean hasNext() {
while (currentIndex < currentFolder.count() && currentFolder.getImapUid(currentIndex) > endUid) {
skipToStartUid();
}
protected boolean hasNextInRange() {
return hasNextIndex() && currentFolder.getImapUid(currentIndex) <= endUid;
}
protected boolean hasNextIndex() {
return currentIndex < currentFolder.count();
}
protected boolean hasNextRange() {
return currentRangeIndex < ranges.length;
}
public boolean hasNext() {
boolean hasNextInRange = hasNextInRange();
// if has next range and current index after current range end, reset index
if (hasNextRange() && !hasNextInRange) {
currentIndex = 0;
}
while (hasNextIndex() && !hasNextInRange) {
skipToNextRangeStartUid();
hasNextInRange = hasNextInRange();
}
return hasNextIndex();
}
public ExchangeSession.Message next() {
ExchangeSession.Message message = currentFolder.get(currentIndex++);
long uid = message.getImapUid();
@ -1080,18 +1101,21 @@ public class ImapConnection extends AbstractConnection {
}
}
protected void skipToStartUid() {
protected void skipToNextRangeStart() {
if (currentRangeIndex < ranges.length) {
String currentRange = ranges[currentRangeIndex++];
int colonIndex = currentRange.indexOf(':');
if (colonIndex > 0) {
startUid = convertToLong(currentRange.substring(0, colonIndex));
endUid = convertToLong(currentRange.substring(colonIndex + 1));
if (endUid < startUid) {
long swap = endUid;
endUid = startUid;
startUid = swap;
}
} else {
startUid = endUid = convertToLong(currentRange);
}
// Need to reset index for Palm pre
currentIndex = 0;
while (currentIndex < currentFolder.count() && (currentIndex + 1) < startUid) {
currentIndex++;
}
@ -1100,13 +1124,31 @@ public class ImapConnection extends AbstractConnection {
}
}
public boolean hasNext() {
while (currentIndex < currentFolder.count() && (currentIndex + 1) > endUid) {
skipToStartUid();
}
protected boolean hasNextInRange() {
return hasNextIndex() && currentIndex < endUid;
}
protected boolean hasNextIndex() {
return currentIndex < currentFolder.count();
}
protected boolean hasNextRange() {
return currentRangeIndex < ranges.length;
}
public boolean hasNext() {
boolean hasNextInRange = hasNextInRange();
// if has next range and current index after current range end, reset index
if (hasNextRange() && !hasNextInRange) {
currentIndex = 0;
}
while (hasNextIndex() && !hasNextInRange) {
skipToNextRangeStart();
hasNextInRange = hasNextInRange();
}
return hasNextIndex();
}
public ExchangeSession.Message next() {
return currentFolder.get(currentIndex++);
}