Re: Directing replies based on contents of To: header; was: How to match a string like '+447537170394 <[email protected]>' in a send hook?

Chris Green <[email protected]>
Newsgroups gmane.mail.mutt.user
Message-ID <ZvQd-m_6mCYR9-YW@q957>
On Wed, Sep 25, 2024 at 12:43:36PM +0000, Michael Kjörling wrote:
> On 25 Sep 2024 12:11 +0100, from [email protected] (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 <[email protected]>' 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 <[email protected]>
> > 
> > I want replies (i.e. the To: header) to go to:-
> > 
> >     To: Fred Bloggs <[email protected]>
> > 
> > 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@sms\.example\.net>$
>   {
>   :0 fW
>     | formail -f -i "Reply-To: Fred Bloggs <[email protected]>"
>   :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.
> 
I'm not using procmail or anything similar, my mail is delivered
direct to my system by SMTP and I use postfix as my mail server.

I do have a custom python script, called from my .forward, that does
some procmail-like processing so I suppose I can add the header
changing code to that.

I'm surprised that there's no easy way to do it with mutt though.


-- 
Chris Green
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.