added in nifty changes from branch to make easier to compile
[unix-history] / usr / src / usr.bin / mail / send.c
index 9d09448..7786349 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
@@ -11,7 +12,7 @@
  * Mail to others.
  */
 
  * Mail to others.
  */
 
-static char *SccsId = "@(#)send.c      1.2 %G%";
+static char *SccsId = "@(#)send.c      2.1 %G%";
 
 /*
  * Send message described by the passed pointer to the
 
 /*
  * Send message described by the passed pointer to the
@@ -29,25 +30,39 @@ send(mailp, obuf)
        unsigned int c;
        FILE *ibuf;
        char line[LINESIZE];
        unsigned int c;
        FILE *ibuf;
        char line[LINESIZE];
-       int lc, ishead;
+       int lc, ishead, infld, fline;
 
        mp = mailp;
        ibuf = setinput(mp);
        c = msize(mp);
        ishead = (mailp->m_flag & MSTATUS) != 0;
 
        mp = mailp;
        ibuf = setinput(mp);
        c = msize(mp);
        ishead = (mailp->m_flag & MSTATUS) != 0;
+       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) {
+                       if (fline) {
+                               fline = 0;
+                               goto writeit;
+                       }
                        if (line[0] == '\n') {
                                statusput(mailp, obuf);
                                ishead = 0;
                                goto writeit;
                        }
                        if (line[0] == '\n') {
                                statusput(mailp, obuf);
                                ishead = 0;
                                goto writeit;
                        }
-                       if (index(line, ':') == 0)
+                       if (isspace(line[0]) && infld)
                                goto writeit;
                                goto writeit;
+                       infld = 0;
+                       if (!headerp(line)) {
+                               statusput(mailp, obuf);
+                               putc('\n', obuf);
+                               ishead = 0;
+                               goto writeit;
+                       }
+                       infld++;
                        if (icisname(line, "status", 6)) {
                                statusput(mailp, obuf);
                                ishead = 0;
                        if (icisname(line, "status", 6)) {
                                statusput(mailp, obuf);
                                ishead = 0;
@@ -66,6 +81,21 @@ writeit:
        return(lc);
 }
 
        return(lc);
 }
 
+/*
+ * Test if the passed line is a header line, RFC 733 style.
+ */
+headerp(line)
+       register char *line;
+{
+       register char *cp = line;
+
+       while (*cp && !isspace(*cp) && *cp != ':')
+               cp++;
+       while (*cp && isspace(*cp))
+               cp++;
+       return(*cp == ':');
+}
+
 /*
  * Output a reasonable looking status field.
  */
 /*
  * Output a reasonable looking status field.
  */
@@ -157,7 +187,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;
@@ -273,13 +303,13 @@ topdog:
        if (pid == 0) {
 #ifdef SIGTSTP
                if (remote == 0) {
        if (pid == 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);
+                       sigset(i, SIG_IGN);
                if ((postage = fopen("/crp/kurt/postage", "a")) != NULL) {
                        fprintf(postage, "%s %d %d\n", myname,
                            count(to), fsize(mtf));
                if ((postage = fopen("/crp/kurt/postage", "a")) != NULL) {
                        fprintf(postage, "%s %d %d\n", myname,
                            count(to), fsize(mtf));
@@ -296,7 +326,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 +388,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 +400,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 +407,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);