]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mailbox_verify_name() - Deduplicate error handling
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 17 Feb 2018 20:04:52 +0000 (22:04 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 1 Mar 2018 11:47:10 +0000 (13:47 +0200)
src/lib-storage/mail-storage.c

index b72b9017b27cbb909e83068785f1bf1b23ac5419..5e6b9b14b85c711892dc324f01f369b91a7cd85b 100644 (file)
@@ -1032,7 +1032,8 @@ mailbox_name_verify_extra_separators(const char *vname, char sep,
        return TRUE;
 }
 
-static bool mailbox_verify_name_prefix(struct mailbox *box)
+static bool
+mailbox_verify_name_prefix(struct mailbox *box, const char **error_r)
 {
        const char *vname = box->vname;
        struct mail_namespace *ns = box->list->ns;
@@ -1048,10 +1049,8 @@ static bool mailbox_verify_name_prefix(struct mailbox *box)
                   here. The main reason this isn't an assert is to
                   allow any input at all to mailbox_verify_*_name()
                   without crashing. */
-               mail_storage_set_error(box->storage, MAIL_ERROR_PARAMS,
-                       t_strdup_printf("Invalid mailbox name '%s': "
-                                       "Missing namespace prefix '%s'",
-                                       str_sanitize(vname, 80), ns->prefix));
+               *error_r = t_strdup_printf("Missing namespace prefix '%s'",
+                                          ns->prefix);
                return FALSE;
        }
        vname += ns->prefix_len - 1;
@@ -1061,9 +1060,7 @@ static bool mailbox_verify_name_prefix(struct mailbox *box)
 
                if (vname[0] == '\0') {
                        /* "namespace/" isn't a valid mailbox name. */
-                       mail_storage_set_error(box->storage,
-                                              MAIL_ERROR_PARAMS,
-                                              "Invalid mailbox name");
+                       *error_r = "Ends with hierarchy separator";
                        return FALSE;
                }
        }
@@ -1081,8 +1078,12 @@ static int mailbox_verify_name(struct mailbox *box)
                return 0;
        }
 
-       if (!mailbox_verify_name_prefix(box))
+       if (!mailbox_verify_name_prefix(box, &error)) {
+               mail_storage_set_error(box->storage, MAIL_ERROR_PARAMS,
+                       t_strdup_printf("Invalid mailbox name '%s': %s",
+                                       str_sanitize(vname, 80), error));
                return -1;
+       }
 
        list_sep = mailbox_list_get_hierarchy_sep(box->list);
        ns_sep = mail_namespace_get_sep(ns);