Sometimes I need to send an email from a different address than usual. I do have $edit_headers set, but I've gotten tired of specifying the recipients and the subject, then moving to the first line and change the From:, then write the email. So I went ahead and added a $askfrom option.
I think the implementation is straightforward. One area I'm concerned about is the interaction with the N other ways to set the From (via myhdr, $from, hooks, and whatnot); I'm simply too new to mutt to be sure I accounted for all possibilities here. I'd like to thank rudi_s (from #mutt IRC) for his help with reviewing and testing an earlier version of the patch, and Ramkumar Ramachandra for reviewing the patch and contributing several hunks to it. I'm attaching the patch, and it can also be found at [1]. If there's anything further I can do, please let me know. Thanks, Daniel [1] http://people.apache.org/~danielsh/askfrom.diff
# HG changeset patch # User Daniel Shahaf <[email protected]> # Date 1288050464 -7200 # Branch HEAD # Node ID c69246544f0b35d60333cbce3014764c6c6a7350 # Parent 57568da7d9aaaef82aba7634ad3668f6e67f3c2d add $askfrom option Credits: * Daniel Shahaf (shepherd) * Simon Ruderich (reviews) * Ramkumar Ramachandra (reviews, builtin editor support) diff -r 57568da7d9aa -r c69246544f0b contrib/sample.muttrc --- a/contrib/sample.muttrc Wed Oct 13 07:38:30 2010 -0700 +++ b/contrib/sample.muttrc Tue Oct 26 01:47:44 2010 +0200 @@ -23,6 +23,7 @@ #set ascii_chars # use ASCII instead of ACS chars for threads #set askbcc #set askcc +#set askfrom #set attribution="On %d, %n wrote:" # how to attribute replies set autoedit # go to the editor right away when composing #set auto_tag # always operate on tagged messages diff -r 57568da7d9aa -r c69246544f0b doc/manual.xml.head --- a/doc/manual.xml.head Wed Oct 13 07:38:30 2010 -0700 +++ b/doc/manual.xml.head Tue Oct 26 01:47:44 2010 +0200 @@ -1221,6 +1221,7 @@ a default if you are replying to or forwarding a message. You again have the chance to adjust recipients, subject, and security settings right before actually sending the message. See also <link +linkend="askfrom">$askfrom</link>, <link linkend="askcc">$askcc</link>, <link linkend="askbcc">$askbcc</link>, <link linkend="autoedit">$autoedit</link>, <link linkend="bounce">$bounce</link>, <link diff -r 57568da7d9aa -r c69246544f0b doc/mutt.pwl --- a/doc/mutt.pwl Wed Oct 13 07:38:30 2010 -0700 +++ b/doc/mutt.pwl Tue Oct 26 01:47:44 2010 +0200 @@ -305,6 +305,7 @@ pubring fBif ldap +noaskfrom noaskbcc wiki unsetting @@ -512,5 +513,6 @@ prepends login cntrl +askfrom askbcc pagesize diff -r 57568da7d9aa -r c69246544f0b edit.c --- a/edit.c Wed Oct 13 07:38:30 2010 -0700 +++ b/edit.c Tue Oct 26 01:47:44 2010 +0200 @@ -194,6 +194,14 @@ { char tmp[HUGE_STRING]; + if (env->from) + { + addstr ("From: "); + tmp[0] = 0; + rfc822_write_address (tmp, sizeof (tmp), env->from, 1); + addstr (tmp); + addch ('\n'); + } if (env->to) { addstr ("To: "); @@ -235,6 +243,27 @@ char tmp[HUGE_STRING]; move (LINES-1, 0); + + if ((!e->from && option (OPTASKFROM)) || force) + { + addstr ("From: "); + tmp[0] = 0; + mutt_addrlist_to_local (e->from); + rfc822_write_address (tmp, sizeof (tmp), e->from, 0); + if (mutt_enter_string (tmp, sizeof (tmp), LINES-1, 6, 0) == 0) + { + rfc822_free_address (&e->from); + e->from = mutt_parse_adrlist (e->from, tmp); + e->from = mutt_expand_aliases (e->from); + mutt_addrlist_to_idna (e->from, NULL); + tmp[0] = 0; + rfc822_write_address (tmp, sizeof (tmp), e->from, 1); + mvaddstr (LINES - 1, 6, tmp); + } + else + mutt_addrlist_to_idna (e->from, NULL); + addch ('\n'); + } addstr ("To: "); tmp[0] = 0; @@ -367,6 +396,7 @@ case 'h': be_edit_header (msg->env, 1); break; + /* No, 'f' is not 'add to from'. */ case 'F': case 'f': case 'm': diff -r 57568da7d9aa -r c69246544f0b init.h --- a/init.h Wed Oct 13 07:38:30 2010 -0700 +++ b/init.h Tue Oct 26 01:47:44 2010 +0200 @@ -175,6 +175,12 @@ ** .pp ** If \fIset\fP, Mutt will prompt you for carbon-copy (Cc) recipients before ** editing the body of an outgoing message. + */ + { "askfrom", DT_BOOL, R_NONE, OPTASKFROM, 0 }, + /* + ** .pp + ** If \fIset\fP, Mutt will prompt you for From address + ** before editing an outgoing message. */ { "assumed_charset", DT_STR, R_NONE, UL &AssumedCharset, UL 0}, /* diff -r 57568da7d9aa -r c69246544f0b mutt.h --- a/mutt.h Wed Oct 13 07:38:30 2010 -0700 +++ b/mutt.h Tue Oct 26 01:47:44 2010 +0200 @@ -319,6 +319,7 @@ OPTASCIICHARS, OPTASKBCC, OPTASKCC, + OPTASKFROM, OPTATTACHSPLIT, OPTAUTOEDIT, OPTAUTOTAG, diff -r 57568da7d9aa -r c69246544f0b send.c --- a/send.c Wed Oct 13 07:38:30 2010 -0700 +++ b/send.c Tue Oct 26 01:47:44 2010 +0200 @@ -218,6 +218,8 @@ char buf[HUGE_STRING]; LIST *uh = UserHeader; + if (option (OPTASKFROM) && edit_address (&en->from, "From: ") == -1) + return (-1); if (edit_address (&en->to, "To: ") == -1 || en->to == NULL) return (-1); if (option (OPTASKCC) && edit_address (&en->cc, "Cc: ") == -1) @@ -1124,7 +1126,7 @@ char fcc[_POSIX_PATH_MAX] = ""; /* where to copy this message */ FILE *tempfp = NULL; BODY *pbody; - int i, killfrom = 0; + int i, killfrom = 0, manually_set = 0; int fcc_error = 0; int free_clear_content = 0; @@ -1268,6 +1270,8 @@ { if (edit_envelope (msg->env) == -1) goto cleanup; + else + manually_set = (option (OPTASKFROM) && msg->env->from); } /* the from address must be set here regardless of whether or not @@ -1309,6 +1313,7 @@ /* $use_from and/or $from might have changed in a send-hook */ if (killfrom) { + /* at this point, manually_set is false. */ rfc822_free_address (&msg->env->from); if (option (OPTUSEFROM) && !(flags & (SENDPOSTPONED|SENDRESEND))) msg->env->from = mutt_default_from (); @@ -1345,7 +1350,7 @@ /* wait until now to set the real name portion of our return address so that $realname can be set in a send-hook */ if (msg->env->from && !msg->env->from->personal - && !(flags & (SENDRESEND|SENDPOSTPONED))) + && !manually_set && !(flags & (SENDRESEND|SENDPOSTPONED))) msg->env->from->personal = safe_strdup (Realname); if (!((WithCrypto & APPLICATION_PGP) && (flags & SENDKEY)))
