From c6a6247939591175f8f8dcdd9286bccc9d901b7a Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 14 May 2018 21:31:59 +0300 Subject: [PATCH] lib-storage: Add MAILBOX_FLAG_FSCK to fsck index immediately after opening it This can be used to fix a broken index that is causing mailbox_open() to fail. --- src/lib-storage/index/index-storage.c | 6 ++++++ src/lib-storage/mail-storage.h | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib-storage/index/index-storage.c b/src/lib-storage/index/index-storage.c index 218b624141..56199fdb4f 100644 --- a/src/lib-storage/index/index-storage.c +++ b/src/lib-storage/index/index-storage.c @@ -332,6 +332,12 @@ int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory) return -1; } } + if ((box->flags & MAILBOX_FLAG_FSCK) != 0) { + if (mail_index_fsck(box->index) < 0) { + mailbox_set_index_error(box); + return -1; + } + } box->cache = mail_index_get_cache(box->index); index_cache_register_defaults(box); diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index f863993717..5b7b6fc7fc 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -68,7 +68,11 @@ enum mailbox_flags { /* Mailbox is created implicitly if it does not exist. */ MAILBOX_FLAG_AUTO_CREATE = 0x1000, /* Mailbox is subscribed to implicitly when it is created automatically */ - MAILBOX_FLAG_AUTO_SUBSCRIBE = 0x2000 + MAILBOX_FLAG_AUTO_SUBSCRIBE = 0x2000, + /* Run fsck for mailbox index before doing anything else. This may be + useful in fixing index corruption errors that aren't otherwise + detected and that are causing the full mailbox opening to fail. */ + MAILBOX_FLAG_FSCK = 0x4000, }; enum mailbox_feature { -- 2.47.3