Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5661:f18a7fd8ac9a HEAD
Added rejection_reason setting for deliver.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 24 May 2007 20:21:29 +0300 |
parents | 6533e11eda80 |
children | fdc30be3b5e5 |
files | dovecot-example.conf src/deliver/deliver.c src/deliver/deliver.h src/deliver/mail-send.c |
diffstat | 4 files changed, 45 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/dovecot-example.conf Thu May 24 11:34:47 2007 +0300 +++ b/dovecot-example.conf Thu May 24 20:21:29 2007 +0300 @@ -666,6 +666,10 @@ # 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 + #rejection_reason = Your message to <%t> was automatically rejected:%n%r + # UNIX socket path to master authentication server to find users. #auth_socket_path = /var/run/dovecot/auth-master }
--- a/src/deliver/deliver.c Thu May 24 11:34:47 2007 +0300 +++ b/src/deliver/deliver.c Thu May 24 20:21:29 2007 +0300 @@ -652,6 +652,11 @@ deliver_set->sendmail_path = getenv("SENDMAIL_PATH"); if (deliver_set->sendmail_path == NULL) deliver_set->sendmail_path = DEFAULT_SENDMAIL_PATH; + deliver_set->rejection_reason = getenv("REJECTION_REASON"); + if (deliver_set->rejection_reason == NULL) { + deliver_set->rejection_reason = + DEFAULT_MAIL_REJECTION_HUMAN_REASON; + } dict_driver_register(&dict_driver_client); duplicate_init();
--- a/src/deliver/deliver.h Thu May 24 11:34:47 2007 +0300 +++ b/src/deliver/deliver.h Thu May 24 20:21:29 2007 +0300 @@ -6,10 +6,14 @@ #include "lib.h" #include "mail-storage.h" +#define DEFAULT_MAIL_REJECTION_HUMAN_REASON \ + "Your message to <%t> was automatically rejected:%n%r" + struct deliver_settings { const char *hostname; const char *postmaster_address; const char *sendmail_path; + const char *rejection_reason; }; extern struct deliver_settings *deliver_set;
--- a/src/deliver/mail-send.c Thu May 24 11:34:47 2007 +0300 +++ b/src/deliver/mail-send.c Thu May 24 20:21:29 2007 +0300 @@ -4,7 +4,9 @@ #include "ioloop.h" #include "hostpid.h" #include "istream.h" +#include "str.h" #include "str-sanitize.h" +#include "var-expand.h" #include "message-date.h" #include "message-size.h" #include "duplicate.h" @@ -15,13 +17,31 @@ #include <sys/wait.h> -#define MAIL_REJECTION_HUMAN_REASON \ -"Your message was automatically rejected by Dovecot Mail Delivery Agent.\r\n" \ -"\r\n" \ -"The following reason was given:\r\n" \ -"%s\r\n" +int global_outgoing_count = 0; -int global_outgoing_count = 0; +static const struct var_expand_table * +get_var_expand_table(struct mail *mail, const char *reason, + const char *recipient) +{ + static struct var_expand_table static_tab[] = { + { 'n', NULL }, + { 'r', NULL }, + { 's', NULL }, + { 't', NULL }, + { '\0', NULL } + }; + struct var_expand_table *tab; + + tab = t_malloc(sizeof(static_tab)); + memcpy(tab, static_tab, sizeof(static_tab)); + + tab[0].value = "\r\n"; + tab[1].value = reason; + tab[2].value = str_sanitize(mail_get_first_header(mail, "Subject"), 80); + tab[3].value = recipient; + + return tab; +} int mail_send_rejection(struct mail *mail, const char *recipient, const char *reason) @@ -33,6 +53,7 @@ const char *return_addr, *str; const unsigned char *data; const char *msgid, *orig_msgid, *boundary; + string_t *human_reason; size_t size; int ret; @@ -69,7 +90,11 @@ fprintf(f, "Content-Type: text/plain; charset=utf-8\r\n"); fprintf(f, "Content-Disposition: inline\r\n"); fprintf(f, "Content-Transfer-Encoding: 8bit\r\n\r\n"); - fprintf(f, MAIL_REJECTION_HUMAN_REASON"\r\n", reason); + + human_reason = t_str_new(256); + var_expand(human_reason, deliver_set->rejection_reason, + get_var_expand_table(mail, reason, recipient)); + fprintf(f, "%s\r\n", str_c(human_reason)); /* MDN status report */ fprintf(f, "--%s\r\n"