Don't solely rely on the presence of RECENT for checking for new mail.
It may happen (depending on server and/or timing) that only an EXISTS response is sent to the IDLE connection when new mail arrives. Don't discard that response, but evaluate it to determine whether there's new mail by checking whether the message count increased. Change-Id: Ia49714e6cd42dd71dfda8b7bbdf1fd622972edda
This commit is contained in:
parent
d13071399f
commit
006ea81b71
@ -548,7 +548,9 @@ public class ImapFolder extends Folder {
|
||||
|
||||
@Override
|
||||
public int getMessageCount() {
|
||||
return mMessageCount;
|
||||
synchronized (this) {
|
||||
return mMessageCount;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1103,7 +1105,9 @@ public class ImapFolder extends Folder {
|
||||
*/
|
||||
private void handleUntaggedResponse(ImapResponse response) {
|
||||
if (response.isDataResponse(1, ImapConstants.EXISTS)) {
|
||||
mMessageCount = response.getStringOrEmpty(0).getNumberOrZero();
|
||||
synchronized (this) {
|
||||
mMessageCount = response.getStringOrEmpty(0).getNumberOrZero();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1541,9 +1545,10 @@ public class ImapFolder extends Folder {
|
||||
// OK DONE
|
||||
// No more changes
|
||||
// n EXISTS
|
||||
// Indicates that the mailbox changed => ignore
|
||||
// Indicates the number of messages in the mailbox => handle like
|
||||
// RECENT if the number increased
|
||||
// n EXPUNGE
|
||||
// Indicates a message were completely deleted => a full sync is required
|
||||
// Indicates a message was completely deleted => a full sync is required
|
||||
// n RECENT
|
||||
// New messages waiting in the server => use UIDNEXT to search for the new messages.
|
||||
// If isn't possible to retrieve the new UID messages, then a full sync is required
|
||||
@ -1587,9 +1592,24 @@ public class ImapFolder extends Folder {
|
||||
if (op.is(ImapConstants.DONE)) {
|
||||
break;
|
||||
} else if (op.is(ImapConstants.EXISTS)) {
|
||||
continue;
|
||||
int newMessageCount = change.getStringOrEmpty(0).getNumberOrZero();
|
||||
int oldMessageCount;
|
||||
synchronized (this) {
|
||||
oldMessageCount = mMessageCount;
|
||||
mMessageCount = newMessageCount;
|
||||
}
|
||||
if (Logging.LOGD) {
|
||||
LogUtils.d(LOG_TAG, "Got EXISTS idle response, message count now "
|
||||
+ newMessageCount + ", was " + oldMessageCount);
|
||||
}
|
||||
if (newMessageCount > oldMessageCount) {
|
||||
hasNewMessages = true;
|
||||
}
|
||||
} else if (op.is(ImapConstants.EXPUNGE)) {
|
||||
imapIdleChanges.mRequiredSync = true;
|
||||
synchronized (this) {
|
||||
mMessageCount--;
|
||||
}
|
||||
} else if (op.is(ImapConstants.RECENT)) {
|
||||
hasNewMessages = true;
|
||||
} else if (op.is(ImapConstants.FETCH)
|
||||
|
Loading…
Reference in New Issue
Block a user