From: Markus Valentin Date: Thu, 22 Jun 2023 08:01:39 +0000 (+0200) Subject: sdbox: sdbox_mailbox_open() - Force rebuild if index directory is not found but mailb... X-Git-Tag: 2.4.0~2629 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ceee59092bc5977dfc10cc185c8c94aebbd1a343;p=thirdparty%2Fdovecot%2Fcore.git sdbox: sdbox_mailbox_open() - Force rebuild if index directory is not found but mailbox appears to exist This prevents losing mails if a separate index directory was configured and the mail index has been lost. --- diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.c b/src/lib-storage/index/dbox-single/sdbox-storage.c index 8814674663..bb07cf7c96 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.c +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c @@ -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 */