check for "<<>>" etc as equivalent to "<>"
[unix-history] / usr / src / usr.sbin / sendmail / src / envelope.c
index 482f821..f8e09e7 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)envelope.c 8.36 (Berkeley) %G%";
+static char sccsid[] = "@(#)envelope.c 8.43 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -74,9 +74,11 @@ dropenvelope(e)
        register ENVELOPE *e;
 {
        bool queueit = FALSE;
        register ENVELOPE *e;
 {
        bool queueit = FALSE;
-       bool saveit = bitset(EF_FATALERRS, e->e_flags);
+       bool failure_return = FALSE;
+       bool success_return = FALSE;
        register ADDRESS *q;
        char *id = e->e_id;
        register ADDRESS *q;
        char *id = e->e_id;
+       bool return_no, return_yes;
        char buf[MAXLINE];
 
        if (tTd(50, 1))
        char buf[MAXLINE];
 
        if (tTd(50, 1))
@@ -112,19 +114,45 @@ dropenvelope(e)
        */
 
        e->e_flags &= ~EF_QUEUERUN;
        */
 
        e->e_flags &= ~EF_QUEUERUN;
+       return_no = return_yes = FALSE;
        for (q = e->e_sendqueue; q != NULL; q = q->q_next)
        {
                if (bitset(QQUEUEUP, q->q_flags))
                        queueit = TRUE;
        for (q = e->e_sendqueue; q != NULL; q = q->q_next)
        {
                if (bitset(QQUEUEUP, q->q_flags))
                        queueit = TRUE;
-               if (!bitset(QDONTSEND, q->q_flags) &&
-                   bitset(QBADADDR, q->q_flags))
+
+               /* see if a notification is needed */
+               if (bitset(QBADADDR, q->q_flags) &&
+                   bitset(QPINGONFAILURE, q->q_flags))
                {
                {
-                       if (q->q_owner == NULL &&
-                           strcmp(e->e_from.q_paddr, "<>") != 0)
+                       failure_return = TRUE;
+                       if (q->q_owner == NULL && !emptyaddr(&e->e_from))
                                (void) sendtolist(e->e_from.q_paddr, NULL,
                                                  &e->e_errorqueue, e);
                }
                                (void) sendtolist(e->e_from.q_paddr, NULL,
                                                  &e->e_errorqueue, e);
                }
+               else if (bitset(QSENT, q->q_flags) &&
+                   bitnset(M_LOCALMAILER, q->q_mailer->m_flags) &&
+                   bitset(QPINGONSUCCESS, q->q_flags))
+               {
+                       success_return = TRUE;
+               }
+               else
+                       continue;
+
+               /* common code for error returns and return receipts */
+
+               /* test for returning the body */
+               if (!bitset(QHASRETPARAM, q->q_flags))
+               {
+                       if (!bitset(EF_NORETURN, e->e_flags))
+                               return_yes = TRUE;
+               }
+               else if (bitset(QNOBODYRETURN, q->q_flags))
+                       return_no = TRUE;
+               else
+                       return_yes = TRUE;
        }
        }
+       if (return_no && !return_yes)
+               e->e_flags |= EF_NORETURN;
 
        /*
        **  See if the message timed out.
 
        /*
        **  See if the message timed out.
@@ -132,18 +160,18 @@ dropenvelope(e)
 
        if (!queueit)
                /* nothing to do */ ;
 
        if (!queueit)
                /* nothing to do */ ;
-       else if (curtime() > e->e_ctime + TimeOuts.to_q_return)
+       else if (curtime() > e->e_ctime + TimeOuts.to_q_return[e->e_timeoutclass])
        {
                (void) sprintf(buf, "Cannot send message for %s",
        {
                (void) sprintf(buf, "Cannot send message for %s",
-                       pintvl(TimeOuts.to_q_return, FALSE));
+                       pintvl(TimeOuts.to_q_return[e->e_timeoutclass], FALSE));
                if (e->e_message != NULL)
                        free(e->e_message);
                e->e_message = newstr(buf);
                message(buf);
                e->e_flags |= EF_CLRQUEUE;
                if (e->e_message != NULL)
                        free(e->e_message);
                e->e_message = newstr(buf);
                message(buf);
                e->e_flags |= EF_CLRQUEUE;
-               saveit = TRUE;
+               failure_return = TRUE;
                fprintf(e->e_xfp, "Message could not be delivered for %s\n",
                fprintf(e->e_xfp, "Message could not be delivered for %s\n",
-                       pintvl(TimeOuts.to_q_return, FALSE));
+                       pintvl(TimeOuts.to_q_return[e->e_timeoutclass], FALSE));
                fprintf(e->e_xfp, "Message will be deleted from queue\n");
                for (q = e->e_sendqueue; q != NULL; q = q->q_next)
                {
                fprintf(e->e_xfp, "Message will be deleted from queue\n");
                for (q = e->e_sendqueue; q != NULL; q = q->q_next)
                {
@@ -151,28 +179,31 @@ dropenvelope(e)
                                q->q_flags |= QBADADDR;
                }
        }
                                q->q_flags |= QBADADDR;
                }
        }
-       else if (TimeOuts.to_q_warning > 0 &&
-           curtime() > e->e_ctime + TimeOuts.to_q_warning)
+       else if (TimeOuts.to_q_warning[e->e_timeoutclass] > 0 &&
+           curtime() > e->e_ctime + TimeOuts.to_q_warning[e->e_timeoutclass])
        {
                if (!bitset(EF_WARNING|EF_RESPONSE, e->e_flags) &&
                    e->e_class >= 0 &&
        {
                if (!bitset(EF_WARNING|EF_RESPONSE, e->e_flags) &&
                    e->e_class >= 0 &&
-                   strcmp(e->e_from.q_paddr, "<>") != 0)
+                   strcmp(e->e_from.q_paddr, "<>") != 0 &&
+                   strncasecmp(e->e_from.q_paddr, "owner-", 6) != 0 &&
+                   (strlen(e->e_from.q_paddr) <= 8 ||
+                    strcasecmp(&e->e_from.q_paddr[strlen(e->e_from.q_paddr) - 8], "-request") != 0))
                {
                        (void) sprintf(buf,
                                "Warning: cannot send message for %s",
                {
                        (void) sprintf(buf,
                                "Warning: cannot send message for %s",
-                               pintvl(TimeOuts.to_q_warning, FALSE));
+                               pintvl(TimeOuts.to_q_warning[e->e_timeoutclass], FALSE));
                        if (e->e_message != NULL)
                                free(e->e_message);
                        e->e_message = newstr(buf);
                        message(buf);
                        e->e_flags |= EF_WARNING;
                        if (e->e_message != NULL)
                                free(e->e_message);
                        e->e_message = newstr(buf);
                        message(buf);
                        e->e_flags |= EF_WARNING;
-                       saveit = TRUE;
+                       failure_return = TRUE;
                }
                fprintf(e->e_xfp,
                        "Warning: message still undelivered after %s\n",
                }
                fprintf(e->e_xfp,
                        "Warning: message still undelivered after %s\n",
-                       pintvl(TimeOuts.to_q_warning, FALSE));
+                       pintvl(TimeOuts.to_q_warning[e->e_timeoutclass], FALSE));
                fprintf(e->e_xfp, "Will keep trying until message is %s old\n",
                fprintf(e->e_xfp, "Will keep trying until message is %s old\n",
-                       pintvl(TimeOuts.to_q_return, FALSE));
+                       pintvl(TimeOuts.to_q_return[e->e_timeoutclass], FALSE));
                for (q = e->e_sendqueue; q != NULL; q = q->q_next)
                {
                        if (bitset(QQUEUEUP, q->q_flags))
                for (q = e->e_sendqueue; q != NULL; q = q->q_next)
                {
                        if (bitset(QQUEUEUP, q->q_flags))
@@ -180,25 +211,35 @@ dropenvelope(e)
                }
        }
 
                }
        }
 
+       if (tTd(50, 2))
+               printf("failure_return=%d success_return=%d queueit=%d\n",
+                       failure_return, success_return, queueit);
+
        /*
        **  Send back return receipts as requested.
        */
 
        /*
        **  Send back return receipts as requested.
        */
 
+/*
        if (e->e_receiptto != NULL && bitset(EF_SENDRECEIPT, e->e_flags)
            && !bitset(PRIV_NORECEIPTS, PrivacyFlags))
        if (e->e_receiptto != NULL && bitset(EF_SENDRECEIPT, e->e_flags)
            && !bitset(PRIV_NORECEIPTS, PrivacyFlags))
+*/
+       if (e->e_receiptto == NULL)
+               e->e_receiptto = e->e_from.q_paddr;
+       if (success_return && strcmp(e->e_receiptto, "<>") != 0)
        {
                auto ADDRESS *rlist = NULL;
 
        {
                auto ADDRESS *rlist = NULL;
 
+               e->e_flags |= EF_SENDRECEIPT;
                (void) sendtolist(e->e_receiptto, NULLADDR, &rlist, e);
                (void) returntosender("Return receipt", rlist, FALSE, e);
                (void) sendtolist(e->e_receiptto, NULLADDR, &rlist, e);
                (void) returntosender("Return receipt", rlist, FALSE, e);
-               e->e_flags &= ~EF_SENDRECEIPT;
        }
        }
+       e->e_flags &= ~EF_SENDRECEIPT;
 
        /*
        **  Arrange to send error messages if there are fatal errors.
        */
 
 
        /*
        **  Arrange to send error messages if there are fatal errors.
        */
 
-       if (saveit && e->e_errormode != EM_QUIET)
+       if (failure_return && e->e_errormode != EM_QUIET)
                savemail(e);
 
        /*
                savemail(e);
 
        /*
@@ -222,7 +263,8 @@ dropenvelope(e)
            bitset(EF_CLRQUEUE, e->e_flags))
        {
                if (tTd(50, 1))
            bitset(EF_CLRQUEUE, e->e_flags))
        {
                if (tTd(50, 1))
-                       printf("\n===== Dropping [dq]f%s =====\n\n", e->e_id);
+                       printf("\n===== Dropping [dq]f%s (queueit=%d, e_flags=%x) =====\n\n",
+                               e->e_id, queueit, e->e_flags);
                if (e->e_df != NULL)
                        xunlink(e->e_df);
                xunlink(queuename(e, 'q'));
                if (e->e_df != NULL)
                        xunlink(e->e_df);
                xunlink(queuename(e, 'q'));
@@ -632,34 +674,27 @@ setsender(from, e, delimptr, internal)
        }
        SuprErrs = FALSE;
 
        }
        SuprErrs = FALSE;
 
-       pvp = NULL;
+# ifdef USERDB
        if (bitnset(M_CHECKUDB, e->e_from.q_mailer->m_flags))
        {
        if (bitnset(M_CHECKUDB, e->e_from.q_mailer->m_flags))
        {
-# ifdef USERDB
                register char *p;
                extern char *udbsender();
                register char *p;
                extern char *udbsender();
-# endif
 
 
+               p = udbsender(e->e_from.q_user);
+               if (p != NULL)
+                       from = p;
+       }
+# endif /* USERDB */
+
+       if (bitnset(M_HASPWENT, e->e_from.q_mailer->m_flags))
+       {
                if (!internal)
                {
                if (!internal)
                {
-                       /* if the user has given fullname already, don't redefine */
+                       /* if the user already given fullname don't redefine */
                        if (FullName == NULL)
                                FullName = macvalue('x', e);
                        if (FullName != NULL && FullName[0] == '\0')
                                FullName = NULL;
                        if (FullName == NULL)
                                FullName = macvalue('x', e);
                        if (FullName != NULL && FullName[0] == '\0')
                                FullName = NULL;
-
-# ifdef USERDB
-                       p = udbsender(e->e_from.q_user);
-
-                       if (p != NULL)
-                       {
-                               /*
-                               **  We have an alternate address for the sender
-                               */
-
-                               pvp = prescan(p, '\0', pvpbuf, sizeof pvpbuf, NULL);
-                       }
-# endif /* USERDB */
                }
 
                if ((pw = getpwnam(e->e_from.q_user)) != NULL)
                }
 
                if ((pw = getpwnam(e->e_from.q_user)) != NULL)
@@ -714,8 +749,7 @@ setsender(from, e, delimptr, internal)
        **      links in the net.
        */
 
        **      links in the net.
        */
 
-       if (pvp == NULL)
-               pvp = prescan(from, delimchar, pvpbuf, sizeof pvpbuf, NULL);
+       pvp = prescan(from, delimchar, pvpbuf, sizeof pvpbuf, NULL);
        if (pvp == NULL)
        {
                /* don't need to give error -- prescan did that already */
        if (pvp == NULL)
        {
                /* don't need to give error -- prescan did that already */
@@ -725,12 +759,14 @@ setsender(from, e, delimptr, internal)
 # endif
                finis();
        }
 # endif
                finis();
        }
+/*
        (void) rewrite(pvp, 3, 0, e);
        (void) rewrite(pvp, 1, 0, e);
        (void) rewrite(pvp, 4, 0, e);
        (void) rewrite(pvp, 3, 0, e);
        (void) rewrite(pvp, 1, 0, e);
        (void) rewrite(pvp, 4, 0, e);
+*/
        bp = buf + 1;
        cataddr(pvp, NULL, bp, sizeof buf - 2, '\0');
        bp = buf + 1;
        cataddr(pvp, NULL, bp, sizeof buf - 2, '\0');
-       if (*bp == '@')
+       if (*bp == '@' && !bitnset(M_NOBRACKET, e->e_from.q_mailer->m_flags))
        {
                /* heuristic: route-addr: add angle brackets */
                strcat(bp, ">");
        {
                /* heuristic: route-addr: add angle brackets */
                strcat(bp, ">");