more cleanup for DSN drafts
[unix-history] / usr / src / usr.sbin / sendmail / src / srvrsmtp.c
index cb51cf5..5280aac 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef SMTP
 
 #ifndef lint
 #ifdef SMTP
-static char sccsid[] = "@(#)srvrsmtp.c 8.50 (Berkeley) %G% (with SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 8.62 (Berkeley) %G% (with SMTP)";
 #else
 #else
-static char sccsid[] = "@(#)srvrsmtp.c 8.50 (Berkeley) %G% (without SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 8.62 (Berkeley) %G% (without SMTP)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -124,7 +124,7 @@ smtp(e)
                CurSmtpClient = CurHostName;
 
        setproctitle("server %s startup", CurSmtpClient);
                CurSmtpClient = CurHostName;
 
        setproctitle("server %s startup", CurSmtpClient);
-       expand("\201e", inp, &inp[sizeof inp], e);
+       expand("\201e", inp, sizeof inp, e);
        if (BrokenSmtpPeers)
        {
                p = strchr(inp, '\n');
        if (BrokenSmtpPeers)
        {
                p = strchr(inp, '\n');
@@ -334,7 +334,7 @@ smtp(e)
                        define('s', sendinghost, e);
                        initsys(e);
                        nrcpts = 0;
                        define('s', sendinghost, e);
                        initsys(e);
                        nrcpts = 0;
-                       e->e_flags |= EF_LOGSENDER;
+                       e->e_flags |= EF_LOGSENDER|EF_CLRQUEUE;
                        setproctitle("%s %s: %.80s", e->e_id, CurSmtpClient, inp);
 
                        /* child -- go do the processing */
                        setproctitle("%s %s: %.80s", e->e_id, CurSmtpClient, inp);
 
                        /* child -- go do the processing */
@@ -372,7 +372,7 @@ smtp(e)
                        }
 
                        /* now parse ESMTP arguments */
                        }
 
                        /* now parse ESMTP arguments */
-                       msize = 0;
+                       e->e_msgsize = 0;
                        while (p != NULL && *p != '\0')
                        {
                                char *kp;
                        while (p != NULL && *p != '\0')
                        {
                                char *kp;
@@ -407,75 +407,17 @@ smtp(e)
                                        printf("MAIL: got arg %s=\"%s\"\n", kp,
                                                vp == NULL ? "<null>" : vp);
 
                                        printf("MAIL: got arg %s=\"%s\"\n", kp,
                                                vp == NULL ? "<null>" : vp);
 
-                               if (strcasecmp(kp, "size") == 0)
-                               {
-                                       if (vp == NULL)
-                                       {
-                                               usrerr("501 SIZE requires a value");
-                                               /* NOTREACHED */
-                                       }
-# ifdef __STDC__
-                                       msize = strtoul(vp, (char **) NULL, 10);
-# else
-                                       msize = strtol(vp, (char **) NULL, 10);
-# endif
-                               }
-                               else if (strcasecmp(kp, "body") == 0)
-                               {
-                                       if (vp == NULL)
-                                       {
-                                               usrerr("501 BODY requires a value");
-                                               /* NOTREACHED */
-                                       }
-                                       e->e_bodytype = newstr(vp);
-                                       if (strcasecmp(vp, "8bitmime") == 0)
-                                       {
-                                               SevenBitInput = FALSE;
-                                       }
-                                       else if (strcasecmp(vp, "7bit") == 0)
-                                       {
-                                               SevenBitInput = TRUE;
-                                       }
-                                       else
-                                       {
-                                               usrerr("501 Unknown BODY type %s",
-                                                       vp);
-                                               /* NOTREACHED */
-                                       }
-                               }
-                               else if (strcasecmp(kp, "envid") == 0)
-                               {
-                                       if (vp == NULL)
-                                       {
-                                               usrerr("501 ENVID requires a value");
-                                               /* NOTREACHED */
-                                       }
-                                       e->e_envid = newstr(vp);
-                               }
-                               else if (strcasecmp(kp, "omts") == 0)
-                               {
-                                       if (vp == NULL)
-                                       {
-                                               usrerr("501 OMTS requires a value");
-                                               /* NOTREACHED */
-                                       }
-                                       e->e_omts = newstr(vp);
-                               }
-                               else
-                               {
-                                       usrerr("501 %s parameter unrecognized", kp);
-                                       /* NOTREACHED */
-                               }
+                               mail_esmtp_args(kp, vp, e);
                        }
 
                        }
 
