diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index eda66afb9..00672c4f9 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -2978,6 +2978,7 @@ public class ImapStore extends Store { if (K9.DEBUG) Log.i(K9.LOG_TAG, "Pusher starting for " + getLogId()); + long lastUidNext = -1L; while (!stop.get()) { try { long oldUidNext = -1L; @@ -2990,6 +2991,18 @@ public class ImapStore extends Store { } catch (Exception e) { Log.e(K9.LOG_TAG, "Unable to get oldUidNext for " + getLogId(), e); } + + /* + * This makes sure 'oldUidNext' is never smaller than 'UIDNEXT' from + * the last loop iteration. This way we avoid looping endlessly causing + * the battery to drain. + * + * See issue 4907 + */ + if (oldUidNext < lastUidNext) { + oldUidNext = lastUidNext; + } + ImapConnection oldConnection = mConnection; internalOpen(OPEN_MODE_RO); ImapConnection conn = mConnection; @@ -3041,6 +3054,8 @@ public class ImapStore extends Store { if (startUid < 1) { startUid = 1; } + + lastUidNext = newUidNext; if (newUidNext > startUid) { if (K9.DEBUG)