changeset 22907:8b32d37472a0

imapc: If SELECT INBOX fails with NO, treat it as temporary failure If it's treated as "mailbox doesn't exist", the INBOX autocreation code will attempt to CREATE INBOX. This is very unlikely to work.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 11 Apr 2018 14:19:06 +0300
parents 8fc3c7215f29
children 27af5f2acc53
files src/lib-storage/index/imapc/imapc-storage.c
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/imapc/imapc-storage.c	Tue Feb 27 12:26:09 2018 +0200
+++ b/src/lib-storage/index/imapc/imapc-storage.c	Wed Apr 11 14:19:06 2018 +0300
@@ -647,8 +647,22 @@
 			ctx->ret = 0;
 		}
 	} else if (reply->state == IMAPC_COMMAND_STATE_NO) {
+		/* Unless the remote IMAP server supports sending
+		   resp-text-code, we don't know if the NO reply is because
+		   the mailbox doesn't exist or because of some internal error.
+		   We'll default to assuming it doesn't exist, so e.g.
+		   mailbox { auto=create } will auto-create missing mailboxes.
+		   However, INBOX is a special mailbox, which is always
+		   autocreated if it doesn't exist. This is true in both the
+		   local Dovecot and the remote IMAP server. This means that
+		   there's no point in trying to send CREATE INBOX to the
+		   remote server. We'll avoid that by defaulting to temporary
+		   failure with INBOX. */
+		enum mail_error default_error =
+			ctx->mbox->box.inbox_any ?
+			MAIL_ERROR_TEMP : MAIL_ERROR_NOTFOUND;
 		imapc_copy_error_from_reply(ctx->mbox->storage,
-					    MAIL_ERROR_NOTFOUND, reply);
+					    default_error, reply);
 		ctx->ret = -1;
 	} else if (imapc_storage_client_handle_auth_failure(ctx->mbox->storage->client)) {
 		ctx->ret = -1;