update for MIME encapsulated error messages
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Wed, 5 May 1993 06:45:18 +0000 (22:45 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Wed, 5 May 1993 06:45:18 +0000 (22:45 -0800)
SCCS-vsn: usr.sbin/sendmail/src/usersmtp.c 6.29
SCCS-vsn: usr.sbin/sendmail/src/savemail.c 6.39
SCCS-vsn: usr.sbin/sendmail/src/srvrsmtp.c 6.50
SCCS-vsn: usr.sbin/sendmail/src/readcf.c 6.34
SCCS-vsn: usr.sbin/sendmail/src/deliver.c 6.71
SCCS-vsn: usr.sbin/sendmail/src/queue.c 6.56

usr/src/usr.sbin/sendmail/src/deliver.c
usr/src/usr.sbin/sendmail/src/queue.c
usr/src/usr.sbin/sendmail/src/readcf.c
usr/src/usr.sbin/sendmail/src/savemail.c
usr/src/usr.sbin/sendmail/src/srvrsmtp.c
usr/src/usr.sbin/sendmail/src/usersmtp.c

index 5a872da..07daffa 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)deliver.c  6.70 (Berkeley) %G%";
+static char sccsid[] = "@(#)deliver.c  6.71 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -1294,7 +1294,7 @@ tryhost:
                putfromline(mci->mci_out, m, e);
                (*e->e_puthdr)(mci->mci_out, m, e);
                putline("\n", mci->mci_out, m);
                putfromline(mci->mci_out, m, e);
                (*e->e_puthdr)(mci->mci_out, m, e);
                putline("\n", mci->mci_out, m);
-               (*e->e_putbody)(mci->mci_out, m, e);
+               (*e->e_putbody)(mci->mci_out, m, e, NULL);
 
                /* get the exit status */
                rcode = endmailer(mci, e, pv);
 
                /* get the exit status */
                rcode = endmailer(mci, e, pv);
@@ -1805,6 +1805,8 @@ putfromline(fp, m, e)
 **             fp -- file to output onto.
 **             m -- a mailer descriptor to control output format.
 **             e -- the envelope to put out.
 **             fp -- file to output onto.
 **             m -- a mailer descriptor to control output format.
 **             e -- the envelope to put out.
+**             separator -- if non-NULL, a message separator that must
+**                     not be permitted in the resulting message.
 **
 **     Returns:
 **             none.
 **
 **     Returns:
 **             none.
@@ -1813,10 +1815,11 @@ putfromline(fp, m, e)
 **             The message is written onto fp.
 */
 
 **             The message is written onto fp.
 */
 
-putbody(fp, m, e)
+putbody(fp, m, e, separator)
        FILE *fp;
        MAILER *m;
        register ENVELOPE *e;
        FILE *fp;
        MAILER *m;
        register ENVELOPE *e;
+       char *separator;
 {
        char buf[MAXLINE];
 
 {
        char buf[MAXLINE];
 
@@ -1844,6 +1847,14 @@ putbody(fp, m, e)
                        if (buf[0] == 'F' && bitnset(M_ESCFROM, m->m_flags) &&
                            strncmp(buf, "From ", 5) == 0)
                                (void) putc('>', fp);
                        if (buf[0] == 'F' && bitnset(M_ESCFROM, m->m_flags) &&
                            strncmp(buf, "From ", 5) == 0)
                                (void) putc('>', fp);
+                       if (buf[0] == '-' && buf[1] == '-' && separator != NULL)
+                       {
+                               /* possible separator */
+                               int sl = strlen(separator);
+
+                               if (strncmp(&buf[2], separator, sl) == 0)
+                                       (void) putc(' ', fp);
+                       }
                        putline(buf, fp, m);
                }
 
                        putline(buf, fp, m);
                }
 
@@ -1990,7 +2001,7 @@ mailfile(filename, ctladdr, e)
                putfromline(f, FileMailer, e);
                (*e->e_puthdr)(f, FileMailer, e);
                putline("\n", f, FileMailer);
                putfromline(f, FileMailer, e);
                (*e->e_puthdr)(f, FileMailer, e);
                putline("\n", f, FileMailer);
