fixes for problems causing mail to be both sent and rejected
[unix-history] / usr / src / usr.sbin / sendmail / src / srvrsmtp.c
index ba5b36a..5deb512 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef SMTP
 
 #ifndef lint
 #ifdef SMTP
-static char sccsid[] = "@(#)srvrsmtp.c 6.51 (Berkeley) %G% (with SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 6.52 (Berkeley) %G% (with SMTP)";
 #else
 #else
-static char sccsid[] = "@(#)srvrsmtp.c 6.51 (Berkeley) %G% (without SMTP)";
+static char sccsid[] = "@(#)srvrsmtp.c 6.52 (Berkeley) %G% (without SMTP)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -263,6 +263,7 @@ smtp(e)
                        define('r', protocol, e);
                        define('s', sendinghost, e);
                        initsys(e);
                        define('r', protocol, e);
                        define('s', sendinghost, e);
                        initsys(e);
+                       nrcpts = 0;
                        setproctitle("%s %s: %s", e->e_id, CurHostName, inp);
 
                        /* child -- go do the processing */
                        setproctitle("%s %s: %s", e->e_id, CurHostName, inp);
 
                        /* child -- go do the processing */
@@ -415,7 +416,10 @@ smtp(e)
                        /* no errors during parsing, but might be a duplicate */
                        e->e_to = p;
                        if (!bitset(QBADADDR, a->q_flags))
                        /* no errors during parsing, but might be a duplicate */
                        e->e_to = p;
                        if (!bitset(QBADADDR, a->q_flags))
+                       {
                                message("250 Recipient ok");
                                message("250 Recipient ok");
+                               nrcpts++;
+                       }
                        else
                        {
                                /* punt -- should keep message in ADDRESS.... */
                        else
                        {
                                /* punt -- should keep message in ADDRESS.... */
@@ -449,7 +453,7 @@ smtp(e)
                        collect(TRUE, a != NULL, e);
                        e->e_flags &= ~EF_FATALERRS;
                        if (Errors != 0)
                        collect(TRUE, a != NULL, e);
                        e->e_flags &= ~EF_FATALERRS;
                        if (Errors != 0)
-                               break;
+                               goto abortmessage;
 
                        /*
                        **  Arrange to send to everyone.
 
                        /*
                        **  Arrange to send to everyone.
@@ -470,7 +474,7 @@ smtp(e)
                        */
 
                        SmtpPhase = "delivery";
                        */
 
                        SmtpPhase = "delivery";
-                       if (e->e_nrcpts != 1)
+                       if (nrcpts != 1 && a == NULL)
                        {
                                HoldErrs = TRUE;
                                e->e_errormode = EM_MAIL;
                        {
                                HoldErrs = TRUE;
                                e->e_errormode = EM_MAIL;
@@ -490,13 +494,19 @@ 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);
-                       if (bitset(EF_FATALERRS, e->e_flags))
+
+                       if (bitset(EF_FATALERRS, e->e_flags) && !HoldErrs)
                        {
                                /* avoid sending back an extra message */
                                e->e_flags &= ~EF_FATALERRS;
                        {
                                /* avoid sending back an extra message */
                                e->e_flags &= ~EF_FATALERRS;
+                               e->e_flags |= EF_CLRQUEUE;
                        }
                        else
                        {
                        }
                        else
                        {
+                               /* from now on, we have to operate silently */
+                               HoldErrs = TRUE;
+                               e->e_errormode = EM_MAIL;
+
                                /* if we just queued, poke it */
                                if (a != NULL && e->e_sendmode != SM_QUEUE)
                                {
                                /* if we just queued, poke it */
                                if (a != NULL && e->e_sendmode != SM_QUEUE)
                                {
@@ -510,6 +520,7 @@ smtp(e)
                        if (!Verbose && e->e_sendmode != SM_QUEUE)
                                dowork(id, TRUE, e);
 
                        if (!Verbose && e->e_sendmode != SM_QUEUE)
                                dowork(id, TRUE, e);
 
+  abortmessage:
                        /* if in a child, pop back to our parent */
                        if (InChild)
                                finis();
                        /* if in a child, pop back to our parent */
                        if (InChild)
                                finis();