changeset 22396:0c6517451de5

lib-storage: Don't autocreate mailbox during deletion. Trying to delete a nonexistent autocreated mailbox first created it and then immediately deleted it.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 26 Jun 2017 19:44:43 +0300
parents f9b51fa352bb
children 32fe9ba7019b
files src/lib-storage/index/index-storage.c src/lib-storage/mail-storage.c
diffstat 2 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-storage.c	Tue Jun 27 14:22:50 2017 +0300
+++ b/src/lib-storage/index/index-storage.c	Mon Jun 26 19:44:43 2017 +0300
@@ -735,7 +735,15 @@
 
 	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) {
--- a/src/lib-storage/mail-storage.c	Tue Jun 27 14:22:50 2017 +0300
+++ b/src/lib-storage/mail-storage.c	Mon Jun 26 19:44:43 2017 +0300
@@ -1203,6 +1203,7 @@
 	} 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;
@@ -1549,7 +1550,7 @@
 		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);