new ip statistics
[unix-history] / usr / src / usr.bin / mail / send.c
index b87b841..3a47106 100644 (file)
@@ -5,6 +5,7 @@
 #include <wait.h>
 #endif
 #include <ctype.h>
 #include <wait.h>
 #endif
 #include <ctype.h>
+#include <sys/stat.h>
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
@@ -12,7 +13,7 @@
  * Mail to others.
  */
 
  * Mail to others.
  */
 
-static char *SccsId = "@(#)send.c      2.4 %G%";
+static char *SccsId = "@(#)send.c      2.10 %G%";
 
 /*
  * Send message described by the passed pointer to the
 
 /*
  * Send message described by the passed pointer to the
@@ -26,7 +27,7 @@ send(mailp, obuf, doign)
 {
        register struct message *mp;
        register int t;
 {
        register struct message *mp;
        register int t;
-       unsigned int c;
+       long c;
        FILE *ibuf;
        char line[LINESIZE], field[BUFSIZ];
        int lc, ishead, infld, fline, dostat;
        FILE *ibuf;
        char line[LINESIZE], field[BUFSIZ];
        int lc, ishead, infld, fline, dostat;
@@ -34,15 +35,15 @@ send(mailp, obuf, doign)
 
        mp = mailp;
        ibuf = setinput(mp);
 
        mp = mailp;
        ibuf = setinput(mp);
-       c = msize(mp);
+       c = mp->m_size;
        ishead = 1;
        dostat = 1;
        infld = 0;
        fline = 1;
        lc = 0;
        ishead = 1;
        dostat = 1;
        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) {
                        /* 
@@ -68,11 +69,14 @@ send(mailp, obuf, doign)
                                goto writeit;
                        }
                        /*
                                goto writeit;
                        }
                        /*
-                        * If this line is a continuation
-                        * of a previous header field, just echo it.
+                        * 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 (isspace(line[0]) && infld)
+                       if (infld && (isspace(line[0]) || line[0] == '\t')) {
+                               if (doign && isign(field)) continue;
                                goto writeit;
                                goto writeit;
+                       }
                        infld = 0;
                        /*
                         * If we are no longer looking at real
                        infld = 0;
                        /*
                         * If we are no longer looking at real
@@ -236,6 +240,7 @@ mail1(hp)
        int pid, i, s, p, gotcha;
        char **namelist, *deliver;
        struct name *to, *np;
        int pid, i, s, p, gotcha;
        char **namelist, *deliver;
        struct name *to, *np;
+       struct stat sbuf;
        FILE *mtf, *postage;
        int remote = rflag != NOSTR || rmail;
        char **t;
        FILE *mtf, *postage;
        int remote = rflag != NOSTR || rmail;
        char **t;
@@ -334,7 +339,12 @@ topdog:
         */
 
 #ifdef VMUNIX
         */
 
 #ifdef VMUNIX
+#ifdef pdp11
+       while (wait2(&s, WNOHANG) > 0)
+#endif
+#if defined(vax) || defined(sun)
        while (wait3(&s, WNOHANG, 0) > 0)
        while (wait3(&s, WNOHANG, 0) > 0)
+#endif
                ;
 #else
        wait(&s);
                ;
 #else
        wait(&s);
@@ -358,11 +368,12 @@ 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(POSTAGE, "a")) != NULL) {
-                       fprintf(postage, "%s %d %d\n", myname,
-                           count(to), fsize(mtf));
-                       fclose(postage);
-               }
+               if (!stat(POSTAGE, &sbuf))
+                       if ((postage = fopen(POSTAGE, "a")) != NULL) {
+                               fprintf(postage, "%s %d %d\n", myname,
+                                   count(to), fsize(mtf));
+                               fclose(postage);
+                       }
                s = fileno(mtf);
                for (i = 3; i < 15; i++)
                        if (i != s)
                s = fileno(mtf);
                for (i = 3; i < 15; i++)
                        if (i != s)
@@ -373,18 +384,18 @@ topdog:
 #ifdef CC
                submit(getpid());
 #endif CC
 #ifdef CC
                submit(getpid());
 #endif CC
