changeset 12264:a3e40c6b14fe

lib-storage: If mailbox deletion failed, we crashed while trying to write undelete record to index.
author Timo Sirainen <tss@iki.fi>
date Thu, 14 Oct 2010 16:53:04 +0100
parents 03ac8057710d
children f3aa8be626fa
files src/lib-storage/mail-storage.c
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-storage.c	Thu Oct 14 16:22:54 2010 +0100
+++ b/src/lib-storage/mail-storage.c	Thu Oct 14 16:53:04 2010 +0100
@@ -669,8 +669,10 @@
 
 int mailbox_mark_index_deleted(struct mailbox *box, bool del)
 {
+	struct mail_index_transaction *trans;
 	enum mail_index_transaction_flags trans_flags = 0;
-	struct mail_index_transaction *trans;
+	enum mailbox_flags old_flag;
+	int ret;
 
 	if (box->marked_deleted && del) {
 		/* we already marked it deleted. this allows plugins to
@@ -678,6 +680,13 @@
 		return 0;
 	}
 
+	old_flag = box->flags & MAILBOX_FLAG_OPEN_DELETED;
+	box->flags |= MAILBOX_FLAG_OPEN_DELETED;
+	ret = mailbox_open(box);
+	box->flags = (box->flags & ~MAILBOX_FLAG_OPEN_DELETED) | old_flag;
+	if (ret < 0)
+		return -1;
+
 	trans_flags = del ? 0 : MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL;
 	trans = mail_index_transaction_begin(box->view, trans_flags);
 	if (del)