return index_storage_mailbox_delete_dir(box, FALSE);
}
+ if (mailbox_mark_index_deleted(box, TRUE) < 0)
+ return -1;
+
if (mailbox_get_guid(box, mailbox_guid) < 0)
return -1;
int mail_set_aborted(struct mail *mail);
void mail_set_expunged(struct mail *mail);
void mailbox_set_deleted(struct mailbox *box);
+int mailbox_mark_index_deleted(struct mailbox *box, bool del);
void mailbox_refresh_permissions(struct mailbox *box);
/* Returns -1 if error, 0 if failed with EEXIST, 1 if ok */
return box->v.update(box, update);
}
-static int mailbox_mark_index_deleted(struct mailbox *box, bool del)
+int mailbox_mark_index_deleted(struct mailbox *box, bool del)
{
enum mail_index_transaction_flags trans_flags = 0;
struct mail_index_transaction *trans;
}
}
- if (box->opened) {
- if (mailbox_mark_index_deleted(box, TRUE) < 0)
- return -1;
- }
ret = box->v.delete(box);
box->deleting = FALSE;
char timestamp[256];
int ret;
- if (llist->internal_namespace)
+ if (llist->internal_namespace || !box->opened) {
+ /* a) deleting mailbox from lazy_expunge namespaces
+ b) deleting a \noselect mailbox */
return lbox->super.delete(box);
+ }
expunge_ns = get_lazy_ns(list->ns->user, LAZY_NAMESPACE_EXPUNGE);
dest_ns = get_lazy_ns(list->ns->user, LAZY_NAMESPACE_DELETE);
destname = t_strconcat(box->name, "-", timestamp, NULL);
}
- /* first move the actual mailbox */
+ /* avoid potential race conditions by marking it deleted */
+ if (mailbox_mark_index_deleted(box, TRUE) < 0)
+ return -1;
+
+ /* rename it into the lazy_expunge namespace */
ret = mailbox_move(box, dest_ns->list, destname, &expunge_box);
if (ret < 0)
return -1;