-                       if (MaxMessageSize > 0 && msize > MaxMessageSize)
+                       if (MaxMessageSize > 0 && e->e_msgsize > MaxMessageSize)
                        {
                                usrerr("552 Message size exceeds fixed maximum message size (%ld)",
                                        MaxMessageSize);
                                /* NOTREACHED */
                        }
                                
                        {
                                usrerr("552 Message size exceeds fixed maximum message size (%ld)",
                                        MaxMessageSize);
                                /* NOTREACHED */
                        }
                                
-                       if (!enoughspace(msize))
+                       if (!enoughspace(e->e_msgsize))
                        {
                                message("452 Insufficient disk space; try again later");
                                break;
                        {
                                message("452 Insufficient disk space; try again later");
                                break;
@@ -568,6 +510,9 @@ smtp(e)
                        if (Errors != 0)
                                goto abortmessage;
 
                        if (Errors != 0)
                                goto abortmessage;
 
+                       /* make sure we actually do delivery */
+                       e->e_flags &= ~EF_CLRQUEUE;
+
                        /* from now on, we have to operate silently */
                        HoldErrs = TRUE;
                        e->e_errormode = EM_MAIL;
                        /* from now on, we have to operate silently */
                        HoldErrs = TRUE;
                        e->e_errormode = EM_MAIL;
@@ -598,6 +543,8 @@ smtp(e)
                        {
                                /* make sure it is in the queue */
                                queueup(e, TRUE, FALSE);
                        {
                                /* make sure it is in the queue */
                                queueup(e, TRUE, FALSE);
+                               if (e->e_sendmode == SM_QUEUE)
+                                       e->e_flags |= EF_KEEPQUEUE;
                        }
                        else
                        {
                        }
                        else
                        {
@@ -636,6 +583,9 @@ smtp(e)
 
                  case CMDRSET:         /* rset -- reset state */
                        message("250 Reset state");
 
                  case CMDRSET:         /* rset -- reset state */
                        message("250 Reset state");
+
+                       /* arrange to ignore any current send list */
+                       e->e_sendqueue = NULL;
                        e->e_flags |= EF_CLRQUEUE;
                        if (InChild)
                                finis();
                        e->e_flags |= EF_CLRQUEUE;
                        if (InChild)
                                finis();
@@ -691,6 +641,9 @@ smtp(e)
                        message("221 %s closing connection", MyHostName);
 
 doquit:
                        message("221 %s closing connection", MyHostName);
 
 doquit:
+                       /* arrange to ignore any current send list */
+                       e->e_sendqueue = NULL;
+
                        /* avoid future 050 messages */
                        disconnect(1, e);
 
                        /* avoid future 050 messages */
                        disconnect(1, e);
 
@@ -814,6 +767,105 @@ skipword(p, w)
        return (p);
 }
 \f/*
        return (p);
 }
 \f/*
+**  MAIL_ESMTP_ARGS -- process ESMTP arguments from MAIL line
+**
+**     Parameters:
+**             kp -- the parameter key.
+**             vp -- the value of that parameter.
+**             e -- the envelope.
+**
+**     Returns:
+**             none.
+*/
+
+mail_esmtp_args(kp, vp, e)
+       char *kp;
+       char *vp;
+       ENVELOPE *e;
+{
+       if (strcasecmp(kp, "size") == 0)
+       {
+               if (vp == NULL)
+               {
+                       usrerr("501 SIZE requires a value");
+                       /* NOTREACHED */
+               }
+# ifdef __STDC__
+               e->e_msgsize = strtoul(vp, (char **) NULL, 10);
+# else
+               e->e_msgsize = strtol(vp, (char **) NULL, 10);
+# endif
+       }
+       else if (strcasecmp(kp, "body") == 0)
+       {
+               if (vp == NULL)
+               {
+                       usrerr("501 BODY requires a value");
+                       /* NOTREACHED */
+               }
+               if (strcasecmp(vp, "8bitmime") == 0)
+               {
+                       SevenBitInput = FALSE;
+               }
+               else if (strcasecmp(vp, "7bit") == 0)
+               {
+                       SevenBitInput = TRUE;
+               }
+               else
+               {
+                       usrerr("501 Unknown BODY type %s",
+                               vp);
+                       /* NOTREACHED */
+               }
+               e->e_bodytype = newstr(vp);
+       }
+       else if (strcasecmp(kp, "envid") == 0)
+       {
+               if (vp == NULL)
+               {
+                       usrerr("501 ENVID requires a value");
+                       /* NOTREACHED */
+               }
+               if (!xtextok(vp))
+               {
+                       usrerr("501 Syntax error in ENVID parameter value");
+                       /* NOTREACHED */
+               }
+               if (e->e_envid != NULL)
+               {
+                       usrerr("501 Duplicate ENVID parameter");
+                       /* NOTREACHED */
+               }
+               e->e_envid = newstr(vp);
+       }
+       else if (strcasecmp(kp, "ret") == 0)
+       {
+               if (vp == NULL)
+               {
+                       usrerr("501 RET requires a value");
+                       /* NOTREACHED */
+               }
+               if (bitset(EF_RET_PARAM, e->e_flags))
+               {
+                       usrerr("501 Duplicate RET parameter");
+                       /* NOTREACHED */
+               }
+               e->e_flags |= EF_RET_PARAM;
+               if (strcasecmp(vp, "hdrs") == 0)
+                       e->e_flags |= EF_NO_BODY_RETN;
+               else if (strcasecmp(vp, "full") != 0)
+               {
+                       usrerr("501 Bad argument \"%s\" to RET", vp);
+                       /* NOTREACHED */
+               }
+       }
+       else
+       {
+               usrerr("501 %s parameter unrecognized", kp);
+               /* NOTREACHED */
+       }
+}
+\f/*
 **  RCPT_ESMTP_ARGS -- process ESMTP arguments from RCPT line
 **
 **     Parameters:
 **  RCPT_ESMTP_ARGS -- process ESMTP arguments from RCPT line
 **
 **     Parameters:
@@ -842,6 +894,7 @@ rcpt_esmtp_args(a, kp, vp, e)
                        /* NOTREACHED */
                }
                a->q_flags &= ~(QPINGONSUCCESS|QPINGONFAILURE|QPINGONDELAY);
                        /* NOTREACHED */
                }
                a->q_flags &= ~(QPINGONSUCCESS|QPINGONFAILURE|QPINGONDELAY);
+               a->q_flags |= QHASNOTIFY;
                if (strcasecmp(vp, "never") == 0)
                        return;
                for (p = vp; p != NULL; vp = p)
                if (strcasecmp(vp, "never") == 0)
                        return;
                for (p = vp; p != NULL; vp = p)
@@ -863,27 +916,21 @@ rcpt_esmtp_args(a, kp, vp, e)
                        }
                }
        }
                        }
                }
        }
