projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
hash() could return negative values.
[unix-history]
/
usr
/
src
/
usr.bin
/
mail
/
send.c
diff --git
a/usr/src/usr.bin/mail/send.c
b/usr/src/usr.bin/mail/send.c
index
54c128b
..
7cfae0e
100644
(file)
--- a/
usr/src/usr.bin/mail/send.c
+++ b/
usr/src/usr.bin/mail/send.c
@@
-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.
3
%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
@@
-20,14
+21,13
@@
static char *SccsId = "@(#)send.c 2.3 %G%";
* the number of lines written. Adjust the status: field
* if need be. If doign is set, suppress ignored header fields.
*/
* the number of lines written. Adjust the status: field
* if need be. If doign is set, suppress ignored header fields.
*/
-
send(mailp, obuf, doign)
struct message *mailp;
FILE *obuf;
{
register struct message *mp;
register int t;
send(mailp, obuf, doign)
struct message *mailp;
FILE *obuf;
{
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;
@@
-35,15
+35,15
@@
send(mailp, obuf, doign)
mp = mailp;
ibuf = setinput(mp);
mp = mailp;
ibuf = setinput(mp);
- c = m
size(mp)
;
+ c = m
p->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 > 0
L
) {
fgets(line, LINESIZE, ibuf);
fgets(line, LINESIZE, ibuf);
- c -= strlen(line);
+ c -=
(long)
strlen(line);
lc++;
if (ishead) {
/*
lc++;
if (ishead) {
/*
@@
-69,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
@@
-91,18
+94,6
@@
send(mailp, obuf, doign)
goto writeit;
}
infld++;
goto writeit;
}
infld++;
- /*
- * We are looking at a header line.
- * See if it is the status: field,
- * and if it is, print the real status: field
- */
- if (icisname(line, "status", 6)) {
- if (dostat) {
- statusput(mailp, obuf, doign);
- dostat = 0;
- }
- continue;
- }
/*
* Pick up the header field.
* If it is an ignored field and
/*
* Pick up the header field.
* If it is an ignored field and
@@
-115,6
+106,17
@@
send(mailp, obuf, doign)
*cp2 = 0;
if (doign && isign(field))
continue;
*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;
+ }
}
writeit:
fputs(line, obuf);
}
writeit:
fputs(line, obuf);
@@
-238,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;
@@
-253,10
+256,6
@@
mail1(hp)
hp->h_seq = 1;
if (hp->h_subject == NOSTR)
hp->h_subject = sflag;
hp->h_seq = 1;
if (hp->h_subject == NOSTR)
hp->h_subject = sflag;
- if (fsize(mtf) == 0 && hp->h_subject == NOSTR) {
- printf("No message !?!\n");
- goto out;
- }
if (intty && value("askcc") != NOSTR)
grabh(hp, GCC);
else if (intty) {
if (intty && value("askcc") != NOSTR)
grabh(hp, GCC);
else if (intty) {
@@
-309,6
+308,9
@@
topdog:
if (hp->h_seq > 0 && !remote) {
fixhead(hp, to);
if (fsize(mtf) == 0)
if (hp->h_seq > 0 && !remote) {
fixhead(hp, to);
if (fsize(mtf) == 0)
+ if (hp->h_subject == NOSTR)
+ printf("No message, no subject; hope that's ok\n");
+ else
printf("Null message body; hope that's ok\n");
if ((mtf = infix(hp, mtf)) == NULL) {
fprintf(stderr, ". . . message lost, sorry.\n");
printf("Null message body; hope that's ok\n");
if ((mtf = infix(hp, mtf)) == NULL) {
fprintf(stderr, ". . . message lost, sorry.\n");
@@
-336,7
+338,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);
@@
-360,11
+367,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)
@@
-375,18
+383,18
@@
topdog:
#ifdef CC
submit(getpid());
#endif CC
#ifdef CC
submit(getpid());
#endif CC
-#ifdef
DELIVER
MAIL
+#ifdef
SEND
MAIL
if ((deliver = value("sendmail")) == NOSTR)
if ((deliver = value("sendmail")) == NOSTR)
- deliver =
DELIVER
MAIL;
+ deliver =
SEND
MAIL;
execv(deliver, namelist);
execv(deliver, namelist);
-#endif
DELIVER
MAIL
+#endif
SEND
MAIL
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)
@@
-485,13
+493,13
@@
puthead(hp, fo, w)
gotcha = 0;
if (hp->h_to != NOSTR && w & GTO)
gotcha = 0;
if (hp->h_to != NOSTR && w & GTO)
- f
printf(fo, "To: "), fmt(
hp->h_to, fo), gotcha++;
+ f
mt("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)
- f
printf(fo, "Cc: "), fmt(
hp->h_cc, fo), gotcha++;
+ f
mt("Cc: ",
hp->h_cc, fo), gotcha++;
if (hp->h_bcc != NOSTR && w & GBCC)
if (hp->h_bcc != NOSTR && w & GBCC)
- f
printf(fo, "Bcc: "), fmt(
hp->h_bcc, fo), gotcha++;
+ f
mt("Bcc: ",
hp->h_bcc, fo), gotcha++;
if (gotcha && w & GNL)
putc('\n', fo);
return(0);
if (gotcha && w & GNL)
putc('\n', fo);
return(0);
@@
-501,26
+509,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);
}
/*
}
/*