Search and limit from command line

Jens John lists at 2ion.de
Sat Mar 20 10:11:43 UTC 2021


On Sat, 20 Mar 2021, at 10:42, Julius Hamilton wrote:
> Hello Mutt users,
> 
> I would like to know if there is a way to retrieve a list of emails from
> a particular user at stdout in bash, rather than launching the mutt
> application. Or, if one can launch mutt with the search already
> executed. I currently know how to launch mutt, and then search for a
> particular sender.
> 
> Or, if someone knows commands from a similar tool to achieve this.

Use notmuch.

 $ notmuch search 'from:Julius Hamilton'
thread:0000000000015cd4 25 mins. ago [1/1] Julius Hamilton; Search and limit from command line (inbox unread)

 $ notmuch search --format=json 'from:Julius Hamilton'
[{"thread": "0000000000015cd4", "timestamp": 1616233332, "date_relative": "26 mins. ago", "matched": 1, "total": 1, "authors": "Julius Hamilton", "subject": "Search and limit from command line", "query": ["id:YFXDdAEhEL3NU0sj at localhost", null], "tags": ["inbox", "unread"]}]

I have integrated it with my mutt like so (I fetch email using isync/mbsync instead of using mutt's IMAP support):

macro generic,index,pager <F2>  "<shell-escape>mbsync -a<enter><shell-escape>notmuch new<enter>" "fetch mail"
macro index <F7> \
           "<enter-command>set my_old_pipe_decode=\$pipe_decode my_old_wait_key=\$wait_key nopipe_decode nowait_key<enter>\
           <shell-escape>notmuch-mutt -r --prompt search<enter>\
           <change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter>\
           <enter-command>set pipe_decode=\$my_old_pipe_decode wait_key=\$my_old_wait_key<enter>" \
                 "notmuch: search mail"
macro index <F8> \
"<enter-command>set my_old_pipe_decode=\$pipe_decode my_old_wait_key=\$wait_key nopipe_decode nowait_key<enter>\
<pipe-message>notmuch-mutt -r thread<enter>\
<change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter>\
<enter-command>set pipe_decode=\$my_old_pipe_decode wait_key=\$my_old_wait_key<enter>" \
     "notmuch: reconstruct thread"

Macros given as a reference, not as an example of especially good scripting. I haven't touched or improved these definitions in years.


More information about the Mutt-users mailing list