version 1.23, 2014/01/17 18:42:30 |
version 1.24, 2015/01/20 16:59:07 |
|
|
*/ |
*/ |
int |
int |
mail(struct name *to, struct name *cc, struct name *bcc, struct name *smopts, |
mail(struct name *to, struct name *cc, struct name *bcc, struct name *smopts, |
char *subject) |
char *fromaddr, char *subject) |
{ |
{ |
struct header head; |
struct header head; |
|
|
head.h_to = to; |
head.h_to = to; |
|
head.h_from = fromaddr; |
head.h_subject = subject; |
head.h_subject = subject; |
head.h_cc = cc; |
head.h_cc = cc; |
head.h_bcc = bcc; |
head.h_bcc = bcc; |
|
|
return(0); |
return(0); |
} |
} |
|
|
|
|
/* |
/* |
* Send mail to a bunch of user names. The interface is through |
* Send mail to a bunch of user names. The interface is through |
* the mail routine below. |
* the mail routine below. |
|
|
struct header head; |
struct header head; |
|
|
head.h_to = extract(str, GTO); |
head.h_to = extract(str, GTO); |
|
head.h_from = NULL; |
head.h_subject = NULL; |
head.h_subject = NULL; |
head.h_cc = NULL; |
head.h_cc = NULL; |
head.h_bcc = NULL; |
head.h_bcc = NULL; |
|
|
void |
void |
mail1(struct header *hp, int printheaders) |
mail1(struct header *hp, int printheaders) |
{ |
{ |
char *cp; |
char *cp, *envfrom = NULL; |
|
char *argv[8]; |
|
char **ap = argv; |
pid_t pid; |
pid_t pid; |
char **namelist; |
|
struct name *to; |
struct name *to; |
FILE *mtf; |
FILE *mtf; |
|
|
|
|
fputs(". . . message lost, sorry.\n", stderr); |
fputs(". . . message lost, sorry.\n", stderr); |
return; |
return; |
} |
} |
namelist = unpack(hp->h_smopts, to); |
if ((cp = value("record")) != NULL) |
|
(void)savemail(expand(cp), mtf); |
|
|
|
/* Setup sendmail arguments. */ |
|
*ap++ = "send-mail"; |
|
*ap++ = "-i"; |
|
*ap++ = "-t"; |
|
cp = hp->h_from ? hp->h_from : value("from"); |
|
if (cp != NULL) { |
|
envfrom = skin(cp); |
|
*ap++ = "-f"; |
|
*ap++ = envfrom; |
|
if (envfrom == cp) |
|
envfrom = NULL; |
|
} |
|
if (value("metoo") != NULL) |
|
*ap++ = "-m"; |
|
if (value("verbose") != NULL) |
|
*ap++ = "-v"; |
|
*ap = NULL; |
if (debug) { |
if (debug) { |
char **t; |
|
|
|
fputs("Sendmail arguments:", stdout); |
fputs("Sendmail arguments:", stdout); |
for (t = namelist; *t != NULL; t++) |
for (ap = argv; *ap != NULL; ap++) |
printf(" \"%s\"", *t); |
printf(" \"%s\"", *ap); |
putchar('\n'); |
putchar('\n'); |
goto out; |
goto out; |
} |
} |
if ((cp = value("record")) != NULL) |
|
(void)savemail(expand(cp), mtf); |
|
/* |
/* |
* Fork, set up the temporary mail file as standard |
* Fork, set up the temporary mail file as standard |
* input for "mail", and exec with the user list we generated |
* input for "mail", and exec with the user list we generated |
|
|
cp = expand(cp); |
cp = expand(cp); |
else |
else |
cp = _PATH_SENDMAIL; |
cp = _PATH_SENDMAIL; |
execv(cp, namelist); |
execv(cp, argv); |
warn("%s", cp); |
warn("%s", cp); |
_exit(1); |
_exit(1); |
} |
} |
|
free(envfrom); |
if (value("verbose") != NULL) |
if (value("verbose") != NULL) |
(void)wait_child(pid); |
(void)wait_child(pid); |
else |
else |
|
|
puthead(struct header *hp, FILE *fo, int w) |
puthead(struct header *hp, FILE *fo, int w) |
{ |
{ |
int gotcha; |
int gotcha; |
|
char *from; |
|
|
gotcha = 0; |
gotcha = 0; |
|
from = hp->h_from ? hp->h_from : value("from"); |
|
if (from != NULL) |
|
fprintf(fo, "From: %s\n", from), gotcha++; |
if (hp->h_to != NULL && w & GTO) |
if (hp->h_to != NULL && w & GTO) |
fmt("To:", hp->h_to, fo, w&GCOMMA), gotcha++; |
fmt("To:", hp->h_to, fo, w&GCOMMA), gotcha++; |
if (hp->h_subject != NULL && w & GSUBJECT) |
if (hp->h_subject != NULL && w & GSUBJECT) |