Directing replies based on contents of To: header; was: How to match a string like '+447537170394 <sms at aa.net.uk>' in a send hook?
Michael Kjörling
ba47c4919fb5 at ewoof.net
Wed Sep 25 12:43:36 UTC 2024
On 25 Sep 2024 12:11 +0100, from cl at isbd.net (Chris Green):
>> So, next question (which replaces the first one), how can I change a
>> To: header dependent on the contents of the To: header?
>>
>> What I am trying to do is to change the destination address when I get
>> messages from addresses like '+447537170394 <sms at aa.net.uk>' because
>> messages back to that address disappear into a black hole.
>
> To clarify, whhen I get an E-Mail with a From: header like:-
>
> From: +447537170394 <sms at aa.net.uk>
>
> I want replies (i.e. the To: header) to go to:-
>
> To: Fred Bloggs <f.bloggs at another.address.co.uk>
>
> I can't seem to get mutt to do this for me, I'm sure it must be
> possible and, probably, quite easy.
Easiest is probably to inject a Reply-To: header in the original
message based on whatever criteria you need. For example, if you're
using procmail, try something like the following in your procmailrc:
:0
*^From: \+447537170394 <sms at sms\.example\.net>$
{
:0 fW
| formail -f -i "Reply-To: Fred Bloggs <f.bloggs at example.com>"
:0
$DEFAULT
}
The "fW" flags specifies that this rule is a "f"ilter (essentially
re-injects the output of the pipe) and to "W"ait for the process to
complete before continuing. The second rule delivers the message to
the default mailbox which is where it would go in the absence of any
matching filtering rule.
With formail -i (as opposed to -I), any existing similar header will
be renamed with a -Old suffix. See the formail man page.
I have a number of similar rules in my setup and it works like a
charm. The biggest caveat is that procmail operates on the _raw_
message, so for example if the sender name may be surrounded by quotes
or encoded somehow, you need to account for that.
--
Michael Kjörling 🔗 https://michael.kjorling.se
“Remember when, on the Internet, nobody cared that you were a dog?”
More information about the Mutt-users
mailing list