summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2015-01-20 16:59:07 +0000
committermillert <millert@openbsd.org>2015-01-20 16:59:07 +0000
commit6748e6a0519558451e9cc31d0825d9f7d90c1ee4 (patch)
tree24f783cb445684197871a792b14f6a8d0f9fd2e6
parentAllocate a bit more memory to reduce the change of having to (diff)
downloadwireguard-openbsd-6748e6a0519558451e9cc31d0825d9f7d90c1ee4.tar.xz
wireguard-openbsd-6748e6a0519558451e9cc31d0825d9f7d90c1ee4.zip
Add support for the "-r fromaddr" flag now that we don't support
sendmail flags on the command line. Also allow "from" to be set in mailrc. Use sendmail's "-t" flag when executing sendmail instead of specifying the list of recipients in argv. The "-f" flag will be used to set the from address if specified.
-rw-r--r--usr.bin/mail/cmd3.c4
-rw-r--r--usr.bin/mail/def.h5
-rw-r--r--usr.bin/mail/extern.h8
-rw-r--r--usr.bin/mail/mail.125
-rw-r--r--usr.bin/mail/main.c16
-rw-r--r--usr.bin/mail/names.c48
-rw-r--r--usr.bin/mail/send.c48
7 files changed, 81 insertions, 73 deletions
diff --git a/usr.bin/mail/cmd3.c b/usr.bin/mail/cmd3.c
index 905144b839d..7bdfce32623 100644
--- a/usr.bin/mail/cmd3.c
+++ b/usr.bin/mail/cmd3.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd3.c,v 1.25 2011/04/06 11:36:26 miod Exp $ */
+/* $OpenBSD: cmd3.c,v 1.26 2015/01/20 16:59:07 millert Exp $ */
/* $NetBSD: cmd3.c,v 1.8 1997/07/09 05:29:49 mikel Exp $ */
/*
@@ -227,6 +227,7 @@ _respond(msgvec)
}
np = elide(np);
head.h_to = np;
+ head.h_from = NULL;
if ((head.h_subject = hfield("subject", mp)) == NULL)
head.h_subject = hfield("subj", mp);
head.h_subject = reedit(head.h_subject);
@@ -619,6 +620,7 @@ _Respond(int *msgvec)
if ((head.h_subject = hfield("subject", mp)) == NULL)
head.h_subject = hfield("subj", mp);
head.h_subject = reedit(head.h_subject);
+ head.h_from = NULL;
head.h_cc = NULL;
head.h_bcc = NULL;
head.h_smopts = NULL;
diff --git a/usr.bin/mail/def.h b/usr.bin/mail/def.h
index 17bdaf54eb5..a1f1a9675f8 100644
--- a/usr.bin/mail/def.h
+++ b/usr.bin/mail/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.14 2015/01/16 06:40:09 deraadt Exp $ */
+/* $OpenBSD: def.h,v 1.15 2015/01/20 16:59:07 millert Exp $ */
/* $NetBSD: def.h,v 1.9 1996/12/28 07:11:00 tls Exp $ */
/*
@@ -30,7 +30,7 @@
* SUCH DAMAGE.
*
* @(#)def.h 8.4 (Berkeley) 4/20/95
- * $OpenBSD: def.h,v 1.14 2015/01/16 06:40:09 deraadt Exp $
+ * $OpenBSD: def.h,v 1.15 2015/01/20 16:59:07 millert Exp $
*/
/*
@@ -172,6 +172,7 @@ struct headline {
*/
struct header {
struct name *h_to; /* Dynamic "To:" string */
+ char *h_from; /* User-specified "From:" string */
char *h_subject; /* Subject string */
struct name *h_cc; /* Carbon copies string */
struct name *h_bcc; /* Blind carbon copies */
diff --git a/usr.bin/mail/extern.h b/usr.bin/mail/extern.h
index 5255f6529ad..61f022bec25 100644
--- a/usr.bin/mail/extern.h
+++ b/usr.bin/mail/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.27 2009/07/28 16:05:04 martynas Exp $ */
+/* $OpenBSD: extern.h,v 1.28 2015/01/20 16:59:07 millert Exp $ */
/* $NetBSD: extern.h,v 1.7 1997/07/09 05:22:00 mikel Exp $ */
/*-
@@ -30,7 +30,7 @@
* SUCH DAMAGE.
*
* @(#)extern.h 8.2 (Berkeley) 4/20/95
- * $OpenBSD: extern.h,v 1.27 2009/07/28 16:05:04 martynas Exp $
+ * $OpenBSD: extern.h,v 1.28 2015/01/20 16:59:07 millert Exp $
*/
struct name;
@@ -163,8 +163,8 @@ const struct cmd *
void load(char *);
struct var *
lookup(char *);
-int mail (struct name *, struct name *, struct name *, struct name *,
- char *);
+int mail(struct name *, struct name *, struct name *, struct name *,
+ char *, char *);
void mail1(struct header *, int);
void makemessage(FILE *, int);
void mark(int);
diff --git a/usr.bin/mail/mail.1 b/usr.bin/mail/mail.1
index 8a0387589ee..fefbfef2751 100644
--- a/usr.bin/mail/mail.1
+++ b/usr.bin/mail/mail.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mail.1,v 1.72 2015/01/07 17:08:21 millert Exp $
+.\" $OpenBSD: mail.1,v 1.73 2015/01/20 16:59:07 millert Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)mail.1 8.8 (Berkeley) 4/28/95
.\"
-.Dd $Mdocdate: January 7 2015 $
+.Dd $Mdocdate: January 20 2015 $
.Dt MAIL 1
.Os
.Sh NAME
@@ -43,6 +43,7 @@
.Op Fl dEIinv
.Op Fl b Ar list
.Op Fl c Ar list
+.Op Fl r Ar from-addr
.Op Fl s Ar subject
.Ar to-addr ...
.Ek
@@ -109,6 +110,13 @@ when reading mail or editing a mail folder.
Inhibits reading
.Pa /etc/mail.rc
upon startup.
+.It Fl r Ar from-addr
+Use
+.Ar from-addr
+as the from address in the message and envelope.
+Overrides any
+.Em from
+options in the startup files.
.It Fl s Ar subject
Specify subject on command line
(only the first argument after the
@@ -969,6 +977,19 @@ Causes
.Nm mail
to expand message recipient addresses, as explained in the section
.Sx Recipient address specifications .
+.It Ar from
+Causes
+.Nm mail
+to use the specified sender address in the
+.Dq From:
+field of the message header.
+A stripped down version of the address is also used in the message envelope.
+If unset, the message will not include an explicit sender address and
+a default value will be added by the MTA, typically
+.Dq user@host .
+This value can be overridden by specifying the
+.Fl r
+flag on the command line.
.It Ar hold
This option is used to hold messages in the system mailbox
by default.
diff --git a/usr.bin/mail/main.c b/usr.bin/mail/main.c
index 2dfde98ef28..eb02c18b57c 100644
--- a/usr.bin/mail/main.c
+++ b/usr.bin/mail/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.27 2015/01/16 06:40:09 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.28 2015/01/20 16:59:07 millert Exp $ */
/* $NetBSD: main.c,v 1.7 1997/05/13 06:15:57 mikel Exp $ */
/*
@@ -49,6 +49,7 @@ main(int argc, char **argv)
{
int i;
struct name *to, *cc, *bcc, *smopts;
+ char *fromaddr;
char *subject;
char *ef;
char nosrc = 0;
@@ -77,8 +78,9 @@ main(int argc, char **argv)
cc = NULL;
bcc = NULL;
smopts = NULL;
+ fromaddr = NULL;
subject = NULL;
- while ((i = getopt(argc, argv, "EIN:b:c:dfins:u:v")) != -1) {
+ while ((i = getopt(argc, argv, "EIN:b:c:dfinr:s:u:v")) != -1) {
switch (i) {
case 'u':
/*
@@ -100,6 +102,12 @@ main(int argc, char **argv)
case 'd':
debug++;
break;
+ case 'r':
+ /*
+ * Set From: address
+ */
+ fromaddr = optarg;
+ break;
case 's':
/*
* Give a subject field for sending from
@@ -203,7 +211,7 @@ main(int argc, char **argv)
rc = "~/.mailrc";
load(expand(rc));
if (!rcvmode) {
- mail(to, cc, bcc, smopts, subject);
+ mail(to, cc, bcc, smopts, fromaddr, subject);
/*
* why wait?
*/
@@ -272,7 +280,7 @@ usage(void)
{
fprintf(stderr, "usage: %s [-dEIinv] [-b list] [-c list] "
- "[-s subject] to-addr ...\n", __progname);
+ "[-r from-addr] [-s subject] to-addr ...\n", __progname);
fprintf(stderr, " %s [-dEIiNnv] -f [file]\n", __progname);
fprintf(stderr, " %s [-dEIiNnv] [-u user]\n", __progname);
exit(1);
diff --git a/usr.bin/mail/names.c b/usr.bin/mail/names.c
index 87905aaea0f..c61640eec57 100644
--- a/usr.bin/mail/names.c
+++ b/usr.bin/mail/names.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: names.c,v 1.21 2014/12/16 18:36:46 millert Exp $ */
+/* $OpenBSD: names.c,v 1.22 2015/01/20 16:59:07 millert Exp $ */
/* $NetBSD: names.c,v 1.5 1996/06/08 19:48:32 christos Exp $ */
/*
@@ -456,52 +456,6 @@ cat(struct name *n1, struct name *n2)
}
/*
- * Unpack the name list onto a vector of strings.
- * Return an error if the name list won't fit.
- */
-char **
-unpack(struct name *sm, struct name *np)
-{
- char **ap, **top;
- int t, extra, metoo, verbose;
-
- if ((t = count(np)) == 0)
- errx(1, "No names to unpack");
- t += count(sm);
-
- /*
- * Compute the number of extra arguments we will need.
- * We need at least four extra -- one for "send-mail", one for the
- * "-i" flag, one for the "--" to signal end of command line
- * arguments, and one for the terminating 0 pointer.
- */
- extra = 4;
- metoo = value("metoo") != NULL;
- if (metoo)
- extra++;
- verbose = value("verbose") != NULL;
- if (verbose)
- extra++;
- top = (char **)salloc((t + extra) * sizeof(*top));
- ap = top;
- *ap++ = "send-mail";
- *ap++ = "-i";
- if (metoo)
- *ap++ = "-m";
- if (verbose)
- *ap++ = "-v";
- for (; sm != NULL; sm = sm->n_flink)
- if ((sm->n_type & GDEL) == 0)
- *ap++ = sm->n_name;
- *ap++ = "--";
- for (; np != NULL; np = np->n_flink)
- if ((np->n_type & GDEL) == 0)
- *ap++ = np->n_name;
- *ap = NULL;
- return(top);
-}
-
-/*
* Remove all of the duplicates from the passed name list by
* insertion sorting them, then checking for dups.
* Return the head of the new list.
diff --git a/usr.bin/mail/send.c b/usr.bin/mail/send.c
index f8fdac9d1a8..8f127ac837f 100644
--- a/usr.bin/mail/send.c
+++ b/usr.bin/mail/send.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: send.c,v 1.23 2014/01/17 18:42:30 okan Exp $ */
+/* $OpenBSD: send.c,v 1.24 2015/01/20 16:59:07 millert Exp $ */
/* $NetBSD: send.c,v 1.6 1996/06/08 19:48:39 christos Exp $ */
/*
@@ -279,11 +279,12 @@ statusput(struct message *mp, FILE *obuf, char *prefix)
*/
int
mail(struct name *to, struct name *cc, struct name *bcc, struct name *smopts,
- char *subject)
+ char *fromaddr, char *subject)
{
struct header head;
head.h_to = to;
+ head.h_from = fromaddr;
head.h_subject = subject;
head.h_cc = cc;
head.h_bcc = bcc;
@@ -292,7 +293,6 @@ mail(struct name *to, struct name *cc, struct name *bcc, struct name *smopts,
return(0);
}
-
/*
* Send mail to a bunch of user names. The interface is through
* the mail routine below.
@@ -304,6 +304,7 @@ sendmail(void *v)
struct header head;
head.h_to = extract(str, GTO);
+ head.h_from = NULL;
head.h_subject = NULL;
head.h_cc = NULL;
head.h_bcc = NULL;
@@ -319,9 +320,10 @@ sendmail(void *v)
void
mail1(struct header *hp, int printheaders)
{
- char *cp;
+ char *cp, *envfrom = NULL;
+ char *argv[8];
+ char **ap = argv;
pid_t pid;
- char **namelist;
struct name *to;
FILE *mtf;
@@ -365,18 +367,33 @@ mail1(struct header *hp, int printheaders)
fputs(". . . message lost, sorry.\n", stderr);
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) {
- char **t;
-
fputs("Sendmail arguments:", stdout);
- for (t = namelist; *t != NULL; t++)
- printf(" \"%s\"", *t);
+ for (ap = argv; *ap != NULL; ap++)
+ printf(" \"%s\"", *ap);
putchar('\n');
goto out;
}
- if ((cp = value("record")) != NULL)
- (void)savemail(expand(cp), mtf);
/*
* Fork, set up the temporary mail file as standard
* input for "mail", and exec with the user list we generated
@@ -403,10 +420,11 @@ mail1(struct header *hp, int printheaders)
cp = expand(cp);
else
cp = _PATH_SENDMAIL;
- execv(cp, namelist);
+ execv(cp, argv);
warn("%s", cp);
_exit(1);
}
+ free(envfrom);
if (value("verbose") != NULL)
(void)wait_child(pid);
else
@@ -497,8 +515,12 @@ int
puthead(struct header *hp, FILE *fo, int w)
{
int gotcha;
+ char *from;
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)
fmt("To:", hp->h_to, fo, w&GCOMMA), gotcha++;
if (hp->h_subject != NULL && w & GSUBJECT)