notmuch
provides a full-text index of maildirs, and can
easily be used from within mutt. The tool itself is available
from https://notmuchmail.org/ (also packaged as notmuch
in most major
distros). You'll also need notmuch-mutt
(which is also packaged in most major
distros, as notmuch-mutt
).
To start using it, first run notmuch setup
.
I use the following cronjobs to generate the index
# Update mail index every 15 minutes
*/15 * * * * notmuch new &> /dev/null
# Remove old search results every morning
11 5 * * * rm -rf "/home/zerodogg/.cache/notmuch/mutt/results"
And the following code in your muttrc, where F7 will do a search and display the results, and F8 will reconstruct a thread from metadata.
macro index <F7> \
"<enter-command>unset wait_key<enter><shell-escape>notmuch-mutt --prompt search<enter><change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter>" \
"notmuch: search mail"
macro index <F8> \
"<enter-command>unset wait_key<enter><pipe-message>notmuch-mutt thread<enter><change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter><enter-command>set wait_key<enter>" \
"notmuch: reconstruct thread"