From: Timo Sirainen Date: Tue, 13 Jan 2009 21:55:03 +0000 (-0500) Subject: Added rejection_subject setting to deliver, which is used for rejected mails. X-Git-Tag: 1.2.beta1~121 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=19e0c0db0a28e709b07f88576ab2d74419ecc450;p=thirdparty%2Fdovecot%2Fcore.git Added rejection_subject setting to deliver, which is used for rejected mails. Based on patch by Allan Cassaro. --HG-- branch : HEAD --- diff --git a/dovecot-example.conf b/dovecot-example.conf index 91c07d37b5..b54e14cbe1 100644 --- a/dovecot-example.conf +++ b/dovecot-example.conf @@ -712,8 +712,12 @@ protocol lda { # Binary to use for sending mails. #sendmail_path = /usr/lib/sendmail - # Human readable error message for rejection mails. Use can use variables: - # %n = CRLF, %r = reason, %s = subject, %t = recipient + # Subject: header to use for rejection mails. You can use the same variables + # as for rejection_reason below. + #rejection_subject = Automatically rejected mail + + # Human readable error message for rejection mails. You can use variables: + # %n = CRLF, %r = reason, %s = original subject, %t = recipient #rejection_reason = Your message to <%t> was automatically rejected:%n%r # UNIX socket path to master authentication server to find users. diff --git a/src/deliver/deliver.c b/src/deliver/deliver.c index 7f2fddda93..6342a71f17 100644 --- a/src/deliver/deliver.c +++ b/src/deliver/deliver.c @@ -1048,6 +1048,9 @@ int main(int argc, char *argv[]) deliver_set->sendmail_path = getenv("SENDMAIL_PATH"); if (deliver_set->sendmail_path == NULL) deliver_set->sendmail_path = DEFAULT_SENDMAIL_PATH; + deliver_set->rejection_subject = getenv("REJECTION_SUBJECT"); + if (deliver_set->rejection_subject == NULL) + deliver_set->rejection_subject = DEFAULT_MAIL_REJECTION_SUBJECT; deliver_set->rejection_reason = getenv("REJECTION_REASON"); if (deliver_set->rejection_reason == NULL) { deliver_set->rejection_reason = diff --git a/src/deliver/deliver.h b/src/deliver/deliver.h index 1ea2b6ba73..69b6c9949b 100644 --- a/src/deliver/deliver.h +++ b/src/deliver/deliver.h @@ -10,6 +10,8 @@ #include "lib.h" #include "mail-storage.h" +#define DEFAULT_MAIL_REJECTION_SUBJECT \ + "Automatically rejected mail" #define DEFAULT_MAIL_REJECTION_HUMAN_REASON \ "Your message to <%t> was automatically rejected:%n%r" #define DEFAULT_LOG_FORMAT "msgid=%m: %$" @@ -18,6 +20,7 @@ struct deliver_settings { const char *hostname; const char *postmaster_address; const char *sendmail_path; + const char *rejection_subject; const char *rejection_reason; const char *log_format; bool mailbox_autosubscribe; diff --git a/src/deliver/mail-send.c b/src/deliver/mail-send.c index bd32cd0409..41d89f7cb5 100644 --- a/src/deliver/mail-send.c +++ b/src/deliver/mail-send.c @@ -54,10 +54,10 @@ int mail_send_rejection(struct mail *mail, const char *recipient, struct smtp_client *smtp_client; FILE *f; struct message_size hdr_size; - const char *return_addr, *str; + const char *return_addr, *hdr; const unsigned char *data; const char *msgid, *orig_msgid, *boundary; - string_t *human_reason; + string_t *str; size_t size; int ret; @@ -90,7 +90,12 @@ int mail_send_rejection(struct mail *mail, const char *recipient, fprintf(f, "Content-Type: " "multipart/report; report-type=disposition-notification;\r\n" "\tboundary=\"%s\"\r\n", boundary); - fprintf(f, "Subject: Automatically rejected mail\r\n"); + + str = t_str_new(256); + var_expand(str, deliver_set->rejection_subject, + get_var_expand_table(mail, reason, recipient)); + fprintf(f, "Subject: %s\r\n", str_c(str)); + fprintf(f, "Auto-Submitted: auto-replied (rejected)\r\n"); fprintf(f, "Precedence: bulk\r\n"); fprintf(f, "\r\nThis is a MIME-encapsulated message\r\n\r\n"); @@ -101,10 +106,10 @@ int mail_send_rejection(struct mail *mail, const char *recipient, fprintf(f, "Content-Disposition: inline\r\n"); fprintf(f, "Content-Transfer-Encoding: 8bit\r\n\r\n"); - human_reason = t_str_new(256); - var_expand(human_reason, deliver_set->rejection_reason, + str_truncate(str, 0); + var_expand(str, deliver_set->rejection_reason, get_var_expand_table(mail, reason, recipient)); - fprintf(f, "%s\r\n", str_c(human_reason)); + fprintf(f, "%s\r\n", str_c(str)); /* MDN status report */ fprintf(f, "--%s\r\n" @@ -112,8 +117,8 @@ int mail_send_rejection(struct mail *mail, const char *recipient, boundary); fprintf(f, "Reporting-UA: %s; Dovecot Mail Delivery Agent\r\n", deliver_set->hostname); - if (mail_get_first_header(mail, "Original-Recipient", &str) > 0) - fprintf(f, "Original-Recipient: rfc822; %s\r\n", str); + if (mail_get_first_header(mail, "Original-Recipient", &hdr) > 0) + fprintf(f, "Original-Recipient: rfc822; %s\r\n", hdr); fprintf(f, "Final-Recipient: rfc822; %s\r\n", recipient); if (orig_msgid != NULL)