changeset 22359:04910d5ceb05

lib-storage: If mail_index_header.first_recent_uid shrinks, reset \Recent flags This should never happen.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Tue, 18 Jul 2017 11:57:24 +0300
parents 4f3967e2f493
children d5c4dca315de
files src/lib-storage/index/index-storage.h src/lib-storage/index/index-sync.c
diffstat 2 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-storage.h	Mon Jul 17 18:10:49 2017 +0300
+++ b/src/lib-storage/index/index-storage.h	Tue Jul 18 11:57:24 2017 +0300
@@ -40,6 +40,7 @@
 
 	struct mailbox_vsize_update *vsize_update;
 
+	uint32_t recent_flags_prev_first_recent_uid;
 	uint32_t recent_flags_last_check_nextuid;
 
 	time_t sync_last_check;
--- a/src/lib-storage/index/index-sync.c	Mon Jul 17 18:10:49 2017 +0300
+++ b/src/lib-storage/index/index-sync.c	Tue Jul 18 11:57:24 2017 +0300
@@ -278,8 +278,17 @@
 	uint32_t seq1, seq2;
 
 	hdr = mail_index_get_header(box->view);
+	if (hdr->first_recent_uid < ibox->recent_flags_prev_first_recent_uid) {
+		mail_storage_set_critical(box->storage,
+			"Mailbox %s: first_recent_uid unexpectedly shrank: %u -> %u",
+			box->vname, ibox->recent_flags_prev_first_recent_uid,
+			hdr->first_recent_uid);
+		mailbox_recent_flags_reset(box);
+	}
+
 	if (hdr->first_recent_uid > box->recent_flags_prev_uid ||
 	    hdr->next_uid > ibox->recent_flags_last_check_nextuid) {
+		ibox->recent_flags_prev_first_recent_uid = hdr->first_recent_uid;
 		ibox->recent_flags_last_check_nextuid = hdr->next_uid;
 		if (mail_index_lookup_seq_range(box->view,
 						hdr->first_recent_uid,