From 0de8b6a7e5788c7af9970d42a24de6101ea1ef34 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Thu, 11 Mar 2021 16:11:24 +0100 Subject: [PATCH] Update uid_next if the server rewinded it fix #2188 Also, if we notice that the server started reusing old UIDs, _also_ do a `ResyncFolders`, because the server likely forgot to change uid_validity --- src/imap/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/imap/mod.rs b/src/imap/mod.rs index 1c086a93c..0395b8864 100644 --- a/src/imap/mod.rs +++ b/src/imap/mod.rs @@ -575,6 +575,15 @@ impl Imap { // new messages is only one command, just as a SELECT command) true } else if let Some(uid_next) = mailbox.uid_next { + if uid_next < old_uid_next { + warn!( + context, + "The server illegally decreased the uid_next of folder {} from {} to {} without changing validity ({}), resyncing UIDs...", + folder, old_uid_next, uid_next, new_uid_validity, + ); + set_uid_next(context, folder, uid_next).await?; + job::schedule_resync(context).await; + } uid_next != old_uid_next // If uid_next changed, there are new emails } else { true // We have no uid_next and if in doubt, return true