]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Don't reset \Recent flags when rebuilding index
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 16 Mar 2017 16:46:28 +0000 (18:46 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 17 Mar 2017 09:03:31 +0000 (11:03 +0200)
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

index f5cf154a203a55f97d07c465ceb48b5807c15a46..6533f061d79b8a50e70bd060a056db4f7cfb6bda 100644 (file)
@@ -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);