static char SccsId
[] = "@(#)collect.c 3.24 %G%";
** COLLECT -- read & parse message header & make temp file.
** Creates a temporary file name and copies the standard
** input to that file. While it is doing it, it looks for
** "From:" and "Sender:" fields to use as the from-person
** (but only if the -a flag is specified). It prefers to
** to use the "Sender:" field.
** MIT seems to like to produce "Sent-By:" fields instead
** of "Sender:" fields. We used to catch this, but it turns
** out that the "Sent-By:" field doesn't always correspond
** to someone real ("___057", for instance), as required by
** the protocol. So we limp by.....
** from -- the person we think it may be from. If
** there is a "From" line, we will replace
** the name of the person by this. If NULL,
** do no such replacement.
** Name of the "from" person extracted from the
** Temp file is created and filled.
** The from person may be set.
long MsgSize
; /* size of message in bytes */
FILE *TempFile
; /* the tempfile (after creation) */
** Create the temp file name and create the file.
(void) mktemp(InFileName
);
(void) close(creat(InFileName
, 0600));
if ((tf
= fopen(InFileName
, "w")) == NULL
)
syserr("Cannot create %s", InFileName
);
** Tell ARPANET to go ahead.
if (ArpaMode
== ARPA_MAIL
)
extern char Arpa_Enter
[];
message(Arpa_Enter
, "Enter mail, end with \".\" on a line by itself");
** Try to read a UNIX-style From line
if (fgets(buf
, sizeof buf
, stdin
) == NULL
)
if (!SaveFrom
&& strncmp(buf
, "From ", 5) == 0)
(void) fgets(buf
, sizeof buf
, stdin
);
** Copy stdin to temp file & do message editting.
** To keep certain mailers from getting confused,
** and to keep the output clean, lines that look
** like UNIX "From" lines are deleted in the header,
** and prepended with ">" in the body.
for (; !feof(stdin
); !feof(stdin
) && fgets(buf
, sizeof buf
, stdin
))
/* see if the header is over */
/* get the rest of this field */
while ((c
= getc(stdin
)) == ' ' || c
== '\t')
if (fgets(p
, sizeof buf
- (p
- buf
), stdin
) == NULL
)
if (bitset(H_EOH
, chompheader(buf
, FALSE
)))
/* throw away a blank line */
(void) fgets(buf
, sizeof buf
, stdin
);
** Collect the body of the message.
for (; !feof(stdin
); !feof(stdin
) && fgets(buf
, sizeof buf
, stdin
) != NULL
)
/* check for end-of-message */
if (!IgnrDot
&& buf
[0] == '.' && (buf
[1] == '\n' || buf
[1] == '\0'))
/* check for transparent dot */
/* Hide UNIX-like From lines */
if (strncmp(bp
, "From ", 5) == 0)
** Figure message length, output the line to the temp
** file, and insert a newline if missing.
(void) freopen(InFileName
, "w", tf
);
fputs("\nMAIL DELETED BECAUSE OF LACK OF DISK SPACE\n\n", tf
);
syserr("collect: Out of disk space for temp file");
syserr("collect: Cannot write %s", InFileName
);
(void) freopen("/dev/null", "w", tf
);
** Find out some information from the headers.
** Examples are who is the from person & the date.
xfrom
= hvalue("sender");
if (ArpaMode
!= ARPA_NONE
)
setfrom(xfrom
, (char *) NULL
);
/* full name of from person */
** Try to extract the full name from a general From:
** field. We take anything which is a comment as a
** first choice. Failing in that, we see if there is
** a "machine readable" name (in <angle brackets>); if
** so we take anything preceeding that clause.
** If we blow it here it's not all that serious.
p
= hvalue("original-from");
for (p
= q
; *p
!= '\0'; p
++)
else if (*p
== ')' && --parenlev
<= 0)
else if ((q
= index(p
, '<')) != NULL
)
/* date message originated */
p
= hvalue("posted-date");
/* we don't have a good way to do canonical conversion ....
define('d', newstr(arpatounix(p)));
.... so we will ignore the problem for the time being */
if ((TempFile
= fopen(InFileName
, "r")) == NULL
)
syserr("Cannot reopen %s", InFileName
);
extern char *capitalize();
printf("----- collected header -----\n");
for (h
= Header
; h
!= NULL
; h
= h
->h_link
)
printf("%s: %s\n", capitalize(h
->h_field
), h
->h_value
);
printf("----------------------------\n");
** EATFROM -- chew up a UNIX style from line and process
** This does indeed make some assumptions about the format
** extracts what information it can from the header,
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
printf("eatfrom(%s)\n", fm
);
while (*p
!= '\0' && *p
!= ' ')
if (!isupper(*p
) || p
[3] != ' ' || p
[13] != ':' || p
[16] != ':')
/* we have a possible date */
for (dt
= DowList
; *dt
!= NULL
; dt
++)
if (strncmp(*dt
, p
, 3) == 0)
for (dt
= MonthList
; *dt
!= NULL
; dt
++)
if (strncmp(*dt
, &p
[4], 3) == 0)
/* we have found a date */