From 5eb43c3bb43c559cc54d66504c7b79183d45e803 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 16 Mar 2017 18:46:28 +0200 Subject: [PATCH] lib-storage: Don't reset \Recent flags when rebuilding index The recent flags are tracked with first_recent_uid in the header. If the first_recent_uid is valid in the old index, preserve it. This way all mails don't show as having \Recent flag. This was used by sdbox and mdbox code. --- src/lib-storage/index/index-rebuild.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib-storage/index/index-rebuild.c b/src/lib-storage/index/index-rebuild.c index f5cf154a20..6533f061d7 100644 --- a/src/lib-storage/index/index-rebuild.c +++ b/src/lib-storage/index/index-rebuild.c @@ -99,7 +99,7 @@ index_rebuild_header(struct index_rebuild_context *ctx, struct mail_index *index = mail_index_view_get_index(ctx->view); struct mail_index_modseq_header modseq_hdr; struct mail_index_view *trans_view; - uint32_t uid_validity, next_uid; + uint32_t uid_validity, next_uid, first_recent_uid; uint64_t modseq; hdr = mail_index_get_header(ctx->view); @@ -132,6 +132,17 @@ index_rebuild_header(struct index_rebuild_context *ctx, &next_uid, sizeof(next_uid), FALSE); } + /* set first_recent_uid */ + first_recent_uid = hdr->first_recent_uid; + if (backup_hdr != NULL && + backup_hdr->first_recent_uid > first_recent_uid && + backup_hdr->first_recent_uid <= next_uid) + first_recent_uid = backup_hdr->first_recent_uid; + first_recent_uid = I_MIN(first_recent_uid, next_uid); + mail_index_update_header(ctx->trans, + offsetof(struct mail_index_header, first_recent_uid), + &first_recent_uid, sizeof(first_recent_uid), FALSE); + /* set highest-modseq */ i_zero(&modseq_hdr); modseq_hdr.highest_modseq = mail_index_modseq_get_highest(ctx->view); -- 2.47.3