7

I would like to replicate GMail's "Filter Messages Like These" feature. Basically, I'm hoping to bind a key in mutt, such as *, and that can "Limit" displayed messages to those sent by the same sender (or senders if prefixed with ;)

macro index * "<enter-command>set sender=display-address<enter><limit>$sender<enter>" "Filter Messages Like"

I am trying the macro approach above, but struggling to read the sender address into a variable in mutt. Is macro the right way to go here? and what's the correct way to read message headers into variables?

Meitham
  • 203

2 Answers2

3

Unfortunately it's not possible to populate variable from function. Even if You're able to call function <display-address> :push @, :exec display-address or using lua in neomutt – it's displayed in the bottom bar, but variable stays empty.

After consulting this issue today on #neomutt IRC the best option right now is using temporary file.

  • This macro will pipe message to formail which returns the from header, passes it to awk to get the e-mail address only and redirects output to /tmp/sender
  • set variable $my_sender with content of the /tmp/sender
  • limit index with the $my_sender
macro index,pager * \
"<pipe-message>formail -X from:|awk -F'[<>]' '{print $2}'>/tmp/sender<enter>\
:set my_sender=\"`cat /tmp/sender`\"\n\
l~f \"$my_sender\"\n" \
"Filter Messages Like"

Requirements: formail

or you can use any other command to parse e-mail address from the message.


EDIT: works only once per neomutt session. There's probably issue with variable expansion inside macro since it is in doublequotes and it has to be this way. So it's still probably not possible, at least easily.

Jakub Jindra
  • 1,462
1

This answer is based on Jakub Jindra's answer. Unfortunately, I didn't have enough reputation to post it as a comment to his correct answer but I thought this might help others who encounter the same issue.

This is a workaround to his macro that can fix the problem of one time expansion:

macro index,pager k "<pipe-message>formail -X from:|awk -F'[<>]' '{print \"set my_tmp_pipe_decode=\\\"\"$2\"\\\"\" }'>/tmp/sender<enter>:source /tmp/sender<enter>l~f $my_tmp_pipe_decode<enter>" "Filter Messages Like"

The main difference is instead of cating the file, I tried to source it. In this way, you will not have the variable expansion problem and it works as many times as you want in one session. Apparently, source is not an onetime expansion compared to cat since it's an internal mutt command however, cat is an external bash command which should be expanded.

Again the credit should go to Jakub Jindra.

ExistMe
  • 126