On Mon, 05 Jan 2015 22:26:03 -0500, trondd wrote:
>>
>> I like this better. But I still want the set from="XXX" in .mailrc and
>> of course the manpage.
>>
>
>I would like to have this option.  The diff doesn't work, however. If
>you reply to a message, it messes up the header and replyall will crash.
>
>& set from="tro...@gmail.com"
>& set
>...
>from    tro...@gmail.com
>...
>& r 294
>From: Replyall
>To: xxxx...@xxxxx.xxx
>Subject: Re: Hi
>
>~x
>& R 294
>Bus error (core dumped)

Sorry, my fault. Try the diff below.

Nathanael

Index: cmd3.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/cmd3.c,v
retrieving revision 1.25
diff -u -p -r1.25 cmd3.c
--- cmd3.c      6 Apr 2011 11:36:26 -0000       1.25
+++ cmd3.c      6 Jan 2015 17:49:11 -0000
@@ -230,6 +230,7 @@ _respond(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;
        if (replyto == NULL && (cp = skin(hfield("cc", mp))) != NULL) {
                np = elide(extract(cp, GCC));
                np = delname(np, myname);
@@ -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;
Index: def.h
===================================================================
RCS file: /cvs/src/usr.bin/mail/def.h,v
retrieving revision 1.13
diff -u -p -r1.13 def.h
--- def.h       25 Jun 2003 15:13:32 -0000      1.13
+++ def.h       6 Jan 2015 17:49:11 -0000
@@ -173,6 +173,7 @@ struct headline {
 struct header {
        struct name *h_to;              /* Dynamic "To:" string */
        char *h_subject;                /* Subject string */
+       char *h_from;                   /* Sender */
        struct name *h_cc;              /* Carbon copies string */
        struct name *h_bcc;             /* Blind carbon copies */
        struct name *h_smopts;          /* Sendmail options */
Index: extern.h
===================================================================
RCS file: /cvs/src/usr.bin/mail/extern.h,v
retrieving revision 1.27
diff -u -p -r1.27 extern.h
--- extern.h    28 Jul 2009 16:05:04 -0000      1.27
+++ extern.h    6 Jan 2015 17:49:11 -0000
@@ -164,7 +164,7 @@ void         load(char *);
 struct var *
         lookup(char *);
 int     mail (struct name *, struct name *, struct name *, struct name *,
-              char *);
+              char *, char *);
 void    mail1(struct header *, int);
 void    makemessage(FILE *, int);
 void    mark(int);
Index: mail.1
===================================================================
RCS file: /cvs/src/usr.bin/mail/mail.1,v
retrieving revision 1.70
diff -u -p -r1.70 mail.1
--- mail.1      16 Dec 2014 18:37:17 -0000      1.70
+++ mail.1      6 Jan 2015 17:49:11 -0000
@@ -42,6 +42,7 @@
 .Bk -words
 .Op Fl dEIinv
 .Op Fl b Ar list
+.Op Fl F Ar from
 .Op Fl c Ar list
 .Op Fl s Ar subject
 .Ar to-addr ...
@@ -62,6 +63,11 @@ with lines replaced by messages.
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
+.It Fl F Ar from
+Pass
+.Ar from
+to the mail delivery system as the from address.
+Overrides the from option below.
 .It Fl b Ar list
 Send blind carbon copies to
 .Ar list .
@@ -965,6 +971,14 @@ Causes
 .Nm mail
 to expand message recipient addresses, as explained in the section
 .Sx Recipient address specifications .
+.It Ar from
+Causes
+.Nm mail
+to pass a from address to the mail delivery system. If unset, no from
+address will be passed and the mail delivery system will use its default
+of user <at> host. This will be overriden if the
+.Fl F
+flag is set.
 .It Ar hold
 This option is used to hold messages in the system mailbox
 by default.
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/main.c,v
retrieving revision 1.26
diff -u -p -r1.26 main.c
--- main.c      16 Dec 2014 18:37:17 -0000      1.26
+++ main.c      6 Jan 2015 17:49:11 -0000
@@ -50,6 +50,7 @@ main(int argc, char **argv)
        int i;
        struct name *to, *cc, *bcc, *smopts;
        char *subject;
+       char *from;
        char *ef;
        char nosrc = 0;
        char *rc;
@@ -78,7 +79,8 @@ main(int argc, char **argv)
        bcc = NULL;
        smopts = NULL;
        subject = NULL;
-       while ((i = getopt(argc, argv, "EIN:b:c:dfins:u:v")) != -1) {
+       from = NULL;
+       while ((i = getopt(argc, argv, "EF:IN:b:c:dfins:u:v")) != -1) {
                switch (i) {
                case 'u':
                        /*
@@ -100,6 +102,9 @@ main(int argc, char **argv)
                case 'd':
                        debug++;
                        break;
+               case 'F':
+                       from = optarg;
+                       break;
                case 's':
                        /*
                         * Give a subject field for sending from
@@ -203,7 +208,7 @@ main(int argc, char **argv)
                rc = "~/.mailrc";
        load(expand(rc));
        if (!rcvmode) {
-               mail(to, cc, bcc, smopts, subject);
+               mail(to, cc, bcc, smopts, subject, from);
                /*
                 * why wait?
                 */
@@ -271,7 +276,7 @@ __dead void
 usage(void)
 {
 
-       fprintf(stderr, "usage: %s [-dEIinv] [-b list] [-c list] "
+       fprintf(stderr, "usage: %s [-dEIinv] [-F from] [-b list] [-c list] "
            "[-s subject] to-addr ...\n", __progname);
        fprintf(stderr, "       %s [-dEIiNnv] -f [file]\n", __progname);
        fprintf(stderr, "       %s [-dEIiNnv] [-u user]\n", __progname);
Index: send.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/send.c,v
retrieving revision 1.23
diff -u -p -r1.23 send.c
--- send.c      17 Jan 2014 18:42:30 -0000      1.23
+++ send.c      6 Jan 2015 17:49:11 -0000
@@ -279,12 +279,13 @@ statusput(struct message *mp, FILE *obuf
  */
 int
 mail(struct name *to, struct name *cc, struct name *bcc, struct name *smopts,
-     char *subject)
+     char *subject, char *from)
 {
        struct header head;
 
        head.h_to = to;
        head.h_subject = subject;
+       head.h_from = from;
        head.h_cc = cc;
        head.h_bcc = bcc;
        head.h_smopts = smopts;
@@ -305,6 +306,7 @@ sendmail(void *v)
 
        head.h_to = extract(str, GTO);
        head.h_subject = NULL;
+       head.h_from = NULL;
        head.h_cc = NULL;
        head.h_bcc = NULL;
        head.h_smopts = NULL;
@@ -403,7 +405,7 @@ mail1(struct header *hp, int printheader
                        cp = expand(cp);
                else
                        cp = _PATH_SENDMAIL;
-               execv(cp, namelist);
+               execl(cp, "sendmail", "-t", NULL);
                warn("%s", cp);
                _exit(1);
        }
@@ -497,8 +499,14 @@ int
 puthead(struct header *hp, FILE *fo, int w)
 {
        int gotcha;
+       char* from;
 
        gotcha = 0;
+       from = hp->h_from;
+       if (from == NULL)
+               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)

Reply via email to