Re: [PATCH] Allow send-hooks to effectively change $from and $use_from
I'm not sure there's a significant use case in here that can't be
solved with my_hdr.
That said, the way in which two pointers to the same ADDRESS
structure are being used here is a recipe for later memory
corruption. Don't do these kinds of things.
Cheers,
--
Thomas Roessler <roessler@xxxxxxxxxxxxxxxxxx>
On 2007-07-08 21:04:34 -0400, Aron Griffis wrote:
> From: Aron Griffis <agriffis@xxxxxxxxx>
> To: mutt-dev@xxxxxxxx
> Date: Sun, 8 Jul 2007 21:04:34 -0400
> Subject: [PATCH] Allow send-hooks to effectively change $from and $use_from
> X-Spam-Level:
> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.1.5
>
> Hi,
>
> This patch modifies ci_send_message() so that send-hooks can modify
> $from and $use_from. This makes it possible for a send-hook to
> provide a fallback address based on the recipient, without overriding
> reverse_name.
>
> Thanks,
> Aron
>
> # HG changeset patch
> # User Aron Griffis <agriffis@xxxxxxxxx>
> # Date 1183941141 14400
> # Branch HEAD
> # Node ID cd46bd8885a00c5b4458a7ff3e5b3766f9a0f045
> # Parent e3eeeb0a37a5fa8b197b8ef28a4ee3a6f22a36ef
> Allow send-hooks to effectively change $from and $use_from
>
> Signed-off-by: Aron Griffis <agriffis@xxxxxxxxx>
>
> diff -r e3eeeb0a37a5 -r cd46bd8885a0 send.c
> --- a/send.c Sun Jul 08 20:31:58 2007 -0400
> +++ b/send.c Sun Jul 08 20:32:21 2007 -0400
> @@ -1092,6 +1092,7 @@ ci_send_message (int flags, /* send mod
> char fcc[_POSIX_PATH_MAX] = ""; /* where to copy this message */
> FILE *tempfp = NULL;
> BODY *pbody;
> + ADDRESS *default_from = NULL;
> int i, killfrom = 0;
> int fcc_error = 0;
> int free_clear_content = 0;
> @@ -1216,7 +1217,7 @@ ci_send_message (int flags, /* send mod
> }
>
> if (!msg->env->from && option (OPTUSEFROM) && !(flags &
> (SENDPOSTPONED|SENDRESEND)))
> - msg->env->from = mutt_default_from ();
> + msg->env->from = default_from = mutt_default_from ();
>
> if (flags & SENDBATCH)
> {
> @@ -1257,10 +1258,7 @@ ci_send_message (int flags, /* send mod
> * after send-hooks are evaulated */
>
> if (!msg->env->from)
> - {
> - msg->env->from = mutt_default_from ();
> - killfrom = 1;
> - }
> + msg->env->from = default_from = mutt_default_from ();
>
> if ((flags & SENDREPLY) && cur)
> {
> @@ -1287,10 +1285,19 @@ ci_send_message (int flags, /* send mod
> */
> msg->replied = 0;
>
> - if (killfrom)
> - {
> - rfc822_free_address (&msg->env->from);
> - killfrom = 0;
> + /* $use_from and/or $from might have changed in a send-hook */
> + if (msg->env->from == default_from)
> + {
> + if (option (OPTUSEFROM))
> + {
> + rfc822_free_address (&msg->env->from);
> + msg->env->from = default_from = mutt_default_from ();
> + }
> + else
> + {
> + rfc822_free_address (&msg->env->from);
> + default_from = NULL;
> + }
> }
>
> if (option (OPTHDRS))
>
>