How to match a string like '+447537170394 <sms at aa.net.uk>' in a send hook?

Chris Green cl at isbd.net
Thu Sep 26 10:21:59 UTC 2024


On Thu, Sep 26, 2024 at 10:29:21AM +0300, Tapani Tarvainen wrote:
> On Wed, Sep 25, 2024 at 12:11:15PM +0100, Chris Green (cl at isbd.net) wrote:
> 
> > 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.
> 
> There doesn't seem to be any clean way to do that with mutt alone.
> 
> One hack that kind of works is
> 
> message-hook . 'unmy_hdr To:'
> message-hook "~f .*447537170394.*" 'my_hdr To: Fred Bloggs <f.bloggs at another.address.co.uk>'
> 
> There are two problems with it:
> 
> First, it doesn't replace the original address, just adds to it,
> which may be acceptable if the original goes to a black hole anyway.
> 
Yes, I managed to cobble something together that does this.  As you
say it just appends the new address to the To: line which would work
but doesn't seem very elegant! :-)


> Second, it only works if you hit Reply when (or after) viewing the
> message, not if you do it directly from the index view.
> 
> What's worse, it will remember the extra address until you view
> another message: if you view a message from 447537170394 and then go
> to the index and reply to another message from there without viewing
> it first, it will remember that extra address. It would probably be
> possible to fix that by unsetting the extra header with some other
> hook, but I don't the time to test that now.
> 
Yes, there's several downsides to this approach.


> An alternative approach, if you use (or could use) $edit_headers,
> would be using your editor to change the To: -header. With a smart
> enough editor (say, emacs) it could automated completely.
> 
I've added some code to my incoming 'filter' program which essentially
does this.  Since it's already looking at headers and sending messages
to appropriate inboxes it's easy enough to get it to look for the
above From: address and then change the To: appropriately.  It's
essentially a home-grown procmail written in Python and called via my
.forward.

Thanks for the help everyone, it does seem to be something that mutt
can't do, unusual! :-)

-- 
Chris Green


More information about the Mutt-users mailing list