/etc/securetty is checked, even when root logins across the net.
[unix-history] / usr / src / usr.bin / mail / send.c
index f19b4e3..80b9c5b 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.6 %G%";
+static char *SccsId = "@(#)send.c      2.11 %G%";
 
 /*
  * Send message described by the passed pointer to the
 
 /*
  * Send message described by the passed pointer to the
@@ -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;
@@ -337,7 +342,7 @@ topdog:
 #ifdef pdp11
        while (wait2(&s, WNOHANG) > 0)
 #endif
 #ifdef pdp11
        while (wait2(&s, WNOHANG) > 0)
 #endif
-#ifdef vax
+#if defined(vax) || defined(sun)
        while (wait3(&s, WNOHANG, 0) > 0)
 #endif
                ;
        while (wait3(&s, WNOHANG, 0) > 0)
 #endif
                ;
@@ -363,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)
@@ -378,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)
@@ -488,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);
@@ -504,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);
 }
 
 /*
 }
 
 /*