From: Timo Sirainen Date: Sat, 17 Feb 2018 20:04:52 +0000 (+0200) Subject: lib-storage: mailbox_verify_name() - Deduplicate error handling X-Git-Tag: 2.3.9~2206 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a3bab1712f660c3bbfa1a213d0f206f9b9aed3a5;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: mailbox_verify_name() - Deduplicate error handling --- diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index b72b9017b2..5e6b9b14b8 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -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);