From: Siavash Tavakoli Date: Wed, 9 Dec 2020 01:31:30 +0000 (+0000) Subject: imap: cmd-setmetadata: Do not open mailbox X-Git-Tag: 2.3.14.rc1~155 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=58668e16112de5a06e0b916edb36a83893c50416;p=thirdparty%2Fdovecot%2Fcore.git imap: cmd-setmetadata: Do not open mailbox Set metadata without actually opening the mailbox. As a side-effect this changes SETMETADATA command response when ACL rules are present and user only has lookup right. For non-existing mailboxes, command fails with "Mailbox doesn't exist" message instead of "Permission denied" error. --- diff --git a/src/imap/cmd-setmetadata.c b/src/imap/cmd-setmetadata.c index 85be2eab4e..eb18dfd578 100644 --- a/src/imap/cmd-setmetadata.c +++ b/src/imap/cmd-setmetadata.c @@ -7,6 +7,7 @@ #include "ostream.h" #include "str.h" #include "imap-metadata.h" +#include "mail-storage-private.h" #define METADATA_MAX_INMEM_SIZE (1024*128) @@ -317,7 +318,15 @@ cmd_setmetadata_mailbox(struct imap_setmetadata_context *ctx, ctx->box = mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_ATTRIBUTE_SESSION); mailbox_set_reason(ctx->box, "SETMETADATA"); - if (mailbox_open(ctx->box) < 0) { + enum mailbox_existence existence; + if (mailbox_exists(ctx->box, TRUE, &existence) < 0) { + client_send_box_error(cmd, ctx->box); + mailbox_free(&ctx->box); + return TRUE; + } else if (existence == MAILBOX_EXISTENCE_NONE) { + const char *err = t_strdup_printf(MAIL_ERRSTR_MAILBOX_NOT_FOUND, + mailbox_get_vname(ctx->box)); + mail_storage_set_error(ctx->box->storage, MAIL_ERROR_NOTFOUND, err); client_send_box_error(cmd, ctx->box); mailbox_free(&ctx->box); return TRUE;