mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-14 19:52:21 -05:00
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:
parent
679d7f55d9
commit
e0b1d6c954
@ -1020,18 +1020,21 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void skipToStartUid() {
|
protected void skipToNextRangeStartUid() {
|
||||||
if (currentRangeIndex < ranges.length) {
|
if (currentRangeIndex < ranges.length) {
|
||||||
String currentRange = ranges[currentRangeIndex++];
|
String currentRange = ranges[currentRangeIndex++];
|
||||||
int colonIndex = currentRange.indexOf(':');
|
int colonIndex = currentRange.indexOf(':');
|
||||||
if (colonIndex > 0) {
|
if (colonIndex > 0) {
|
||||||
startUid = convertToLong(currentRange.substring(0, colonIndex));
|
startUid = convertToLong(currentRange.substring(0, colonIndex));
|
||||||
endUid = convertToLong(currentRange.substring(colonIndex + 1));
|
endUid = convertToLong(currentRange.substring(colonIndex + 1));
|
||||||
|
if (endUid < startUid) {
|
||||||
|
long swap = endUid;
|
||||||
|
endUid = startUid;
|
||||||
|
startUid = swap;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
startUid = endUid = convertToLong(currentRange);
|
startUid = endUid = convertToLong(currentRange);
|
||||||
}
|
}
|
||||||
// Need to reset index for Palm pre
|
|
||||||
currentIndex = 0;
|
|
||||||
while (currentIndex < currentFolder.count() && currentFolder.getImapUid(currentIndex) < startUid) {
|
while (currentIndex < currentFolder.count() && currentFolder.getImapUid(currentIndex) < startUid) {
|
||||||
currentIndex++;
|
currentIndex++;
|
||||||
}
|
}
|
||||||
@ -1040,13 +1043,31 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
protected boolean hasNextInRange() {
|
||||||
while (currentIndex < currentFolder.count() && currentFolder.getImapUid(currentIndex) > endUid) {
|
return hasNextIndex() && currentFolder.getImapUid(currentIndex) <= endUid;
|
||||||
skipToStartUid();
|
}
|
||||||
}
|
|
||||||
|
protected boolean hasNextIndex() {
|
||||||
return currentIndex < currentFolder.count();
|
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() {
|
public ExchangeSession.Message next() {
|
||||||
ExchangeSession.Message message = currentFolder.get(currentIndex++);
|
ExchangeSession.Message message = currentFolder.get(currentIndex++);
|
||||||
long uid = message.getImapUid();
|
long uid = message.getImapUid();
|
||||||
@ -1080,18 +1101,21 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void skipToStartUid() {
|
protected void skipToNextRangeStart() {
|
||||||
if (currentRangeIndex < ranges.length) {
|
if (currentRangeIndex < ranges.length) {
|
||||||
String currentRange = ranges[currentRangeIndex++];
|
String currentRange = ranges[currentRangeIndex++];
|
||||||
int colonIndex = currentRange.indexOf(':');
|
int colonIndex = currentRange.indexOf(':');
|
||||||
if (colonIndex > 0) {
|
if (colonIndex > 0) {
|
||||||
startUid = convertToLong(currentRange.substring(0, colonIndex));
|
startUid = convertToLong(currentRange.substring(0, colonIndex));
|
||||||
endUid = convertToLong(currentRange.substring(colonIndex + 1));
|
endUid = convertToLong(currentRange.substring(colonIndex + 1));
|
||||||
|
if (endUid < startUid) {
|
||||||
|
long swap = endUid;
|
||||||
|
endUid = startUid;
|
||||||
|
startUid = swap;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
startUid = endUid = convertToLong(currentRange);
|
startUid = endUid = convertToLong(currentRange);
|
||||||
}
|
}
|
||||||
// Need to reset index for Palm pre
|
|
||||||
currentIndex = 0;
|
|
||||||
while (currentIndex < currentFolder.count() && (currentIndex + 1) < startUid) {
|
while (currentIndex < currentFolder.count() && (currentIndex + 1) < startUid) {
|
||||||
currentIndex++;
|
currentIndex++;
|
||||||
}
|
}
|
||||||
@ -1100,13 +1124,31 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
protected boolean hasNextInRange() {
|
||||||
while (currentIndex < currentFolder.count() && (currentIndex + 1) > endUid) {
|
return hasNextIndex() && currentIndex < endUid;
|
||||||
skipToStartUid();
|
}
|
||||||
}
|
|
||||||
|
protected boolean hasNextIndex() {
|
||||||
return currentIndex < currentFolder.count();
|
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() {
|
public ExchangeSession.Message next() {
|
||||||
return currentFolder.get(currentIndex++);
|
return currentFolder.get(currentIndex++);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user