-               (*e->e_putbody)(f, FileMailer, e);
+               (*e->e_putbody)(f, FileMailer, e, NULL);
                putline("\n", f, FileMailer);
                if (ferror(f))
                {
                putline("\n", f, FileMailer);
                if (ferror(f))
                {
index 585f1dd..f3ea45a 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef QUEUE
 
 #ifndef lint
 #ifdef QUEUE
-static char sccsid[] = "@(#)queue.c    6.55 (Berkeley) %G% (with queueing)";
+static char sccsid[] = "@(#)queue.c    6.56 (Berkeley) %G% (with queueing)";
 #else
 #else
-static char sccsid[] = "@(#)queue.c    6.55 (Berkeley) %G% (without queueing)";
+static char sccsid[] = "@(#)queue.c    6.56 (Berkeley) %G% (without queueing)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -133,7 +133,7 @@ notemp:
                if (fd < 0)
                        syserr("!queueup: cannot create %s", e->e_df);
                dfp = fdopen(fd, "w");
                if (fd < 0)
                        syserr("!queueup: cannot create %s", e->e_df);
                dfp = fdopen(fd, "w");
-               (*e->e_putbody)(dfp, FileMailer, e);
+               (*e->e_putbody)(dfp, FileMailer, e, NULL);
                (void) xfclose(dfp, "queueup dfp", e->e_id);
                e->e_putbody = putbody;
        }
                (void) xfclose(dfp, "queueup dfp", e->e_id);
                e->e_putbody = putbody;
        }
index 8387c05..5fa7a1c 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)readcf.c   6.33 (Berkeley) %G%";
+static char sccsid[] = "@(#)readcf.c   6.34 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -1142,6 +1142,10 @@ setoption(opt, val, sticky)
                IgnrDot = atobool(val);
                break;
 
                IgnrDot = atobool(val);
                break;
 
+         case 'j':             /* send errors in MIME (RFC 1341) format */
+               SendMIMEErrors = atobool(val);
+               break;
+
          case 'J':             /* .forward search path */
                ForwardPath = newstr(val);
                break;
          case 'J':             /* .forward search path */
                ForwardPath = newstr(val);
                break;
index 3f40fa8..855d964 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)savemail.c 6.38 (Berkeley) %G%";
+static char sccsid[] = "@(#)savemail.c 6.39 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <pwd.h>
 #endif /* not lint */
 
 # include <pwd.h>
@@ -342,7 +342,7 @@ savemail(e)
                        putfromline(fp, FileMailer, e);
                        (*e->e_puthdr)(fp, FileMailer, e);
                        putline("\n", fp, FileMailer);
                        putfromline(fp, FileMailer, e);
                        (*e->e_puthdr)(fp, FileMailer, e);
                        putline("\n", fp, FileMailer);
-                       (*e->e_putbody)(fp, FileMailer, e);
+                       (*e->e_putbody)(fp, FileMailer, e, NULL);
                        putline("\n", fp, FileMailer);
                        (void) fflush(fp);
                        state = ferror(fp) ? ESM_PANIC : ESM_DONE;
                        putline("\n", fp, FileMailer);
                        (void) fflush(fp);
                        state = ferror(fp) ? ESM_PANIC : ESM_DONE;
@@ -456,6 +456,15 @@ returntosender(msg, returnq, sendbody, e)
 
        (void) sprintf(buf, "Returned mail: %s", msg);
        addheader("Subject", buf, ee);
 
        (void) sprintf(buf, "Returned mail: %s", msg);
        addheader("Subject", buf, ee);
+       if (SendMIMEErrors)
+       {
+               (void) sprintf(buf, "%s.%ld/%s",
+                       ee->e_id, curtime(), MyHostName);
+               ee->e_msgboundary = newstr(buf);
+               (void) sprintf(buf, "multipart/mixed; boundary=\"%s\"",
+                                       ee->e_msgboundary);
+               addheader("Content-Type", buf, ee);
+       }
 
        /* fake up an address header for the from person */
        expand("\201n", buf, &buf[sizeof buf - 1], e);
 
        /* fake up an address header for the from person */
        expand("\201n", buf, &buf[sizeof buf - 1], e);
