Skip to content

Notmuch mail

When is the next run ?

systemctl --user status mbsync.timer

Hooks

Hooks can get installed in ~/mail/Mail/.notmuch/hooks

Show all mails in <${EMAIL}> account:

export EMAIL="me@myself.ai"
notmuch search "path:${EMAIL}/**"
notmuch search path:"${EMAIL}/**" and tag:INBOX

notmuch search "('from:root@*.bitmask.net') AND date:today"

Output formats

Thread as json:

notmuch show id:4898FCAE-B024-41B6-91B7-073F40334815@myself.ai
  --format=json | jq . | less

Single msg as json:

notmuch show --entire-thread=false --format=json \
id:4898FCAE-B024-41B6-91B7-073F40334815@myself.ai | jq . | less

Dump complete mail (only works for single mail, not thread):

notmuch show id:CD2E25DE-8157-4849-A7AB-4B9CBD5B89D7@myself.ai
  --format=raw | gpg -d

List all tags:

notmuch search --output=tags '*'

Notmuch saved queries

See queries:

notmuch config list

Set/modify query:

notmuch config set query.leap "tag:/leap/"
notmuch config set query.moewe "tag:/[Mm]oo/"
notmuch config set query.projects "tag:/CAD|[Mm]oo|leap|LEAP/"
notmuch config set query.to-me "to:${EMAIL} OR to:${EMAIL2} OR …"
notmuch config set query.work "from:/example.org|example.com|…/ OR …"

Extract attachments

mkdir /tmp/ausgaben
cd /tmp/ausgaben
notmuch_extract_attachments.py 'tag:Ausgaben AND date:2014'
find . -iname '*.pdf' -exec cp {} ~/Ausgaben/2014/ \;

Exporting emails to PDF

Using https://www.whitebyte.info/publications/eml-to-pdf-converter

nsh --format=raw id:kcis.E36D427A37F34E1B88E3962CD680520D@kopano > /tmp/email.eml
email2pdf /tmp/email.eml
evince /tmp/email.eml
notmuch_print id:kcis.E36D427A37F34E1B88E3962CD680520D@kopano

Tagging

Turn UPPERCASE to lowercase tag:

notmuch tag -INBOX +inbox id:CANu2KkOr3ryGwMiVvO23OaatxvR432JAzyYwpEdkgbfhye6=Qg@mail.gmail.com
notmuch tag -INBOX +inbox tag:INBOX

re-tag all:

time notmuch tag --remove-all +new -- '*' && time notmuch new

Delete mail

excluding

notmuch search --format=text0 --output=files tag:trash | xargs -0 --no-run-if-empty rm
notmuch new

General issues

  • moving a already imported mail remotely will result in notmuch not recognizing this, and the folder name tag (i.e. 'inbox' will stay) https://www.mail-archive.com/notmuch@notmuchmail.org/msg19164.html the only way is to complely retag all mails with

    time notmuch tag --remove-all +new -- '\*' && time notmuch new

    with the downside that the imap flag tags get lost (i.e. 'unread')

Index cleartext from gpg encrypted mails

Howto:

notmuch show id:20180221175027.27116-1@example.net

Configure notmuch to index new incoming encrypted mails:

notmuch config set index.decrypt true

Reindex old encrypted mails:

notmuch reindex tag:encrypted and not property:index.decryption=success

Search encrypted mails:

notmuch search tag:encrypted

Show mails which failed to get reindex:

notmuch search tag:encrypted and not property:index.decryption=success

Alternative: mu