]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Fixed getting recent count for mailbox when it wasn't synced.
authorTimo Sirainen <tss@iki.fi>
Wed, 10 Aug 2011 13:16:57 +0000 (16:16 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 10 Aug 2011 13:16:57 +0000 (16:16 +0300)
src/lib-storage/index/index-status.c
src/lib-storage/index/index-storage.h
src/lib-storage/index/index-sync.c

index ca537222c0f566c761190d7c896a46f13e07ad46..1c1682acd06e3df4912e09ad8e59c6ea5e74e07a 100644 (file)
@@ -26,6 +26,9 @@ int index_storage_get_status(struct mailbox *box,
        hdr = mail_index_get_header(box->view);
        status_r->messages = hdr->messages_count;
        if ((items & STATUS_RECENT) != 0) {
+               /* make sure recent count is set, in case syncing hasn't
+                  been done yet */
+               index_sync_update_recent_count(box);
                status_r->recent = index_mailbox_get_recent_count(box);
                i_assert(status_r->recent <= status_r->messages);
        }
index 08d8078760b592ee76b1dc5185a153c704148dee..1a7503649ae9e296ccf7e850e6daa3dd25c4b723 100644 (file)
@@ -103,6 +103,7 @@ int index_mailbox_sync_deinit(struct mailbox_sync_context *ctx,
 
 int index_storage_sync(struct mailbox *box, enum mailbox_sync_flags flags);
 enum mailbox_sync_type index_sync_type_convert(enum mail_index_sync_type type);
+void index_sync_update_recent_count(struct mailbox *box);
 int index_storage_get_status(struct mailbox *box,
                             enum mailbox_status_items items,
                             struct mailbox_status *status_r);
index 0a5b052a86b68b388ed08a39018c13f2ea6df3a0..2bb2703fb04afb42f18ba42007e366556fcd5a8d 100644 (file)
@@ -463,15 +463,31 @@ static int index_sync_precache(struct mailbox *box)
        return cache_add(box, cache);
 }
 
+void index_sync_update_recent_count(struct mailbox *box)
+{
+       struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
+       const struct mail_index_header *hdr;
+       uint32_t seq1, seq2;
+
+       hdr = mail_index_get_header(box->view);
+       if (hdr->first_recent_uid > ibox->recent_flags_prev_uid) {
+               mail_index_lookup_seq_range(box->view,
+                                           hdr->first_recent_uid,
+                                           hdr->next_uid,
+                                           &seq1, &seq2);
+               if (seq1 != 0) {
+                       index_mailbox_set_recent_seq(box, box->view,
+                                                    seq1, seq2);
+               }
+       }
+}
+
 int index_mailbox_sync_deinit(struct mailbox_sync_context *_ctx,
                              struct mailbox_sync_status *status_r)
 {
        struct index_mailbox_sync_context *ctx =
                (struct index_mailbox_sync_context *)_ctx;
-       struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(_ctx->box);
        struct mailbox_sync_rec sync_rec;
-       const struct mail_index_header *hdr;
-       uint32_t seq1, seq2;
        bool delayed_expunges = FALSE;
        int ret = ctx->failed ? -1 : 0;
 
@@ -494,18 +510,7 @@ int index_mailbox_sync_deinit(struct mailbox_sync_context *_ctx,
        if ((_ctx->box->flags & MAILBOX_FLAG_KEEP_RECENT) != 0 &&
            _ctx->box->opened) {
                /* mailbox syncing didn't necessarily update our recent state */
-               hdr = mail_index_get_header(_ctx->box->view);
-               if (hdr->first_recent_uid > ibox->recent_flags_prev_uid) {
-                       mail_index_lookup_seq_range(_ctx->box->view,
-                                                   hdr->first_recent_uid,
-                                                   hdr->next_uid,
-                                                   &seq1, &seq2);
-                       if (seq1 != 0) {
-                               index_mailbox_set_recent_seq(_ctx->box,
-                                                            _ctx->box->view,
-                                                            seq1, seq2);
-                       }
-               }
+               index_sync_update_recent_count(_ctx->box);
        }
 
        if (status_r != NULL)