static char *SccsId
= "@(#)send.c 1.3 %G%";
* Send message described by the passed pointer to the
* passed output buffer. Return -1 on error, but normally
* the number of lines written. Adjust the status: field
register struct message
*mp
;
ishead
= (mailp
->m_flag
& MSTATUS
) != 0;
fgets(line
, LINESIZE
, ibuf
);
if (index(line
, ':') == 0)
if (icisname(line
, "status", 6)) {
if (ishead
&& (mailp
->m_flag
& MSTATUS
))
printf("failed to fix up status field\n");
* Output a reasonable looking status field.
register struct message
*mp
;
if ((mp
->m_flag
& (MNEW
|MREAD
)) == MNEW
)
if ((mp
->m_flag
& MNEW
) == 0)
fprintf(obuf
, "Status: %s\n", statout
);
* Interface between the argument list and the mail1 routine
* which does all the dirty work.
for (s
= 0, ap
= people
; *ap
!= (char *) -1; ap
++)
for (ap
= people
; *ap
!= (char *) -1; ap
++) {
* Send mail to a bunch of user names. The interface is through
* the mail routine below.
* Mail a message on standard input to the people indicated
* in the passed header. (Internal interface).
int pid
, i
, s
, p
, gotcha
;
int remote
= rflag
!= NOSTR
|| rmail
;
* Collect user's mail from standard input.
if ((mtf
= collect(hp
)) == NULL
)
if (hp
->h_subject
== NOSTR
)
if (fsize(mtf
) == 0 && hp
->h_subject
== NOSTR
) {
printf("No message !?!\n");
if (intty
&& value("askcc") != NOSTR
)
* Now, take the user names from the combined
* to and cc lists and do all the alias
to
= usermap(cat(extract(hp
->h_bcc
, GBCC
),
cat(extract(hp
->h_to
, GTO
), extract(hp
->h_cc
, GCC
))));
printf("No recipients specified\n");
* Look through the recipient list for names with /'s
* in them which we write to as files directly.
if (senderr
&& !remote
) {
exwrite(deadletter
, mtf
, 1);
for (gotcha
= 0, np
= to
; np
!= NIL
; np
= np
->n_flink
)
if ((np
->n_type
& GDEL
) == 0) {
if (hp
->h_seq
> 0 && !remote
) {
printf("Null message body; hope that's ok\n");
if ((mtf
= infix(hp
, mtf
)) == NULL
) {
fprintf(stderr
, ". . . message lost, sorry.\n");
printf("Recipients of message:\n");
for (t
= namelist
; *t
!= NOSTR
; t
++)
if ((cp
= value("record")) != NOSTR
)
savemail(expand(cp
), hp
, mtf
);
* Wait, to absorb a potential zombie, then
* fork, set up the temporary mail file as standard
* input for "mail" and exec with the user list we generated
* far above. Return the process id to caller in case he
* wants to await the completion of mail.
while (wait3(&s
, WNOHANG
, 0) > 0)
exwrite(deadletter
, mtf
, 1);
signal(SIGTSTP
, SIG_IGN
);
signal(SIGTTIN
, SIG_IGN
);
signal(SIGTTOU
, SIG_IGN
);
for (i
= SIGHUP
; i
<= SIGQUIT
; i
++)
if ((postage
= fopen("/crp/kurt/postage", "a")) != NULL
) {
fprintf(postage
, "%s %d %d\n", myname
,
execv(DELIVERMAIL
, namelist
);
while ((p
= wait(&s
)) != pid
&& p
!= -1)
* Fix the header by glopping all of the expanded names from
* the distribution list into the appropriate fields.
* If there are any ARPA net recipients in the message,
* we must insert commas, alas.
register struct name
*nlist
;
register struct name
*np
;
for (f
= 0, np
= tolist
; np
!= NIL
; np
= np
->n_flink
)
if (any('@', np
->n_name
)) {
fprintf(stderr
, "Should be inserting commas in recip lists\n");
hp
->h_to
= detract(tolist
, GTO
|f
);
hp
->h_cc
= detract(tolist
, GCC
|f
);
* Prepend a header in front of the collected stuff
* and return the new file.
register FILE *nfo
, *nfi
;
if ((nfo
= fopen(tempMail
, "w")) == NULL
) {
if ((nfi
= fopen(tempMail
, "r")) == NULL
) {
puthead(hp
, nfo
, GTO
|GSUBJECT
|GCC
|GNL
);
* Dump the to, subject, cc header on the
if (hp
->h_to
!= NOSTR
&& w
& GTO
)
fprintf(fo
, "To: "), fmt(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
)
fprintf(fo
, "Cc: "), fmt(hp
->h_cc
, fo
), gotcha
++;
if (hp
->h_bcc
!= NOSTR
&& w
& GBCC
)
fprintf(fo
, "Bcc: "), fmt(hp
->h_bcc
, fo
), gotcha
++;
* Format the given text to not exceed 72 characters.
if (*cp
== ' ' && col
> 65) {
* Save the outgoing mail on the passed file.
if ((fo
= fopen(name
, "a")) == NULL
) {
fprintf(fo
, "From %s %s", n
, ctime(&now
));
for (c
= getc(fi
); c
!= EOF
; c
= getc(fi
))