]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Delay error handing for invalid postmaster_address setting
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 14 Dec 2017 10:01:33 +0000 (12:01 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 14 Dec 2017 22:06:09 +0000 (00:06 +0200)
src/lib-lda/mail-send.c
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage-settings.h

index 11db554d307f628b028f16e5e41304f484f35bb8..e7d26d57ba022846c7ade38f07e22d8ce31e08bd 100644 (file)
@@ -58,6 +58,7 @@ int mail_send_rejection(struct mail_deliver_context *ctx,
        struct istream *input;
        struct smtp_submit *smtp_submit;
        struct ostream *output;
+       const struct message_address *postmaster_addr;
        const struct smtp_address *return_addr;
        const char *hdr, *value, *msgid, *orig_msgid, *boundary, *error;
        const struct var_expand_table *vtable;
@@ -83,6 +84,13 @@ int mail_send_rejection(struct mail_deliver_context *ctx,
                return 0;
        }
 
+       if (!mail_storage_get_postmaster_address(mail_set, &postmaster_addr,
+                                                &error)) {
+               i_error("msgid=%s: Invalid postmaster_address - can't send rejection: %s",
+                       orig_msgid == NULL ? "" : str_sanitize(orig_msgid, 80), error);
+               return -1;
+       }
+
        if (mailbox_get_settings(mail->box)->mail_debug) {
                i_debug("Sending a rejection to <%s>: %s",
                        smtp_address_encode(return_addr),
@@ -105,7 +113,7 @@ int mail_send_rejection(struct mail_deliver_context *ctx,
        str_printfa(str, "Message-ID: %s\r\n", msgid);
        str_printfa(str, "Date: %s\r\n", message_date_create(ioloop_time));
        str_append(str, "From: ");
-       message_address_write(str, mail_set->parsed_postmaster_address);
+       message_address_write(str, postmaster_addr);
        str_append(str, "\r\n");
        str_printfa(str, "To: <%s>\r\n", smtp_address_encode(return_addr));
        str_append(str, "MIME-Version: 1.0\r\n");
index a73ca67431543802e041e4914b3e25e95562a02e..1a27bdd95c78ec864842dd40cb17f5443314ec1b 100644 (file)
@@ -526,11 +526,10 @@ static bool mail_storage_settings_check(void *_set, pool_t pool ATTR_UNUSED,
 }
 
 #ifndef CONFIG_BINARY
-static bool mail_storage_settings_expand_check(void *_set,
-       pool_t pool ATTR_UNUSED, const char **error_r)
+static bool parse_postmaster_address(const char *address, pool_t pool,
+                                    const struct message_address **addr_r,
+                                    const char **error_r)
 {
-       struct mail_storage_settings *set = _set;
-       const char *address = set->postmaster_address;
        struct message_address *addr;
 
        addr = message_address_parse(pool,
@@ -549,8 +548,20 @@ static bool mail_storage_settings_expand_check(void *_set,
        }
        if (addr->name == NULL || *addr->name == '\0')
                addr->name = "Postmaster";
-       set->parsed_postmaster_address = addr;
+       *addr_r = addr;
+       return TRUE;
+}
 
+static bool mail_storage_settings_expand_check(void *_set,
+       pool_t pool, const char **error_r ATTR_UNUSED)
+{
+       struct mail_storage_settings *set = _set;
+       const char *error;
+
+       /* Parse if possible. Perform error handling later. */
+       (void)parse_postmaster_address(set->postmaster_address, pool,
+                                      &set->_parsed_postmaster_address,
+                                      &error);
        return TRUE;
 }
 #endif
@@ -688,3 +699,20 @@ static bool mail_user_settings_check(void *_set, pool_t pool ATTR_UNUSED,
        return TRUE;
 }
 /* </settings checks> */
+
+bool mail_storage_get_postmaster_address(const struct mail_storage_settings *set,
+                                        const struct message_address **address_r,
+                                        const char **error_r)
+{
+       *address_r = set->_parsed_postmaster_address;
+       if (*address_r != NULL)
+               return TRUE;
+
+       /* parsing failed - do it again to get the error */
+       const struct message_address *addr;
+       if (parse_postmaster_address(set->postmaster_address,
+                                    pool_datastack_create(), &addr, error_r))
+               i_panic("postmaster_address='%s' parsing succeeded unexpectedly after it had already failed",
+                       set->postmaster_address);
+       return FALSE;
+}
index d8a392537e1f3c3005e49374f0bc894f6df16d73..9e17cb9d609b75a5b24a6465bc2fecca47241c7e 100644 (file)
@@ -60,7 +60,6 @@ struct mail_storage_settings {
        const char *pop3_uidl_format;
 
        const char *postmaster_address;
-       const struct message_address *parsed_postmaster_address;
 
        const char *hostname;
        const char *recipient_delimiter;
@@ -71,6 +70,9 @@ struct mail_storage_settings {
 
        enum file_lock_method parsed_lock_method;
        enum fsync_mode parsed_fsync_mode;
+       /* May be NULL - use mail_storage_get_postmaster_address() instead of
+          directly accessing this. */
+       const struct message_address *_parsed_postmaster_address;
 };
 
 struct mail_namespace_settings {
@@ -153,4 +155,8 @@ const void *mail_namespace_get_driver_settings(struct mail_namespace *ns,
 const struct dynamic_settings_parser *
 mail_storage_get_dynamic_parsers(pool_t pool);
 
+bool mail_storage_get_postmaster_address(const struct mail_storage_settings *set,
+                                        const struct message_address **address_r,
+                                        const char **error_r);
+
 #endif