From: Siavash Tavakoli Date: Tue, 1 Dec 2020 17:21:03 +0000 (+0000) Subject: imap: cmd-getmetadata: Retrieve metadata values without opening the mailbox X-Git-Tag: 2.3.14.rc1~156 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=51b5b63b759ff2af450adf95eb63635e959f8f50;p=thirdparty%2Fdovecot%2Fcore.git imap: cmd-getmetadata: Retrieve metadata values without opening the mailbox No need to actually opening the mailbox, only check for its existence. This also makes GETMETADATA command behave more in line with RFC 5464 when acls are preset. Changes to command results for different cases: - User with only "l" right: - for non-existing mailbox command failure error changed from "Permission denied" to "Mailbox doesn't exist" - User with "l" right and one of "s", "w", "i", and "p" rights: - for INBOX, command result changed from "Permission denied" failure to "OK" - for existing mailboxes, command result changed from "Permission denied" failure to "OK" - for non-existing mailboxes, command failure error changed from "Permission denied" to "Mailbox doesn't exist" - for autocreated mailboxes, command result changed from "Permission denied" failure to "OK" - User with "l" right and one of "x", "c", "d", and "a" rights: - for non-existing mailboxes, command failure error changed from "Permission denied" to "Mailbox doesn't exist" - User with only "r" right: - for INBOX, command result changed from "OK" to "Mailbox doesn't exist" - for existing mailboxes, command result changed from "OK" to "Mailbox doesn't exist" - for autocreated mailboxes, command result changed from "OK" to "Mailbox doesn't exist" --- diff --git a/src/imap/cmd-getmetadata.c b/src/imap/cmd-getmetadata.c index 7b653b6afc..ac014c4f1d 100644 --- a/src/imap/cmd-getmetadata.c +++ b/src/imap/cmd-getmetadata.c @@ -1,6 +1,7 @@ /* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ #include "imap-common.h" +#include "mail-storage-private.h" #include "str.h" #include "istream.h" #include "istream-sized.h" @@ -436,8 +437,16 @@ cmd_getmetadata_try_mailbox(struct imap_getmetadata_context *ctx, ctx->box = mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_READONLY); event_add_str(ctx->cmd->event, "mailbox", mailbox_get_vname(ctx->box)); mailbox_set_reason(ctx->box, "GETMETADATA"); - if (mailbox_open(ctx->box) < 0) + + enum mailbox_existence existence; + if (mailbox_exists(ctx->box, TRUE, &existence) < 0) { + return -1; + } 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); return -1; + } ctx->trans = imap_metadata_transaction_begin(ctx->box); return cmd_getmetadata_start(ctx) ? 1 : 0;