Send fixed to supress continuation lines in ignored fields.
[unix-history] / usr / src / usr.bin / mail / send.c
index f90993e..1864888 100644 (file)
  * Mail to others.
  */
 
  * Mail to others.
  */
 
-static char *SccsId = "@(#)send.c      1.5 %G%";
+static char *SccsId = "@(#)send.c      2.7 %G%";
 
 /*
  * Send message described by the passed pointer to the
  * passed output buffer.  Return -1 on error, but normally
  * the number of lines written.  Adjust the status: field
 
 /*
  * Send message described by the passed pointer to the
  * passed output buffer.  Return -1 on error, but normally
  * the number of lines written.  Adjust the status: field
- * if need be.
+ * if need be.  If doign is set, suppress ignored header fields.
  */
  */
-
-send(mailp, obuf)
+send(mailp, obuf, doign)
        struct message *mailp;
        FILE *obuf;
 {
        register struct message *mp;
        register int t;
        struct message *mailp;
        FILE *obuf;
 {
        register struct message *mp;
        register int t;
-       unsigned int c;
+       long c;
        FILE *ibuf;
        FILE *ibuf;
-       char line[LINESIZE];
-       int lc, ishead, infld, fline;
+       char line[LINESIZE], field[BUFSIZ];
+       int lc, ishead, infld, fline, dostat;
+       char *cp, *cp2;
 
        mp = mailp;
        ibuf = setinput(mp);
 
        mp = mailp;
        ibuf = setinput(mp);
-       c = msize(mp);
-       ishead = (mailp->m_flag & MSTATUS) != 0;
+       c = mp->m_size;
+       ishead = 1;
+       dostat = 1;
        infld = 0;
        fline = 1;
        lc = 0;
        infld = 0;
        fline = 1;
        lc = 0;
-       while (c > 0) {
+       while (c > 0L) {
                fgets(line, LINESIZE, ibuf);
                fgets(line, LINESIZE, ibuf);
-               c -= strlen(line);
+               c -= (long) strlen(line);
                lc++;
                if (ishead) {
                lc++;
                if (ishead) {
+                       /* 
+                        * First line is the From line, so no headers
+                        * there to worry about
+                        */
                        if (fline) {
                                fline = 0;
                                goto writeit;
                        }
                        if (fline) {
                                fline = 0;
                                goto writeit;
                        }
+                       /*
+                        * If line is blank, we've reached end of
+                        * headers, so force out status: field
+                        * and note that we are no longer in header
+                        * fields
+                        */
                        if (line[0] == '\n') {
                        if (line[0] == '\n') {
-                               statusput(mailp, obuf);
+                               if (dostat) {
+                                       statusput(mailp, obuf, doign);
+                                       dostat = 0;
+                               }
                                ishead = 0;
                                goto writeit;
                        }
                                ishead = 0;
                                goto writeit;
                        }
-                       if (isspace(line[0]) && infld)
+                       /*
+                        * If this line is a continuation (via space or tab)
+                        * of a previous header field, just echo it
+                        * (unless the field should be ignored).
+                        */
+                       if (infld && (isspace(line[0]) || line[0] == '\t')) {
+                               if (doign && isign(field)) continue;
                                goto writeit;
                                goto writeit;
+                       }
                        infld = 0;
                        infld = 0;
+                       /*
+                        * If we are no longer looking at real
+                        * header lines, force out status:
+                        * This happens in uucp style mail where
+                        * there are no headers at all.
+                        */
                        if (!headerp(line)) {
                        if (!headerp(line)) {
-                               statusput(mailp, obuf);
+                               if (dostat) {
+                                       statusput(mailp, obuf, doign);
+                                       dostat = 0;
+                               }
                                putc('\n', obuf);
                                ishead = 0;
                                goto writeit;
                        }
                        infld++;
                                putc('\n', obuf);
                                ishead = 0;
                                goto writeit;
                        }
                        infld++;
-                       if (icisname(line, "status", 6)) {
-                               statusput(mailp, obuf);
-                               ishead = 0;
+                       /*
+                        * Pick up the header field.
+                        * If it is an ignored field and
+                        * we care about such things, skip it.
+                        */
+                       cp = line;
+                       cp2 = field;
+                       while (*cp && *cp != ':' && !isspace(*cp))
+                               *cp2++ = *cp++;
+                       *cp2 = 0;
+                       if (doign && isign(field))
+                               continue;
+                       /*
+                        * If the field is "status," go compute and print the
+                        * real Status: field
+                        */
+                       if (icequal(field, "status")) {
+                               if (dostat) {
+                                       statusput(mailp, obuf, doign);
+                                       dostat = 0;
+                               }
                                continue;
                        }
                }
                                continue;
                        }
                }
@@ -98,14 +146,16 @@ headerp(line)
 
 /*
  * Output a reasonable looking status field.
 
 /*
  * Output a reasonable looking status field.
+ * But if "status" is ignored and doign, forget it.
  */
  */
-
-statusput(mp, obuf)
+statusput(mp, obuf, doign)
        register struct message *mp;
        register FILE *obuf;
 {
        char statout[3];
 
        register struct message *mp;
        register FILE *obuf;
 {
        char statout[3];
 
+       if (doign && isign("status"))
+               return;
        if ((mp->m_flag & (MNEW|MREAD)) == MNEW)
                return;
        if (mp->m_flag & MREAD)
        if ((mp->m_flag & (MNEW|MREAD)) == MNEW)
                return;
        if (mp->m_flag & MREAD)
@@ -187,7 +237,7 @@ mail1(hp)
 {
        register char *cp;
        int pid, i, s, p, gotcha;
 {
        register char *cp;
        int pid, i, s, p, gotcha;
-       char **namelist;
+       char **namelist, *deliver;
        struct name *to, *np;
        FILE *mtf, *postage;
        int remote = rflag != NOSTR || rmail;
        struct name *to, *np;
        FILE *mtf, *postage;
        int remote = rflag != NOSTR || rmail;
@@ -287,7 +337,12 @@ topdog:
         */
 
 #ifdef VMUNIX
         */
 
 #ifdef VMUNIX
+#ifdef pdp11
+       while (wait2(&s, WNOHANG) > 0)
+#endif
+#ifdef vax
        while (wait3(&s, WNOHANG, 0) > 0)
        while (wait3(&s, WNOHANG, 0) > 0)
+#endif
                ;
 #else
        wait(&s);
                ;
 #else
        wait(&s);
@@ -301,6 +356,7 @@ topdog:
                goto out;
        }
        if (pid == 0) {
                goto out;
        }
        if (pid == 0) {
+               sigchild();
 #ifdef SIGTSTP
                if (remote == 0) {
                        sigset(SIGTSTP, SIG_IGN);
 #ifdef SIGTSTP
                if (remote == 0) {
                        sigset(SIGTSTP, SIG_IGN);
@@ -310,7 +366,7 @@ topdog:
 #endif
                for (i = SIGHUP; i <= SIGQUIT; i++)
                        sigset(i, SIG_IGN);
 #endif
                for (i = SIGHUP; i <= SIGQUIT; i++)
                        sigset(i, SIG_IGN);
-               if ((postage = fopen("/crp/kurt/postage", "a")) != NULL) {
+               if ((postage = fopen(POSTAGE, "a")) != NULL) {
                        fprintf(postage, "%s %d %d\n", myname,
                            count(to), fsize(mtf));
                        fclose(postage);
                        fprintf(postage, "%s %d %d\n", myname,
                            count(to), fsize(mtf));
                        fclose(postage);
@@ -326,7 +382,9 @@ topdog:
                submit(getpid());
 #endif CC
 #ifdef DELIVERMAIL
                submit(getpid());
 #endif CC
 #ifdef DELIVERMAIL
-               execv(DELIVERMAIL, namelist);
+               if ((deliver = value("sendmail")) == NOSTR)
+                       deliver = DELIVERMAIL;
+               execv(deliver, namelist);
 #endif DELIVERMAIL
                execv(MAIL, namelist);
                perror(MAIL);
 #endif DELIVERMAIL
                execv(MAIL, namelist);
                perror(MAIL);