diff -r -u qmail-1.03-orig/qmail-control.9 qmail-1.03/qmail-control.9
--- qmail-1.03-orig/qmail-control.9	1998-06-15 10:53:16.000000000 +0000
+++ qmail-1.03/qmail-control.9	2004-02-11 00:37:30.000000000 +0000
@@ -66,6 +66,7 @@
 .I timeoutconnect	\fR60	\fRqmail-remote
 .I timeoutremote	\fR1200	\fRqmail-remote
 .I timeoutsmtpd	\fR1200	\fRqmail-smtpd
+.I usebounceencap	\fR0	\fRqmail-send
 .I virtualdomains	\fR(none)	\fRqmail-send
 .fi
 .RE
diff -r -u qmail-1.03-orig/qmail-send.9 qmail-1.03/qmail-send.9
--- qmail-1.03-orig/qmail-send.9	1998-06-15 10:53:16.000000000 +0000
+++ qmail-1.03/qmail-send.9	2004-02-11 00:37:30.000000000 +0000
@@ -176,6 +176,15 @@
 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 -r -u qmail-1.03-orig/qmail-send.c qmail-1.03/qmail-send.c
--- qmail-1.03-orig/qmail-send.c	1998-06-15 10:53:16.000000000 +0000
+++ qmail-1.03/qmail-send.c	2004-02-11 00:38:12.000000000 +0000
@@ -43,6 +43,7 @@
 #define OSSIFIED 129600 /* 36 hours; _must_ exceed q-q's DEATH (24 hours) */
 
 int lifetime = 604800;
+int usebounceencap = 0;
 
 stralloc percenthack = {0};
 struct constmap mappercenthack;
@@ -661,6 +662,8 @@
  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 */
 
@@ -703,8 +706,19 @@
    while (!quote2(&quoted,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\
@@ -729,7 +743,16 @@
        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(&quoted,sender.s)) nomem();
    qmail_put(&qqt,quoted.s,quoted.len);
@@ -748,6 +771,13 @@
        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))
@@ -1443,6 +1473,7 @@
 
 int getcontrols() { if (control_init() == -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;