-#ifdef DELIVERMAIL
+#ifdef SENDMAIL
                if ((deliver = value("sendmail")) == NOSTR)
                if ((deliver = value("sendmail")) == NOSTR)
-                       deliver = DELIVERMAIL;
+                       deliver = SENDMAIL;
                execv(deliver, namelist);
                execv(deliver, namelist);
-#endif DELIVERMAIL
+#endif SENDMAIL
                execv(MAIL, namelist);
                perror(MAIL);
                exit(1);
        }
 
 out:
                execv(MAIL, namelist);
                perror(MAIL);
                exit(1);
        }
 
 out:
-       if (remote) {
+       if (remote || (value("verbose") != NOSTR)) {
                while ((p = wait(&s)) != pid && p != -1)
                        ;
                if (s != 0)
                while ((p = wait(&s)) != pid && p != -1)
                        ;
                if (s != 0)
@@ -483,13 +494,13 @@ puthead(hp, fo, w)
 
        gotcha = 0;
        if (hp->h_to != NOSTR && w & GTO)
 
        gotcha = 0;
        if (hp->h_to != NOSTR && w & GTO)
-               fprintf(fo, "To: "), fmt(hp->h_to, fo), gotcha++;
+               fmt("To: ", hp->h_to, fo), gotcha++;
        if (hp->h_subject != NOSTR && w & GSUBJECT)
                fprintf(fo, "Subject: %s\n", hp->h_subject), gotcha++;
        if (hp->h_cc != NOSTR && w & GCC)
        if (hp->h_subject != NOSTR && w & GSUBJECT)
                fprintf(fo, "Subject: %s\n", hp->h_subject), gotcha++;
        if (hp->h_cc != NOSTR && w & GCC)
-               fprintf(fo, "Cc: "), fmt(hp->h_cc, fo), gotcha++;
+               fmt("Cc: ", hp->h_cc, fo), gotcha++;
        if (hp->h_bcc != NOSTR && w & GBCC)
        if (hp->h_bcc != NOSTR && w & GBCC)
-               fprintf(fo, "Bcc: "), fmt(hp->h_bcc, fo), gotcha++;
+               fmt("Bcc: ", hp->h_bcc, fo), gotcha++;
        if (gotcha && w & GNL)
                putc('\n', fo);
        return(0);
        if (gotcha && w & GNL)
                putc('\n', fo);
        return(0);
@@ -499,26 +510,44 @@ puthead(hp, fo, w)
  * Format the given text to not exceed 72 characters.
  */
 
  * Format the given text to not exceed 72 characters.
  */
 
-fmt(str, fo)
-       register char *str;
+fmt(str, txt, fo)
+       register char *str, *txt;
        register FILE *fo;
 {
        register int col;
        register FILE *fo;
 {
        register int col;
-       register char *cp;
-
-       cp = str;
-       col = 0;
-       while (*cp) {
-               if (*cp == ' ' && col > 65) {
-                       fprintf(fo, "\n    ");
+       register char *bg, *bl, *pt, ch;
+
+       col = strlen(str);
+       if (col)
+               fprintf(fo, "%s", str);
+       pt = bg = txt;
+       bl = 0;
+       while (*bg) {
+               pt++;
+               if (++col >72) {
+                       if (!bl) {
+                               bl = bg;
+                               while (*bl && !isspace(*bl))
+                                       bl++;
+                       }
+                       if (!*bl)
+                               goto finish;
+                       ch = *bl;
+                       *bl = '\0';
+                       fprintf(fo, "%s\n    ", bg);
                        col = 4;
                        col = 4;
-                       cp++;
-                       continue;
+                       *bl = ch;
+                       pt = bg = ++bl;
+                       bl = 0;
+               }
+               if (!*pt) {
+finish:
+                       fprintf(fo, "%s\n", bg);
+                       return;
                }
                }
-               putc(*cp++, fo);
-               col++;
+               if (isspace(*pt))
+                       bl = pt;
        }
        }
-       putc('\n', fo);
 }
 
 /*
 }
 
 /*