]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: cmd-getmetadata: Retrieve metadata values without opening the mailbox
authorSiavash Tavakoli <siavash.tavakoli@open-xchange.com>
Tue, 1 Dec 2020 17:21:03 +0000 (17:21 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 13 Jan 2021 09:52:36 +0000 (09:52 +0000)
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"

src/imap/cmd-getmetadata.c

index 7b653b6afc1f8117faa2149d461f2b13e545cc32..ac014c4f1df7cd3a27323772783cd7b80d141a88 100644 (file)
@@ -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;