@@ -517,11 +526,23 @@ errbody(fp, m, e)
        if (e->e_parent == NULL)
        {
                syserr("errbody: null parent");
        if (e->e_parent == NULL)
        {
                syserr("errbody: null parent");
-               putline("\n", fp, m);
                putline("   ----- Original message lost -----\n", fp, m);
                return;
        }
 
                putline("   ----- Original message lost -----\n", fp, m);
                return;
        }
 
+       /*
+       **  Output MIME header.
+       */
+
+       if (e->e_msgboundary != NULL)
+       {
+               putline("This is a MIME-encapsulated message", fp, m);
+               putline("", fp, m);
+               (void) sprintf(buf, "--%s", e->e_msgboundary);
+               putline(buf, fp, m);
+               putline("", fp, m);
+       }
+
        /*
        **  Output error message header (if specified and available).
        */
        /*
        **  Output error message header (if specified and available).
        */
@@ -546,7 +567,7 @@ errbody(fp, m, e)
                {
                        expand(ErrMsgFile, buf, &buf[sizeof buf - 1], e);
                        putline(buf, fp, m);
                {
                        expand(ErrMsgFile, buf, &buf[sizeof buf - 1], e);
                        putline(buf, fp, m);
-                       putline("\n", fp, m);
+                       putline("", fp, m);
                }
        }
 
                }
        }
 
@@ -561,15 +582,14 @@ errbody(fp, m, e)
                {
                        if (printheader)
                        {
                {
                        if (printheader)
                        {
-                               putline("The following addresses failed:\n",
+                               putline("   ----- The following addresses failed -----",
                                        fp, m);
                                printheader = FALSE;
                        }
                        if (q->q_alias != NULL)
                                        fp, m);
                                printheader = FALSE;
                        }
                        if (q->q_alias != NULL)
-                               sprintf(buf, "\t%s\n", q->q_alias->q_paddr);
+                               putline(q->q_alias->q_paddr, fp, m);
                        else
                        else
-                               sprintf(buf, "\t%s\n", q->q_paddr);
-                       putline(buf, fp, m);
+                               putline(q->q_paddr, fp, m);
                }
        }
        if (!printheader)
                }
        }
        if (!printheader)
@@ -603,32 +623,42 @@ errbody(fp, m, e)
 
        if (NoReturn)
                SendBody = FALSE;
 
        if (NoReturn)
                SendBody = FALSE;
+       putline("", fp, m);
        if (e->e_parent->e_df != NULL)
        {
                if (SendBody)
        if (e->e_parent->e_df != NULL)
        {
                if (SendBody)
-               {
-                       putline("\n", fp, m);
                        putline("   ----- Unsent message follows -----\n", fp, m);
                        putline("   ----- Unsent message follows -----\n", fp, m);
-                       (void) fflush(fp);
-                       putheader(fp, m, e->e_parent);
-                       putline("\n", fp, m);
-                       putbody(fp, m, e->e_parent);
-               }
                else
                else
-               {
-                       putline("\n", fp, m);
                        putline("  ----- Message header follows -----\n", fp, m);
                        putline("  ----- Message header follows -----\n", fp, m);
-                       (void) fflush(fp);
-                       putheader(fp, m, e->e_parent);
+               (void) fflush(fp);
+
+               if (e->e_msgboundary != NULL)
+               {
+                       putline("", fp, m);
+                       (void) sprintf(buf, "--%s", e->e_msgboundary);
+                       putline(buf, fp, m);
+                       (void) sprintf(buf, "Content-Type: %s/rfc822",
+                               SendBody ? "message" : "X-message-header");
+                       putline(buf, fp, m);
+                       putline("", fp, m);
+               }
+               putheader(fp, m, e->e_parent);
+               putline("", fp, m);
+               if (SendBody)
+                       putbody(fp, m, e->e_parent, e->e_msgboundary);
+               if (e->e_msgboundary != NULL)
+               {
+                       (void) sprintf(buf, "--%s--", e->e_msgboundary);
+                       putline(buf, fp, m);
                }
        }
        else
        {
                }
        }
        else
        {
-               putline("\n", fp, m);
                putline("  ----- No message was collected -----\n", fp, m);
                putline("  ----- No message was collected -----\n", fp, m);
-               putline("\n", fp, m);
        }
 
        }
 
