Set a mutt configuration value based on the output of a script?

1

I've found a bug in mutt, but would like to build a workaround until it can be fixed.

~ (the mark-message function) is supposed to assign a shortcut (i.e., a macro) to mark a message so that you can jump to it later. For instance, if you mark a message with the shortcut d, mutt will automatically set the following macro:

macro index "'d" "<search>~i '[Message-ID Header]'" "message hotkey"

so that you can hit 'd to jump back to the message you marked.

The problem is that the Message-ID header is interpreted as a regular expression, and sometimes the headers of messages I receive contain special regex characters, like +. (See example below.)

<CAMMr2knNGWssaFdp-+e4u9pWfBQ4DCHNkH9FUrPoXqEXAN+sNg@mail.gmail.com>

If they do, then mutt fails to find the message, and so the macro doesn't work, and simply throws the error Not found..

The solution would be to backslash-escape those special characters, but I don't believe there's a way to do that natively in mutt. What I'd like to do is basically build my own substitute for the mark-message function. I'm thinking I'd need to pipe the given message to a script, grep and cut to extract the Message-ID header, and then sed to backslash-escape any special characters.

The problem is trying to pass this string back to mutt: I know you can use environment variables in muttrc, but I believe those are evaluated upon assignment, and not on execution. Is there any way to get the string from a bash script back into mutt's configuration?

Ryan Lue

Posted 2017-06-10T09:07:26.907

Reputation: 393

Just a workaround, might be a bit more expensive resources-wise: try using =h "Message-ID: <CAMMr2knNGWssaFdp-+e4u9pWfBQ4DCHNkH9FUrPoXqEXAN+sNg@mail.gmail.com>" (don't know how to adapt it to your macro, sorry, you'll have to figure that out) – SΛLVΘ – 2017-06-10T12:03:59.473

=h is a good idea, but figuring out how to adapt it to this situation is exactly what I'm asking about. There are multiple ways to find the right message; it's getting the header out of it and into a config command that's the hard part... – Ryan Lue – 2017-06-11T13:31:25.360

No answers