-       else if (strcasecmp(kp, "ret") == 0)
+       else if (strcasecmp(kp, "orcpt") == 0)
        {
                if (vp == NULL)
                {
        {
                if (vp == NULL)
                {
-                       usrerr("501 RET requires a value");
+                       usrerr("501 ORCPT requires a value");
                        /* NOTREACHED */
                }
                        /* NOTREACHED */
                }
-               a->q_flags |= QHAS_RET_PARAM;
-               if (strcasecmp(vp, "hdrs") == 0)
-                       a->q_flags |= QRET_HDRS;
-               else if (strcasecmp(vp, "full") != 0)
+               if (!xtextok(vp))
                {
                {
-                       usrerr("501 Bad argument \"%s\" to RET", vp);
+                       usrerr("501 Syntax error in ORCPT parameter value");
                        /* NOTREACHED */
                }
                        /* NOTREACHED */
                }
-       }
-       else if (strcasecmp(kp, "orcpt") == 0)
-       {
-               if (vp == NULL)
+               if (a->q_orcpt != NULL)
                {
                {
-                       usrerr("501 ORCPT requires a value");
+                       usrerr("501 Duplicate ORCPT parameter");
                        /* NOTREACHED */
                }
                a->q_orcpt = newstr(vp);
                        /* NOTREACHED */
                }
                a->q_orcpt = newstr(vp);