]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
sdbox: sdbox_mailbox_open() - Force rebuild if index directory is not found but mailb...
authorMarkus Valentin <markus.valentin@open-xchange.com>
Thu, 22 Jun 2023 08:01:39 +0000 (10:01 +0200)
committermarkus.valentin <markus.valentin@open-xchange.com>
Thu, 20 Jul 2023 09:28:22 +0000 (09:28 +0000)
This prevents losing mails if a separate index directory was configured
and the mail index has been lost.

src/lib-storage/index/dbox-single/sdbox-storage.c

index 8814674663936db9a4b0c553e334d3baff2ed184..bb07cf7c969746df0d180e9f237699117a1f01d0 100644 (file)
@@ -332,8 +332,9 @@ static int sdbox_mailbox_open(struct mailbox *box)
        struct sdbox_mailbox *mbox = SDBOX_MAILBOX(box);
        struct sdbox_index_header hdr;
        bool need_resize;
+       int existence_ret;
 
-       if (dbox_mailbox_check_existence(box) < 0)
+       if ((existence_ret = dbox_mailbox_check_existence(box)) < 0)
                return -1;
 
        if (sdbox_mailbox_alloc_index(mbox) < 0)
@@ -347,6 +348,13 @@ static int sdbox_mailbox_open(struct mailbox *box)
                return 0;
        }
 
+       if (box->list->set.index_dir != NULL && existence_ret == 0) {
+               /* If there is an separate INDEX directory configured but no
+                  index files found for this mailbox, do an index rebuild */
+               if (sdbox_sync(mbox, SDBOX_SYNC_FLAG_FORCE_REBUILD) < 0)
+                       return -1;
+       }
+
        /* get/generate mailbox guid */
        if (sdbox_read_header(mbox, &hdr, FALSE, &need_resize) < 0) {
                /* looks like the mailbox is corrupted */