A simple CLI tool written in Go for searching your mails in a MUA like neomutt or mutt using the notmuch mail indexer.
The idea is based on the
original version of the mutt-notmuch
script and mutt-notmuch-py. The
implementation in Go is - for large search results - significantly faster.
go install github.com/timorunge/notmuch2maildir/cmd/notmuch2maildir@latestDownload pre-built binaries for your platform from the releases page.
git clone https://github.com/timorunge/notmuch2maildir.git
cd notmuch2maildir
make buildFor the usage it's required that notmuch itself is in your $PATH (or use
--notmuch-executable to specify the path).
Search your mail:
notmuch2maildir "from:alice subject:meeting"Reconstruct a full thread from a message:
notmuch2maildir -t -m "<message-id>"notmuch2maildir - Search mail and reconstruct threads using notmuch
Usage:
notmuch2maildir [OPTIONS] QUERY
notmuch2maildir -p
notmuch2maildir -t -m <message-id>
notmuch2maildir -t < email.eml
Options:
-t, --thread Thread mode: reconstruct a full mail thread
-p, --prompt Open a prompt to enter the search query
-m, --message-id string Message-ID for thread reconstruction
--notmuch-config string notmuch configuration file (default: notmuch's own resolution)
--output-dir string Output directory for search results (default "$XDG_CACHE_HOME/notmuch/search_results")
--notmuch-executable string Path to notmuch binary (default "notmuch")
-h, --help Show this help message
--version Show the version of notmuch2maildir
By default, notmuch2maildir lets notmuch resolve its own configuration using its built-in search order:
--notmuch-configflag (passed through asnotmuch --config)NOTMUCH_CONFIGenvironment variable$XDG_CONFIG_HOME/notmuch/<profile>/config(ordefaultif no profile)$HOME/.notmuch-config
Most users don't need --notmuch-config at all.
Search mode is the default. Pass your query as positional arguments:
notmuch2maildir "from:alice subject:meeting"
notmuch2maildir from:bob date:2024..Use -- to separate queries that start with a dash:
notmuch2maildir -- -tag:spam from:aliceUse -p / --prompt for interactive input:
notmuch2maildir -pThread mode (-t / --thread) reconstructs a full mail thread. Provide the
message-id via -m or pipe a mail to stdin:
notmuch2maildir -t -m "<message-id>"
notmuch2maildir -t < email.emlChoose the interactive or the query mode and add the following snippets to your
muttrc.
macro index / "<enter-command>unset wait_key<enter><shell-escape>notmuch2maildir -p<enter><change-folder-readonly>~/.cache/notmuch/search_results<enter>" \
"Search mail (using notmuch)"
macro index / "<enter-command>unset wait_key<enter><shell-escape>read -p 'Search query: ' query; notmuch2maildir \$query<enter><change-folder-readonly>~/.cache/notmuch/search_results<enter>" \
"Search mail (using notmuch)"
macro index T "<enter-command>unset wait_key<enter><pipe-message>notmuch2maildir -t<enter><change-folder-readonly>~/.cache/notmuch/search_results<enter>" \
"Search and reconstruct thread (Using notmuch)"
make help # Show all available targets
make check # Run all quality gates (fmt, tidy, vet, lint, test)
make lint # Run golangci-lint
make test # Run tests with race detector
make build # Build static binary