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;
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),
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");
}
#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,
}
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
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;
+}
const char *pop3_uidl_format;
const char *postmaster_address;
- const struct message_address *parsed_postmaster_address;
const char *hostname;
const char *recipient_delimiter;
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 {
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