+       putline("", fp, m);
+
        /*
        **  Cleanup and exit
        */
        /*
        **  Cleanup and exit
        */
index f90bbf4..153874d 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef SMTP
 
 #ifndef lint
 #ifdef SMTP
-static char sccsid[] = "@(#)srvrsmtp.c 6.49 (Berkeley) %G% (with SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 6.50 (Berkeley) %G% (with SMTP)";
 #else
 #else
-static char sccsid[] = "@(#)srvrsmtp.c 6.49 (Berkeley) %G% (without SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 6.50 (Berkeley) %G% (without SMTP)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -447,6 +447,7 @@ smtp(e)
                        /* collect the text of the message */
                        SmtpPhase = "collect";
                        collect(TRUE, a != NULL, e);
                        /* collect the text of the message */
                        SmtpPhase = "collect";
                        collect(TRUE, a != NULL, e);
+                       e->e_flags &= ~EF_FATALERRS;
                        if (Errors != 0)
                                break;
 
                        if (Errors != 0)
                                break;
 
@@ -474,7 +475,6 @@ smtp(e)
                                HoldErrs = TRUE;
                                e->e_errormode = EM_MAIL;
                        }
                                HoldErrs = TRUE;
                                e->e_errormode = EM_MAIL;
                        }
-                       e->e_flags &= ~EF_FATALERRS;
                        e->e_xfp = freopen(queuename(e, 'x'), "w", e->e_xfp);
                        id = e->e_id;
 
                        e->e_xfp = freopen(queuename(e, 'x'), "w", e->e_xfp);
                        id = e->e_id;
 
@@ -490,15 +490,20 @@ smtp(e)
                        /* issue success if appropriate and reset */
                        if (Errors == 0 || HoldErrs)
                                message("250 %s Message accepted for delivery", id);
                        /* issue success if appropriate and reset */
                        if (Errors == 0 || HoldErrs)
                                message("250 %s Message accepted for delivery", id);
-                       else
+                       if (bitset(EF_FATALERRS, e->e_flags))
+                       {
+                               /* avoid sending back an extra message */
                                e->e_flags &= ~EF_FATALERRS;
                                e->e_flags &= ~EF_FATALERRS;
-
-                       /* if we just queued, poke it */
-                       if (a != NULL && e->e_sendmode != SM_QUEUE)
+                       }
+                       else
                        {
                        {
-                               unlockqueue(e);
-                               dowork(id, TRUE, TRUE, e);
-                               e->e_id = NULL;
+                               /* if we just queued, poke it */
+                               if (a != NULL && e->e_sendmode != SM_QUEUE)
+                               {
+                                       unlockqueue(e);
+                                       dowork(id, TRUE, TRUE, e);
+                                       e->e_id = NULL;
+                               }
                        }
 
                        /* now make it really happen */
                        }
 
                        /* now make it really happen */
index bbced10..361d8e0 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef SMTP
 
 #ifndef lint
 #ifdef SMTP
-static char sccsid[] = "@(#)usersmtp.c 6.28 (Berkeley) %G% (with SMTP)";
+static char sccsid[] = "@(#)usersmtp.c 6.29 (Berkeley) %G% (with SMTP)";
 #else
 #else
-static char sccsid[] = "@(#)usersmtp.c 6.28 (Berkeley) %G% (without SMTP)";
+static char sccsid[] = "@(#)usersmtp.c 6.29 (Berkeley) %G% (without SMTP)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -443,7 +443,7 @@ smtpdata(m, mci, e)
        /* now output the actual message */
        (*e->e_puthdr)(mci->mci_out, m, e);
        putline("\n", mci->mci_out, m);
        /* now output the actual message */
        (*e->e_puthdr)(mci->mci_out, m, e);
        putline("\n", mci->mci_out, m);
-       (*e->e_putbody)(mci->mci_out, m, e);
+       (*e->e_putbody)(mci->mci_out, m, e, NULL);
 
        /* terminate the message */
        fprintf(mci->mci_out, ".%s", m->m_eol);
 
        /* terminate the message */
        fprintf(mci->mci_out, ".%s", m->m_eol);