Subject says it all. The From: address (as it is called in the sources) in the prompt will be prepopulated with a suggestion whose value comes from either the "reverse_name" or "from" configuration variables, the latter of the two possibly set during an early reply-hook.
From f0056833c193cfce560563c6e26b48300d5b4ca5 Mon Sep 17 00:00:00 2001 From: Mono DHS <[email protected]> Date: Mon, 20 Jul 2020 20:22:34 +0200 Subject: [PATCH] Optionally prompt for the From: address in outgoing messages.
---
doc/manual.xml.head | 23 ++++++++++++-----
init.h | 29 +++++++++++++++++++++
mutt.h | 3 +++
send.c | 73 +++++++++++++++++++++++++++++++++++++++++------------
4 files changed, 105 insertions(+), 23 deletions(-)
diff --git a/doc/manual.xml.head b/doc/manual.xml.head
index
5276953059e453592c2832db5abed4ec6a500395..a910dc7de04289e54aaa821a0792eeb1fa0bdfda
100644
--- a/doc/manual.xml.head
+++ b/doc/manual.xml.head
@@ -1307,8 +1307,9 @@ when you hit <literal>m</literal> to start a new message.
Next, it will
ask you for the <quote>Subject:</quote> field for the message, providing
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="askcc">$askcc</link>, <link linkend="askbcc">$askbcc</link>,
+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
linkend="fast-reply">$fast_reply</link>, and <link
@@ -7162,10 +7163,8 @@ macro index ,a
"<save-message>=archive<enter><enter-command>ec
</listitem>
<listitem>
<para>
- Prompts for To, Cc, Bcc, Subject headers.
- See <link linkend="askcc">$askcc</link>,
- <link linkend="askbcc">$askbcc</link>,
- <link linkend="fast-reply">$fast_reply</link>.
+ <link linkend="reply-hook">reply-hook</link>,
+ if <link linkend="early-reply-hook">$early_reply_hook</link> is set.
</para>
</listitem>
<listitem>
@@ -7178,7 +7177,17 @@ macro index ,a
"<save-message>=archive<enter><enter-command>ec
</listitem>
<listitem>
<para>
- <link linkend="reply-hook">reply-hook</link>
+ Prompts for From, To, Cc, Bcc, Subject headers.
+ See <link linkend="askfrom">$askfrom</link>,
+ <link linkend="askcc">$askcc</link>,
+ <link linkend="askbcc">$askbcc</link>,
+ <link linkend="fast-reply">$fast_reply</link>.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <link linkend="reply-hook">reply-hook</link>,
+ if <link linkend="early-reply-hook">$early_reply_hook</link> is not
set.
</para>
</listitem>
<listitem>
diff --git a/init.h b/init.h
index
6cbc30a3ca4423a053b69427cb6e906e33618d60..60b1e90023c65144d11e87c9f105305d86d691ee
100644
--- a/init.h
+++ b/init.h
@@ -107,6 +107,17 @@ struct option_t MuttVars[] = {
** sensitive if the pattern contains at least one upper case letter,
** and case insensitive otherwise.
*/
+ { "abort_nofrom", DT_QUAD, R_NONE, {.l=OPT_ABORTNOFROM}, {.l=MUTT_ASKYES}
},
+ /*
+ ** .pp
+ ** If set to \fIyes\fP, when composing messages and no sender address
+ ** is given at the sender address prompt, composition will be aborted.
+ ** If set to \fIno\fP, composing messages with no sender address given
+ ** at the sender address prompt continues, but a default sender address
+ ** is used instead.
+ ** .pp
+ ** \fBSee also:\fP $$askfrom, $$from, $$use_from.
+ */
{ "abort_nosubject", DT_QUAD, R_NONE, {.l=OPT_SUBJECT}, {.l=MUTT_ASKYES} },
/*
** .pp
@@ -200,6 +211,14 @@ struct option_t MuttVars[] = {
** 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, {.l=OPTASKFROM}, {.l=0} },
+ /*
+ ** .pp
+ ** If \fIset\fP, Mutt will prompt you for the sender address (From) before
+ ** editing the body of an outgoing message.
+ ** .pp
+ ** \fBSee also:\fP $$abort_nofrom.
+ */
{ "assumed_charset", DT_STR, R_NONE, {.p=&AssumedCharset}, {.p=0} },
/*
** .pp
@@ -950,6 +969,16 @@ struct option_t MuttVars[] = {
** that it thinks they are duplicates of each other with an equals sign
** in the thread tree.
*/
+ { "early_reply_hook", DT_BOOL, R_NONE, {.l=OPTEARLYREPLYHOOK}, {.l=0}
},
+ /*
+ ** .pp
+ ** This variable controls whether Mutt will apply the \fCreply-hook\fP
+ ** \fIbefore\fP it consults $$from to temporarily set the sender address
(From)
+ ** and gives the user the opportunity to edit the envelope
+ ** of an outgoing message.
+ ** .pp
+ ** \fBSee also:\fP $compose-flow, $$askfrom, $$from
+ */
{ "edit_headers", DT_BOOL, R_NONE, {.l=OPTEDITHDRS}, {.l=0} },
/*
** .pp
diff --git a/mutt.h b/mutt.h
index
4413739ff0748215807e8a7d3e9d803bdeabd26e..e8979db15aa487e60f42f26ad2aacfad1fc302f7
100644
--- a/mutt.h
+++ b/mutt.h
@@ -310,6 +310,7 @@ enum
{
OPT_ABORT,
OPT_ABORTNOATTACH,
+ OPT_ABORTNOFROM,
OPT_BOUNCE,
OPT_COPY,
OPT_DELETE,
@@ -381,6 +382,7 @@ enum
OPTASCIICHARS,
OPTASKBCC,
OPTASKCC,
+ OPTASKFROM,
OPTATTACHSPLIT,
#ifdef USE_AUTOCRYPT
OPTAUTOCRYPT,
@@ -407,6 +409,7 @@ enum
OPTDELETEUNTAG,
OPTDIGESTCOLLAPSE,
OPTDUPTHREADS,
+ OPTEARLYREPLYHOOK,
OPTEDITHDRS,
OPTENCODEFROM,
OPTENVFROM,
diff --git a/send.c b/send.c
index
44e34feaaa3adc0a4e8bdbef9fe3bffc85cbf474..7a760b8c66f93573e82838e15242aa9efcfcb231
100644
--- a/send.c
+++ b/send.c
@@ -225,11 +225,41 @@ int mutt_edit_address (ADDRESS **a, const char *field,
int expand_aliases)
return 0;
}
-static int edit_envelope (ENVELOPE *en)
+static int edit_envelope (ENVELOPE *en, int * killfrom)
{
char buf[HUGE_STRING];
LIST *uh = UserHeader;
+ if (option (OPTASKFROM)) {
+
+ if (mutt_edit_address(&en->from, _("From: "), 1) == -1)
+ return (-1);
+
+ if (en->from == NULL) {
+
+ int b = query_quadoption(OPT_ABORTNOFROM, _("No sender address,
abort?"));
+ if (b != MUTT_NO)
+ return (-1);
+
+ /* Proceeding with no From: address does not really
+ * make much sense here, so we understand the empty
+ * address to mean to fall back to whatever default
+ * From: address Mutt is capable to come up with
+ * further down in the message composition process.
+ */
+ en->from = rfc822_new_address();
+ (*killfrom) = 1;
+
+ } else {
+
+ /* Only if the user specified a proper address do
+ * we instruct Mutt to not touch the From: address
+ * for the outgoing message.
+ */
+ (*killfrom) = 0;
+ }
+ }
+
if (mutt_edit_address (&en->to, _("To: "), 1) == -1 || en->to == NULL)
return (-1);
if (option (OPTASKCC) && mutt_edit_address (&en->cc, _("Cc: "), 1) == -1)
@@ -1949,26 +1979,38 @@ static int send_message_setup (SEND_CONTEXT *sctx,
const char *tempfile,
if (sctx->flags & SENDREPLY)
mutt_fix_reply_recipients (sctx->msg->env);
- if (! (sctx->flags & (SENDMAILX|SENDBATCH)) &&
- ! (option (OPTAUTOEDIT) && option (OPTEDITHDRS)) &&
- ! ((sctx->flags & SENDREPLY) && option (OPTFASTREPLY)))
- {
- if (edit_envelope (sctx->msg->env) == -1)
- goto cleanup;
+ /* An early application of the reply-hook based on $early_reply_hook
+ * makes scenarios possible in which the reply-hook is first applied
+ * here and then again at its traditional point further down below
+ * by clearing $early_reply_hook here and setting it there again.
+ */
+ if (option(OPTEARLYREPLYHOOK) && (sctx->flags & SENDREPLY) && sctx->cur) {
+ mutt_message_hook (ctx, sctx->cur, MUTT_REPLYHOOK);
+ sctx->msg->replied = 1;
}
- /* the from address must be set here regardless of whether or not
- * $use_from is set so that the `~P' (from you) operator in send-hook
- * patterns will work. if $use_from is unset, the from address is killed
- * after send-hooks are evaluated */
-
+ /* The From: address should be set before giving the user the
+ * opportunity to edit the envelope and must be set before applying
+ * any hooks on the new message, regardless of whether or not $use_from
+ * is set so that the `~P' (from you) operator in send-hook patterns will
+ * work. If $use_from is unset, the From: address is killed after
+ * send-hooks are evaluated.
+ */
if (!sctx->msg->env->from)
{
sctx->msg->env->from = mutt_default_from ();
killfrom = 1;
}
- if ((sctx->flags & SENDREPLY) && sctx->cur)
+ if (! (sctx->flags & (SENDMAILX|SENDBATCH)) &&
+ ! (option (OPTAUTOEDIT) && option (OPTEDITHDRS)) &&
+ ! ((sctx->flags & SENDREPLY) && option (OPTFASTREPLY)))
+ {
+ if (edit_envelope (sctx->msg->env, &killfrom) == -1)
+ goto cleanup;
+ }
+
+ if (!option(OPTEARLYREPLYHOOK) && (sctx->flags & SENDREPLY) && sctx->cur)
{
/* change setting based upon message we are replying to */
mutt_message_hook (ctx, sctx->cur, MUTT_REPLYHOOK);
@@ -1997,9 +2039,8 @@ static int send_message_setup (SEND_CONTEXT *sctx, const
char *tempfile,
if (killfrom)
{
rfc822_free_address (&sctx->msg->env->from);
- if (option (OPTUSEFROM) && !(sctx->flags & (SENDPOSTPONED|SENDRESEND)))
- sctx->msg->env->from = mutt_default_from ();
- killfrom = 0;
+ if (option (OPTUSEFROM))
+ sctx->msg->env->from = mutt_default_from ();
}
if (option (OPTHDRS))
--
2.11.0
signature.asc
Description: PGP signature
