[dovecot-cvs] dovecot: Added rejection_reason setting for deliver.

dovecot at dovecot.org dovecot at dovecot.org
Thu May 24 20:21:38 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/f18a7fd8ac9a
changeset: 5661:f18a7fd8ac9a
user:      Timo Sirainen <tss at iki.fi>
date:      Thu May 24 20:21:29 2007 +0300
description:
Added rejection_reason setting for deliver.

diffstat:

4 files changed, 45 insertions(+), 7 deletions(-)
dovecot-example.conf    |    4 ++++
src/deliver/deliver.c   |    5 +++++
src/deliver/deliver.h   |    4 ++++
src/deliver/mail-send.c |   39 ++++++++++++++++++++++++++++++++-------

diffs (119 lines):

diff -r 6533e11eda80 -r f18a7fd8ac9a dovecot-example.conf
--- a/dovecot-example.conf	Thu May 24 11:34:47 2007 +0300
+++ b/dovecot-example.conf	Thu May 24 20:21:29 2007 +0300
@@ -665,6 +665,10 @@ 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
+  #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
diff -r 6533e11eda80 -r f18a7fd8ac9a src/deliver/deliver.c
--- 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 @@ 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_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();
diff -r 6533e11eda80 -r f18a7fd8ac9a src/deliver/deliver.h
--- 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;
diff -r 6533e11eda80 -r f18a7fd8ac9a src/deliver/mail-send.c
--- 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 @@ int mail_send_rejection(struct mail *mai
     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 @@ int mail_send_rejection(struct mail *mai
     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"


More information about the dovecot-cvs mailing list