From eda302e1f049eae6b429a12c5526600eea6a02e1 Mon Sep 17 00:00:00 2001 From: Philipp Takacs Date: Sun, 19 Apr 2015 00:53:14 +0200 Subject: [PATCH] Add "Default-From" config option The "Default-From" config option is used, if the Draft don't contain a From header. If the draft contains a From header and it's not from the user it's used as the Sender header. Bug: If the From-header contains more then one addresse and one is from the user, no Sender-header is attached. --- man/mh-profile.man5 | 10 ++++++++++ man/spost.man8 | 16 +++++++++++++--- uip/spost.c | 32 +++++++++++++++++++++++++++----- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/man/mh-profile.man5 b/man/mh-profile.man5 index 5e02d9f..9b052c9 100644 --- a/man/mh-profile.man5 +++ b/man/mh-profile.man5 @@ -304,6 +304,16 @@ or both ends of the mailbox and host to indicate wild-card matching. (profile, default: your user-id) .RE .PP +.BR Default-From : +Philipp Takacs +.RS 5 +Tells +.B spost +which addresse shall be used, if the draft dosn\'t contain a +.RI ` From ' +Header or the draft is not from the user. +.RE +.PP .BR Aliasfile : aliases .I other-alias diff --git a/man/spost.man8 b/man/spost.man8 index c66ba10..db783ef 100644 --- a/man/spost.man8 +++ b/man/spost.man8 @@ -65,6 +65,11 @@ For example, the `\-v' switch will be added to the invocation. .PP .B Spost +puts the +.RI ` Default-From ' +profile entry in the `From:' line of the message. +If `Default-From' is not set, +.B spost constructs the `From:' line of the message from the user's login name and the full name from the GECOS field of the passwd file. @@ -78,9 +83,11 @@ Its value overrides the full name from the GECOS field. If you specify a `From:' line manually in the message draft. It will be used as provided. -However, a `Sender:' header with the user's +A `Sender:' header with the user's .B real -address will be added. +address will be added, if the `From' line don't contain a address +from the user +.RI ` Alternate-Mailboxes '. .PP Note that this applies equally to `Resent\-From:' lines in messages sent with @@ -102,8 +109,11 @@ None .SH "PROFILE COMPONENTS" .fc ^ ~ .nf -.ta \w'ExtraBigFileName 'u +.ta 3.5i +.ta \w'ExtraBigProfileName 'u ^Aliasfile:~^For default alias files +^Default\-From:~^The default From header +^Alternate\-Mailboxes:~^The user's addresses .fi .SH "SEE ALSO" diff --git a/uip/spost.c b/uip/spost.c index 476227b..48f9797 100644 --- a/uip/spost.c +++ b/uip/spost.c @@ -56,6 +56,7 @@ static struct swit switches[] = { #define MVIS 0x0008 /* we've seen sighted addrs */ #define MINV 0x0010 /* we've seen blind addrs */ #define MRDT 0x0020 /* we've seen a Resent-Date: */ +#define MFMM 0x0040 /* The Mail is From a Alternative-Mailbox Addresse */ struct headers { char *value; @@ -411,6 +412,21 @@ putfmt(char *name, char *str, FILE *out) ** -- meillo@marmaro.de 2012-02 */ + if (hdr->set & MFRM) { + + struct mailname *mp = NULL; + + /* This is need because the addresse parser hold global state */ + ismymbox(NULL); + + while ((cp = getname(str)) != NULL) { + mp = getm(cp, NULL, 0, AD_NAME, NULL); + if (ismymbox(mp)) { + msgflags |= MFMM; + } + } + } + if (hdr->flags & HSUB) { subject = getcpy(str); } @@ -433,11 +449,15 @@ finish_headers(FILE *out) fprintf(out, "%sDate: %s\n", resentstr, dtimenow()); } - snprintf(from, sizeof(from), "%s@%s", getusername(), LocalName()); - if ((cp = getfullname()) && *cp) { - snprintf(signature, sizeof(signature), "%s <%s>", cp, from); + if ((cp = context_find("Default-From")) != NULL) { + snprintf(signature, sizeof(signature), "%s", cp); } else { - snprintf(signature, sizeof(signature), "%s", from); + snprintf(from, sizeof(from), "%s@%s", getusername(), LocalName()); + if ((cp = getfullname()) && *cp) { + snprintf(signature, sizeof(signature), "%s <%s>", cp, from); + } else { + snprintf(signature, sizeof(signature), "%s", from); + } } if (!(msgflags & MFRM)) { fprintf(out, "%sFrom: %s\n", resentstr, signature); @@ -446,7 +466,9 @@ finish_headers(FILE *out) ** Add a Sender: header because the From: header could ** be fake or contain multiple addresses. */ - fprintf(out, "%sSender: %s\n", resentstr, from); + if (!(msgflags & MFMM)) { + fprintf(out, "%sSender: %s\n", resentstr, signature); + } } if (!(msgflags & MVIS)) { fprintf(out, "%sBcc: undisclosed-recipients:;\n", resentstr); -- 1.7.10.4