mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 03:32:16 -05:00
devsk's patch to fix incorrect IMAP message fetching. Fix utilizes UIDNEXT to determine which messages to grab.
This commit is contained in:
parent
a69ff4b337
commit
20b46255c0
@ -304,6 +304,7 @@ public class ImapStore extends Store {
|
|||||||
class ImapFolder extends Folder {
|
class ImapFolder extends Folder {
|
||||||
private String mName;
|
private String mName;
|
||||||
private int mMessageCount = -1;
|
private int mMessageCount = -1;
|
||||||
|
private int mUIDNext = -1;
|
||||||
private ImapConnection mConnection;
|
private ImapConnection mConnection;
|
||||||
private OpenMode mMode;
|
private OpenMode mMode;
|
||||||
private boolean mExists;
|
private boolean mExists;
|
||||||
@ -369,6 +370,13 @@ public class ImapStore extends Store {
|
|||||||
if (response.mTag == null && response.get(1).equals("EXISTS")) {
|
if (response.mTag == null && response.get(1).equals("EXISTS")) {
|
||||||
mMessageCount = response.getNumber(0);
|
mMessageCount = response.getNumber(0);
|
||||||
}
|
}
|
||||||
|
else if (response.mTag == null && response.size() >= 4 && response.getString(3).equalsIgnoreCase("predicted")) {
|
||||||
|
|
||||||
|
// we have a server which specifies the UID of next message that will come into this folder
|
||||||
|
// get the value for UIDNEXT in this case.
|
||||||
|
String mUIDNextStr = response.getString(2);
|
||||||
|
mUIDNext = Integer.parseInt(mUIDNextStr.substring(0, mUIDNextStr.length()-1));
|
||||||
|
}
|
||||||
else if (response.mTag != null && response.size() >= 2) {
|
else if (response.mTag != null && response.size() >= 2) {
|
||||||
if ("[READ-ONLY]".equalsIgnoreCase(response.getString(1))) {
|
if ("[READ-ONLY]".equalsIgnoreCase(response.getString(1))) {
|
||||||
mMode = OpenMode.READ_ONLY;
|
mMode = OpenMode.READ_ONLY;
|
||||||
@ -564,11 +572,21 @@ public class ImapStore extends Store {
|
|||||||
@Override
|
@Override
|
||||||
public Message[] getMessages(int start, int end, MessageRetrievalListener listener)
|
public Message[] getMessages(int start, int end, MessageRetrievalListener listener)
|
||||||
throws MessagingException {
|
throws MessagingException {
|
||||||
|
int visibleLimit = end - start + 1;
|
||||||
if (start < 1 || end < 1 || end < start) {
|
if (start < 1 || end < 1 || end < start) {
|
||||||
throw new MessagingException(
|
throw new MessagingException(
|
||||||
String.format("Invalid message set %d %d",
|
String.format("Invalid message set %d %d",
|
||||||
start, end));
|
start, end));
|
||||||
}
|
}
|
||||||
|
// adjust start and end if UIDNEXT was seen in SELECT
|
||||||
|
// Note that mUIDNext will be 3 if there are 2 messages in the folder
|
||||||
|
// If there are 2 messages in the folder visibleLimit is 2
|
||||||
|
// This math avoids having to change non-store top level code
|
||||||
|
if (mUIDNext > 0) {
|
||||||
|
start = Math.max(1, mUIDNext - visibleLimit);
|
||||||
|
end = mUIDNext;
|
||||||
|
}
|
||||||
|
|
||||||
checkOpen();
|
checkOpen();
|
||||||
ArrayList<Message> messages = new ArrayList<Message>();
|
ArrayList<Message> messages = new ArrayList<Message>();
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user