diff options
author | Danny Baumann <dannybaumann@web.de> | 2015-06-09 12:54:00 +0200 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2015-06-11 06:04:15 +0000 |
commit | f901689e3d6968e24c3f03f5ff1bb6660eebdc1c (patch) | |
tree | 17e680c252e7284467c852c19443c6c3c364df06 | |
parent | 381a2c24ac73c069c609dac8942752c72beba8e7 (diff) | |
download | android_packages_apps_Email-f901689e3d6968e24c3f03f5ff1bb6660eebdc1c.tar.gz android_packages_apps_Email-f901689e3d6968e24c3f03f5ff1bb6660eebdc1c.tar.bz2 android_packages_apps_Email-f901689e3d6968e24c3f03f5ff1bb6660eebdc1c.zip |
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
-rw-r--r-- | provider_src/com/android/email/mail/store/ImapFolder.java | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/provider_src/com/android/email/mail/store/ImapFolder.java b/provider_src/com/android/email/mail/store/ImapFolder.java index 51e99d97a..97dca901d 100644 --- a/provider_src/com/android/email/mail/store/ImapFolder.java +++ b/provider_src/com/android/email/mail/store/ImapFolder.java @@ -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) |