added call to inithost() if GETHOST is defined
[unix-history] / usr / src / usr.bin / mail / send.c
index 9d09448..b87b841 100644 (file)
@@ -4,6 +4,7 @@
 #ifdef VMUNIX
 #include <wait.h>
 #endif
 #ifdef VMUNIX
 #include <wait.h>
 #endif
+#include <ctype.h>
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
  * Mail to others.
  */
 
  * Mail to others.
  */
 
-static char *SccsId = "@(#)send.c      1.2 %G%";
+static char *SccsId = "@(#)send.c      2.4 %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;
 {
        struct message *mailp;
        FILE *obuf;
 {
@@ -28,29 +28,89 @@ send(mailp, obuf)
        register int t;
        unsigned int c;
        FILE *ibuf;
        register int t;
        unsigned int c;
        FILE *ibuf;
-       char line[LINESIZE];
-       int lc, ishead;
+       char line[LINESIZE], field[BUFSIZ];
+       int lc, ishead, infld, fline, dostat;
+       char *cp, *cp2;
 
        mp = mailp;
        ibuf = setinput(mp);
        c = msize(mp);
 
        mp = mailp;
        ibuf = setinput(mp);
        c = msize(mp);
-       ishead = (mailp->m_flag & MSTATUS) != 0;
+       ishead = 1;
+       dostat = 1;
+       infld = 0;
+       fline = 1;
        lc = 0;
        while (c > 0) {
                fgets(line, LINESIZE, ibuf);
                c -= strlen(line);
                lc++;
                if (ishead) {
        lc = 0;
        while (c > 0) {
                fgets(line, LINESIZE, ibuf);
                c -= strlen(line);
                lc++;
                if (ishead) {
+                       /* 
+                        * First line is the From line, so no headers
+                        * there to worry about
+                        */
+                       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 (index(line, ':') == 0)
+                       /*
+                        * If this line is a continuation
+                        * of a previous header field, just echo it.
+                        */
+                       if (isspace(line[0]) && infld)
                                goto writeit;
                                goto writeit;
-                       if (icisname(line, "status", 6)) {
-                               statusput(mailp, obuf);
+                       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 (dostat) {
+                                       statusput(mailp, obuf, doign);
+                                       dostat = 0;
+                               }
+                               putc('\n', obuf);
                                ishead = 0;
                                ishead = 0;
+                               goto writeit;
+                       }
+                       infld++;
+                       /*
+                        * 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;
                        }
                }
@@ -67,15 +127,32 @@ writeit:
 }
 
 /*
 }
 
 /*
- * Output a reasonable looking status field.
+ * Test if the passed line is a header line, RFC 733 style.
  */
  */
+headerp(line)
+       register char *line;
+{
+       register char *cp = line;
 
 
-statusput(mp, obuf)
+       while (*cp && !isspace(*cp) && *cp != ':')
+               cp++;
+       while (*cp && isspace(*cp))
+               cp++;
+       return(*cp == ':');
+}
+
+/*
+ * Output a reasonable looking status field.
+ * But if "status" is ignored and doign, forget it.
+ */
+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)
@@ -157,7 +234,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;
@@ -271,16 +348,17 @@ topdog:
                goto out;
        }
        if (pid == 0) {
                goto out;
        }
        if (pid == 0) {
+               sigchild();
 #ifdef SIGTSTP
                if (remote == 0) {
 #ifdef SIGTSTP
                if (remote == 0) {
-                       signal(SIGTSTP, SIG_IGN);
-                       signal(SIGTTIN, SIG_IGN);
-                       signal(SIGTTOU, SIG_IGN);
+                       sigset(SIGTSTP, SIG_IGN);
+                       sigset(SIGTTIN, SIG_IGN);
+                       sigset(SIGTTOU, SIG_IGN);
                }
 #endif
                for (i = SIGHUP; i <= SIGQUIT; i++)
                }
 #endif
                for (i = SIGHUP; i <= SIGQUIT; i++)
-                       signal(i, SIG_IGN);
-               if ((postage = fopen("/crp/kurt/postage", "a")) != NULL) {
+                       sigset(i, SIG_IGN);
+               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);
@@ -296,7 +374,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);
@@ -356,6 +436,7 @@ infix(hp, fi)
        register FILE *nfo, *nfi;
        register int c;
 
        register FILE *nfo, *nfi;
        register int c;
 
+       rewind(fi);
        if ((nfo = fopen(tempMail, "w")) == NULL) {
                perror(tempMail);
                return(fi);
        if ((nfo = fopen(tempMail, "w")) == NULL) {
                perror(tempMail);
                return(fi);
@@ -367,7 +448,6 @@ infix(hp, fi)
        }
        remove(tempMail);
        puthead(hp, nfo, GTO|GSUBJECT|GCC|GNL);
        }
        remove(tempMail);
        puthead(hp, nfo, GTO|GSUBJECT|GCC|GNL);
-       rewind(fi);
        c = getc(fi);
        while (c != EOF) {
                putc(c, nfo);
        c = getc(fi);
        while (c != EOF) {
                putc(c, nfo);
@@ -375,7 +455,6 @@ infix(hp, fi)
        }
        if (ferror(fi)) {
                perror("read");
        }
        if (ferror(fi)) {
                perror("read");
-               fprintf(stderr, "Please notify Kurt Shoens\n");
                return(fi);
        }
        fflush(nfo);
                return(fi);
        }
        fflush(nfo);