diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-01-16 05:36:10 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-01-16 05:36:10 +0000 |
commit | e913afeb49c504a109e4bb5f0bbc7413c1f2b7d4 (patch) | |
tree | e3f06532bf64681e08848aa1e0b3fd00383cc11d /usr.bin/mail/send.c | |
parent | 86370b96c590d4c80af75091f9238d13ab88f77f (diff) |
Changes from Don Beusee:
o escape From line with a leading '>' when needed
o only print To: address and Subject lines if actually present
o new variable 'allnet' to treat user@foo and user@bar as the same "user"
o folders command now takes an optional argument like ls.
o new "pipe" (|) command to pipe the message through an arbitrary command
o make header display format the same as SunOS 4.1.3 /usr/ucb/mail
o tilde commands work regardless of interactive mode.
o fix "read: Interrupted system call" error by retrying if EINTR
o expanded help file
Changes by me:
o read the help file via the PAGER as it is now more than 24 lines long
Diffstat (limited to 'usr.bin/mail/send.c')
-rw-r--r-- | usr.bin/mail/send.c | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/usr.bin/mail/send.c b/usr.bin/mail/send.c index 26d048669e5..0c0685427bb 100644 --- a/usr.bin/mail/send.c +++ b/usr.bin/mail/send.c @@ -1,4 +1,4 @@ -/* $OpenBSD: send.c,v 1.12 2000/08/23 21:24:08 mickey Exp $ */ +/* $OpenBSD: send.c,v 1.13 2001/01/16 05:36:09 millert Exp $ */ /* $NetBSD: send.c,v 1.6 1996/06/08 19:48:39 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)send.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: send.c,v 1.12 2000/08/23 21:24:08 mickey Exp $"; +static char rcsid[] = "$OpenBSD: send.c,v 1.13 2001/01/16 05:36:09 millert Exp $"; #endif #endif /* not lint */ @@ -179,12 +179,13 @@ sendmessage(mp, obuf, doign, prefix) * Strip trailing whitespace from prefix * if line is blank. */ - if (prefix != NULL) + if (prefix != NULL) { if (length > 1) fputs(prefix, obuf); else (void)fwrite(prefix, sizeof(*prefix), prefixlen, obuf); + } (void)fwrite(line, sizeof(*line), length, obuf); if (ferror(obuf)) return(-1); @@ -195,13 +196,13 @@ sendmessage(mp, obuf, doign, prefix) */ if (doign == ignoreall) count--; /* skip final blank line */ - if (prefix != NULL) - while (count > 0) { - if (fgets(line, sizeof(line), ibuf) == NULL) { - c = 0; - break; - } - count -= c = strlen(line); + while (count > 0) { + if (fgets(line, sizeof(line), ibuf) == NULL) { + c = 0; + break; + } + count -= c = strlen(line); + if (prefix != NULL) { /* * Strip trailing whitespace from prefix * if line is blank. @@ -211,19 +212,19 @@ sendmessage(mp, obuf, doign, prefix) else (void)fwrite(prefix, sizeof(*prefix), prefixlen, obuf); - (void)fwrite(line, sizeof(*line), c, obuf); - if (ferror(obuf)) - return(-1); - } - else - while (count > 0) { - c = count < LINESIZE ? count : LINESIZE; - if ((c = fread(line, sizeof(*line), c, ibuf)) <= 0) - break; - count -= c; - if (fwrite(line, sizeof(*line), c, obuf) != c) - return(-1); } + /* + * We can't read the record file (or inbox for recipient) + * properly with 'From ' lines in the message body (from + * forwarded messages or sentences starting with "From "), + * so we will prepend those lines with a '>'. + */ + if (strncmp(line, "From ", 5) == 0) + (void)fwrite(">", 1, 1, obuf); /* '>' before 'From ' */ + (void)fwrite(line, sizeof(*line), c, obuf); + if (ferror(obuf)) + return(-1); + } if (doign == ignoreall && c > 0 && line[c - 1] != '\n') /* no final blank line */ if ((c = getc(ibuf)) != EOF && putc(c, obuf) == EOF) @@ -315,11 +316,12 @@ mail1(hp, printheaders) */ if ((mtf = collect(hp, printheaders)) == NULL) return; - if (fsize(mtf) == 0) + if (fsize(mtf) == 0) { if (hp->h_subject == NULL) puts("No message, no subject; hope that's ok"); else puts("Null message body; hope that's ok"); + } /* * Now, take the user names from the combined * to and cc lists and do all the alias @@ -546,7 +548,6 @@ savemail(name, fi) { FILE *fo; char buf[BUFSIZ]; - int i; time_t now; if ((fo = Fopen(name, "a")) == NULL) { @@ -555,8 +556,17 @@ savemail(name, fi) } (void)time(&now); fprintf(fo, "From %s %s", myname, ctime(&now)); - while ((i = fread(buf, 1, sizeof(buf), fi)) > 0) - (void)fwrite(buf, 1, i, fo); + while (fgets(buf, sizeof(buf), fi) == buf) { + /* + * We can't read the record file (or inbox for recipient) + * in the message body (from forwarded messages or sentences + * starting with "From "), so we will prepend those lines with + * a '>'. + */ + if (strncmp(buf, "From ", 5) == 0) + (void)fwrite(">", 1, 1, fo); /* '>' before 'From ' */ + (void)fwrite(buf, 1, strlen(buf), fo); + } (void)putc('\n', fo); (void)fflush(fo); if (ferror(fo)) |