]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Moved "INBOX can't be deleted" check from lib-storage to IMAP-specific code.
authorTimo Sirainen <tss@iki.fi>
Wed, 12 Jun 2013 18:41:09 +0000 (21:41 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 12 Jun 2013 18:41:09 +0000 (21:41 +0300)
Especially "doveadm backup" should be able to delete the INBOX if needed.

src/imap/cmd-delete.c
src/lib-storage/mail-storage.c
src/lib-storage/mail-storage.h

index 669b2c35170afc28d3e27198fd5d9ecfe67fbbf9..420755ba272528c7026e54158a50ad89624e0d0c 100644 (file)
@@ -16,17 +16,18 @@ bool cmd_delete(struct client_command_context *cmd)
        if (!client_read_string_args(cmd, 1, &name))
                return FALSE;
 
-       if (strcasecmp(name, "INBOX") == 0) {
-               /* INBOX can't be deleted */
-               client_send_tagline(cmd, "NO INBOX can't be deleted.");
-               return TRUE;
-       }
-
        ns = client_find_namespace(cmd, &name);
        if (ns == NULL)
                return TRUE;
 
        box = mailbox_alloc(ns->list, name, 0);
+       if (mailbox_is_any_inbox(box)) {
+               /* IMAP protocol allows this, but I think it's safer to
+                  not allow it. */
+               mailbox_free(&box);
+               client_send_tagline(cmd, "NO INBOX can't be deleted.");
+               return TRUE;
+       }
        if (client->mailbox != NULL &&
            mailbox_backends_equal(box, client->mailbox)) {
                /* deleting selected mailbox. close it first */
index 78857027af77e3ace47ba05378e81a2d5317f395..415b00c6f3ab1ea45b05600248edc7ea0df89c50 100644 (file)
@@ -1213,6 +1213,11 @@ bool mailbox_equals(const struct mailbox *box1,
                strcasecmp(vname2, "INBOX") == 0;
 }
 
+bool mailbox_is_any_inbox(struct mailbox *box)
+{
+       return box->inbox_any;
+}
+
 int mailbox_create(struct mailbox *box, const struct mailbox_update *update,
                   bool directory)
 {
@@ -1288,11 +1293,6 @@ int mailbox_delete(struct mailbox *box)
                                       "Storage root can't be deleted");
                return -1;
        }
-       if (box->inbox_any) {
-               mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
-                                      "INBOX can't be deleted.");
-               return -1;
-       }
 
        box->deleting = TRUE;
        if (mailbox_open(box) < 0) {
index 0a91572cc7f9a6051151e298e32dd495f3b2f8b2..81d4b76179a8cc5bcec77a4679ab846103e778c5 100644 (file)
@@ -481,6 +481,8 @@ void mailbox_free(struct mailbox **box);
 bool mailbox_equals(const struct mailbox *box1,
                    const struct mail_namespace *ns2,
                    const char *vname2) ATTR_PURE;
+/* Returns TRUE if the mailbox is user's INBOX or another user's shared INBOX */
+bool mailbox_is_any_inbox(struct mailbox *box);
 
 /* Returns -1 if mailbox_create() is guaranteed to fail because the mailbox
    name is invalid, 0 not. The error message contains a reason. */