BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.sbin / sendmail / src / deliver.c
index 56cdfa4..c8e05f1 100644 (file)
@@ -3,21 +3,37 @@
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)deliver.c  5.35 (Berkeley) %G%";
+static char sccsid[] = "@(#)deliver.c  5.41 (Berkeley) 3/21/91";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -27,6 +43,7 @@ static char sccsid[] = "@(#)deliver.c 5.35 (Berkeley) %G%";
 #include <fcntl.h>
 #include <errno.h>
 #ifdef NAMED_BIND
 #include <fcntl.h>
 #include <errno.h>
 #ifdef NAMED_BIND
+#include <sys/param.h>
 #include <arpa/nameser.h>
 #include <resolv.h>
 #endif
 #include <arpa/nameser.h>
 #include <resolv.h>
 #endif
@@ -77,7 +94,7 @@ deliver(e, firstto)
        extern char *remotename();
 
        errno = 0;
        extern char *remotename();
 
        errno = 0;
-       if (!ForceMail && bitset(QDONTSEND|QPSEUDO, to->q_flags))
+       if (bitset(QDONTSEND, to->q_flags))
                return (0);
 
 #ifdef NAMED_BIND
                return (0);
 
 #ifdef NAMED_BIND
@@ -221,7 +238,7 @@ deliver(e, firstto)
                        continue;
 
                /* avoid overflowing tobuf */
                        continue;
 
                /* avoid overflowing tobuf */
-               if (sizeof tobuf - (strlen(to->q_paddr) + strlen(tobuf) + 2) < 0)
+               if (sizeof tobuf < (strlen(to->q_paddr) + strlen(tobuf) + 2))
                        break;
 
                if (tTd(10, 1))
                        break;
 
                if (tTd(10, 1))
@@ -305,6 +322,8 @@ deliver(e, firstto)
                        {
                                rcode = mailfile(user, getctladdr(to));
                                giveresponse(rcode, m, e);
                        {
                                rcode = mailfile(user, getctladdr(to));
                                giveresponse(rcode, m, e);
+                               if (rcode == EX_OK)
+                                       to->q_flags |= QSENT;
                                continue;
                        }
                }
                                continue;
                        }
                }
@@ -371,6 +390,8 @@ deliver(e, firstto)
        **      If we are running SMTP, we just need to clean up.
        */
 
        **      If we are running SMTP, we just need to clean up.
        */
 
+       if (ctladdr == NULL)
+               ctladdr = &e->e_from;
 #ifdef NAMED_BIND
        _res.options &= ~(RES_DEFNAMES | RES_DNSRCH);           /* XXX */
 #endif
 #ifdef NAMED_BIND
        _res.options &= ~(RES_DEFNAMES | RES_DNSRCH);           /* XXX */
 #endif
@@ -428,6 +449,8 @@ deliver(e, firstto)
        else
 #endif /* SMTP */
        {
        else
 #endif /* SMTP */
        {
+               static int sendoff();
+
                message(Arpa_Info, "Connecting to %s (%s)...", host, m->m_name);
                rcode = sendoff(e, m, pv, ctladdr);
        }
                message(Arpa_Info, "Connecting to %s (%s)...", host, m->m_name);
                rcode = sendoff(e, m, pv, ctladdr);
        }
@@ -444,9 +467,11 @@ deliver(e, firstto)
 
        if (tobuf[0] != '\0')
                giveresponse(rcode, m, e);
 
        if (tobuf[0] != '\0')
                giveresponse(rcode, m, e);
-       if (rcode != EX_OK)
-               for (to = tochain; to != NULL; to = to->q_tchain)
+       for (to = tochain; to != NULL; to = to->q_tchain)
+               if (rcode != EX_OK)
                        markfailure(e, to, rcode);
                        markfailure(e, to, rcode);
+               else
+                       to->q_flags |= QSENT;
 
        errno = 0;
        define('g', (char *) NULL, e);
 
        errno = 0;
        define('g', (char *) NULL, e);
@@ -1082,9 +1107,7 @@ logdelivery(stat)
 \f/*
 **  PUTFROMLINE -- output a UNIX-style from line (or whatever)
 **
 \f/*
 **  PUTFROMLINE -- output a UNIX-style from line (or whatever)
 **
-**     then passes the rest of the message through.  If we have
-**     managed to extract a date already, use that; otherwise,
-**     use the current date/time.
+**     This can be made an arbitrary message separator by changing $l
 **
 **     One of the ugliest hacks seen by human eyes is contained herein:
 **     UUCP wants those stupid "remote from <host>" lines.  Why oh why
 **
 **     One of the ugliest hacks seen by human eyes is contained herein:
 **     UUCP wants those stupid "remote from <host>" lines.  Why oh why
@@ -1108,7 +1131,6 @@ putfromline(fp, m)
 {
        char *template = "\001l\n";
        char buf[MAXLINE];
 {
        char *template = "\001l\n";
        char buf[MAXLINE];
-       extern char SentDate[];
 
        if (bitnset(M_NHDR, m->m_flags))
                return;
 
        if (bitnset(M_NHDR, m->m_flags))
                return;
@@ -1344,6 +1366,7 @@ sendall(e, mode)
        register ADDRESS *q;
        bool oldverbose;
        int pid;
        register ADDRESS *q;
        bool oldverbose;
        int pid;
+       int nsent;
        FILE *lockfp = NULL, *queueup();
 
        /* determine actual delivery mode */
        FILE *lockfp = NULL, *queueup();
 
        /* determine actual delivery mode */
@@ -1437,6 +1460,7 @@ sendall(e, mode)
        **  Run through the list and send everything.
        */
 
        **  Run through the list and send everything.
        */
 
+       nsent = 0;
        for (q = e->e_sendqueue; q != NULL; q = q->q_next)
        {
                if (mode == SM_VERIFY)
        for (q = e->e_sendqueue; q != NULL; q = q->q_next)
        {
                if (mode == SM_VERIFY)
@@ -1445,8 +1469,20 @@ sendall(e, mode)
                        if (!bitset(QDONTSEND|QBADADDR, q->q_flags))
                                message(Arpa_Info, "deliverable");
                }
                        if (!bitset(QDONTSEND|QBADADDR, q->q_flags))
                                message(Arpa_Info, "deliverable");
                }
-               else
-                       (void) deliver(e, q);
+               else if (!bitset(QDONTSEND, q->q_flags))
+               {
+                       /*
+                       **  Checkpoint the send list every few addresses
+                       */
+
+                       if (nsent >= CheckpointInterval)
+                       {
+                               queueup(e, TRUE, FALSE);
+                               nsent = 0;
+                       }
+                       if (deliver(e, q) == EX_OK)
+                               nsent++;
+               }
        }
        Verbose = oldverbose;
 
        }
        Verbose = oldverbose;