From c732bf60deb004fcb4872a639d09a7c6c9c33b73 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 5 Feb 2013 18:46:26 +0100 Subject: [PATCH] rfc822 bounces Adding qmail-bounce-encap to encapsulate bounces in rfc822 messages qmail-bounce-encap-20040210 --- qmail-control.9 | 1 + qmail-send.9 | 9 +++++++++ qmail-send.c | 37 ++++++++++++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/qmail-control.9 b/qmail-control.9 index c9bb986..28c4ecf 100644 --- a/qmail-control.9 +++ b/qmail-control.9 @@ -85,6 +85,7 @@ control default used by .I tlsclientciphers \fR(none) \fRqmail-remote .I tlshosts/FQDN.pem \fR(none) \fRqmail-remote .I tlsserverciphers \fR(none) \fRqmail-smtpd +.I usebounceencap \fR0 \fRqmail-send .I virtualdomains \fR(none) \fRqmail-send .fi .RE diff --git a/qmail-send.9 b/qmail-send.9 index e5a44f5..e5be479 100644 --- a/qmail-send.9 +++ b/qmail-send.9 @@ -178,6 +178,15 @@ will try the message once more, but it will treat any temporary delivery failures as permanent failures. .TP 5 +.I usebounceencap +Whether or not to encapsulate the original message in +a MIME part when sending a bounce. +Default: 0 (no). +When set to 0, the bounce contains the original +message, below the error. When set to 1, the original +message is included as a MIME message/rfc822 part, +with the error being the main text/plain part. +.TP 5 .I virtualdomains List of virtual users or domains, one per line. A virtual user has the form diff --git a/qmail-send.c b/qmail-send.c index ccdc852..685b08c 100644 --- a/qmail-send.c +++ b/qmail-send.c @@ -43,6 +43,7 @@ #define OSSIFIED 129600 /* 36 hours; _must_ exceed q-q's DEATH (24 hours) */ int lifetime = 604800; +int usebounceencap = 0; int bouncemaxbytes = 50000; @@ -665,6 +666,8 @@ unsigned long id; static stralloc quoted = {0}; datetime_sec birth; unsigned long qp; + char strid[FMT_ULONG]; + char strqp[FMT_ULONG]; if (!getinfo(&sender,&birth,id)) return 0; /* XXX: print warning */ @@ -707,8 +710,19 @@ unsigned long id; while (!quote2("ed,bouncerecip)) nomem(); qmail_put(&qqt,quoted.s,quoted.len); qmail_puts(&qqt,"\n\ -Subject: failure notice\n\ -\n\ +Subject: failure notice\n"); + if(usebounceencap > 0) { + strid[fmt_ulong(strid,id)] = 0; + strqp[fmt_ulong(strqp,qp)] = 0; + qmail_puts(&qqt,"MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"qrfm-"); + qmail_puts(&qqt,strid); + qmail_puts(&qqt,strqp); + qmail_puts(&qqt,"\"\n\nThis is a multi-part message in MIME format.\n\n--qrfm-"); + qmail_puts(&qqt,strid); + qmail_puts(&qqt,strqp); + qmail_puts(&qqt,"\nContent-Type: text/plain\n"); + } + qmail_puts(&qqt,"\n\ Hi. This is the qmail-send program at "); qmail_put(&qqt,bouncehost.s,bouncehost.len); qmail_puts(&qqt,*sender.s ? ".\n\ @@ -733,7 +747,16 @@ I tried to deliver a bounce message to this address, but the bounce bounced!\n\ qmail_fail(&qqt); } - qmail_puts(&qqt,*sender.s ? "--- Below this line is a copy of the message.\n\n" : "--- Below this line is the original bounce.\n\n"); + if(usebounceencap > 0) { + qmail_puts(&qqt,*sender.s ? "--- Attached is a copy of the message.\n\n" : "--- Attached is the original bounce.\n\n"); + qmail_puts(&qqt,"--qrfm-"); + qmail_puts(&qqt,strid); + qmail_puts(&qqt,strqp); + qmail_puts(&qqt,"\nContent-Type: message/rfc822\nContent-Disposition: attachment\n\n"); + } else { + qmail_puts(&qqt,*sender.s ? "--- Below this line is a copy of the message.\n\n" : "--- Below this line is the original bounce.\n\n"); + } + qmail_puts(&qqt,"Return-Path: <"); while (!quote2("ed,sender.s)) nomem(); qmail_put(&qqt,quoted.s,quoted.len); @@ -760,6 +783,13 @@ I tried to deliver a bounce message to this address, but the bounce bounced!\n\ qmail_fail(&qqt); } + if(usebounceencap > 0) { + qmail_puts(&qqt,"\n--qrfm-"); + qmail_puts(&qqt,strid); + qmail_puts(&qqt,strqp); + qmail_puts(&qqt,"--\n"); + } + qmail_from(&qqt,bouncesender); qmail_to(&qqt,bouncerecip); if (*qmail_close(&qqt)) @@ -1451,6 +1481,7 @@ fd_set *rfds; int getcontrols() { if (control_init() == -1) return 0; if (control_readint(&bouncemaxbytes,"control/bouncemaxbytes") == -1) return 0; if (control_readint(&lifetime,"control/queuelifetime") == -1) return 0; + if (control_readint(&usebounceencap,"control/usebounceencap") == -1) return 0; if (control_readint(&concurrency[0],"control/concurrencylocal") == -1) return 0; if (control_readint(&concurrency[1],"control/concurrencyremote") == -1) return 0; if (control_rldef(&envnoathost,"control/envnoathost",1,"envnoathost") != 1) return 0; -- cgit v1.2.3