Skip to content

Commit

Permalink
lib-storage: Don't autocreate mailbox during deletion.
Browse files Browse the repository at this point in the history
Trying to delete a nonexistent autocreated mailbox first created it and then
immediately deleted it.
  • Loading branch information
sirainen authored and GitLab committed Jun 28, 2017
1 parent b0f0854 commit dc24b97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/lib-storage/index/index-storage.c
Expand Up @@ -700,7 +700,15 @@ int index_storage_mailbox_delete_pre(struct mailbox *box)

if (!box->opened) {
/* \noselect mailbox, try deleting only the directory */
return index_storage_mailbox_delete_dir(box, FALSE);
if (index_storage_mailbox_delete_dir(box, FALSE) == 0)
return 0;
if (mailbox_is_autocreated(box)) {
/* Return success when trying to delete autocreated
mailbox. The client sees it as existing, so we
shouldn't be returning an error. */
return 0;
}
return -1;
}

if ((box->list->flags & MAILBOX_LIST_FLAG_MAILBOX_FILES) == 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/lib-storage/mail-storage.c
Expand Up @@ -1181,6 +1181,7 @@ mailbox_open_full(struct mailbox *box, struct istream *input)
} T_END;

if (ret < 0 && box->storage->error == MAIL_ERROR_NOTFOUND &&
!box->deleting &&
box->input == NULL && mailbox_is_autocreated(box)) T_BEGIN {
ret = mailbox_autocreate_and_reopen(box);
} T_END;
Expand Down Expand Up @@ -1527,7 +1528,7 @@ int mailbox_delete(struct mailbox *box)
if (mailbox_get_last_mail_error(box) != MAIL_ERROR_NOTFOUND &&
!box->mailbox_deleted)
return -1;
/* \noselect mailbox */
/* might be a \noselect mailbox, so continue deletion */
}

ret = box->v.delete_box(box);
Expand Down

0 comments on commit dc24b97

Please sign in to comment.