Difference between revisions of "Notmuch"

From ArchWiki
Jump to: navigation, search
m (Link to Sup)
m (Neomutt: fix instructions)
 
(45 intermediate revisions by 23 users not shown)
Line 1: Line 1:
[[Category:Email Client]]
+
[[Category:Email clients]]
{{Article summary start}}
+
[[ja:Notmuch]]
{{Article summary text|This article explains how to install and configure notmuch.}}
+
{{Related articles start}}
{{Article summary heading|Related}}
+
{{Related|mutt}}
{{Article summary wiki|mutt}}
+
{{Related articles end}}
{{Article summary end}}
 
  
[http://notmuchmail.org/ Notmuch] is a mail indexer. Essentially, is a very thin front end on top of [[xapian]].
+
[http://notmuchmail.org/ Notmuch] is a mail indexer. Essentially, is a very thin front end on top of ''xapian''.
 
Much like [[Sup]], it focuses on one thing: indexing your email messages. Notmuch can be used as an email reader, or simply as an indexer and search tool for other MUAs, like [[mutt]].
 
Much like [[Sup]], it focuses on one thing: indexing your email messages. Notmuch can be used as an email reader, or simply as an indexer and search tool for other MUAs, like [[mutt]].
  
Line 12: Line 11:
 
Notmuch is written in C and an order of magnitude faster than sup-mail.
 
Notmuch is written in C and an order of magnitude faster than sup-mail.
 
Notmuch can be terminated during the indexing process, on the next run it will continue where it left off.
 
Notmuch can be terminated during the indexing process, on the next run it will continue where it left off.
Also like sup-mail, it does not provide a way to permanently delete unwanted email messages.
+
Also like sup-mail, it does not provide a way to permanently delete unwanted email messages (however, see [[#Permanently delete emails]]).
It doesn't fetch or send mails, nor does it store your email addresses, you'll need to use programs like [[offlineimap]], [[msmtp]] and [[abook]] for those tasks.
+
It doesn't fetch or send mails, nor does it store your email addresses, you'll need to use programs like [[OfflineIMAP]], [[msmtp]] and ''abook'' for those tasks.
  
Notmuch is available from [[AUR]]: notmuch [https://aur.archlinux.org/packages.php?ID=36289] or notmuch-git [https://aur.archlinux.org/packages.php?ID=32399]
+
Notmuch is available in the [[official repositories]]: {{Pkg|notmuch}} or {{AUR|notmuch-git}}{{Broken package link|package not found}} from the [[AUR]]
  
 
It provides [[python]], [[vim]], and [[emacs]] bindings.
 
It provides [[python]], [[vim]], and [[emacs]] bindings.
Line 38: Line 37:
  
 
===alot===
 
===alot===
alot is a standalone CLI interface for notmuch, written in python. It is available from [[AUR]]:
+
alot is a standalone CLI interface for notmuch, written in python. It is available from [[AUR]] as {{AUR|alot}} or {{AUR|alot-git}}.
  
alot [https://aur.archlinux.org/packages.php?ID=51503]
+
Alot uses [[wikipedia:Mailcap|mailcap]] for handling different kinds of files. This currently includes html mails, which means that you need to configure a {{Ic|~/.mailcap}} file in order to view html mails. As minimum, put this line into your {{Ic|~/.mailcap}}:
  
alot-git [https://aur.archlinux.org/packages.php?ID=54955]
+
  text/html; w3m -dump -o -document_charset=%{charset} %s; nametemplate=%s.html; copiousoutput
 +
 
 +
This uses {{Pkg|w3m}}, some other text based clients such as {{Pkg|links}} or {{Pkg|lynx}} can be used instead, although their arguments might differ.
  
Alot uses [[mailcap]] for handling different kinds of files. This currently includes html mails, which means that you need to configure a ~/.mailcap file in order to view html mails. As minimum, put this line into your ~/.mailcap:
 
text/html; w3m -dump %s; nametemplate=%s.html; copiousoutput
 
 
More file handlers can be configured of course.
 
More file handlers can be configured of course.
  
 
===bower===
 
===bower===
bower[https://github.com/wangp/bower] is another CLI interface, this one is written in Mercury[http://www.mercury.csse.unimelb.edu.au/].
+
[https://github.com/wangp/bower bower] is another CLI interface, this one is written in [https://mercurylang.org/ Mercury]. It is available from [[AUR]] as {{AUR|bower-mail}}.
 +
 
 +
===Neomutt===
 +
[http://www.neomutt.org/ Neomutt] - Another mutt fork which includes many feature patches, among them the [http://www.neomutt.org/feature/notmuch Notmuch] integration patch. Install the {{Pkg|neomutt}} or the {{AUR|neomutt-git}} package.
 +
 
 +
===astroid===
 +
 
 +
[https://github.com/astroidmail/astroid Astroid] is a graphical MUA and interface to notmuch written using C++ and GTK+. {{AUR|astroid}} (stable) and {{AUR|astroid-git}} (VCS) packages are available in [[AUR]]. The GUI is designed to be very fast, preview HTML and attachments, be navigable by keyboard. It is extensively configurable and you use your favorite editor either embedded or launch it externally. Check out the [https://github.com/astroidmail/astroid/wiki Tour] to see how astroid can be used and for a description of the complete setup, or check out the [https://github.com/astroidmail/astroid README] for more information.
  
 
===ner===
 
===ner===
ner - notmuch email reader [http://the-ner.org/] is yet another CLI interface, apparently written in C++.
+
 
 +
{{Note|Ner does not seem to be actively developed anymore. The latest commit on github is from May 2012.}}
 +
 
 +
[https://github.com/pioto/ner ner] - notmuch email reader - is yet another CLI interface, apparently written in C++.
 +
 
 +
{{AUR|ner-git}}{{Broken package link|{{aur-mirror|ner-git}}}} is available from the [[AUR]].
  
 
==Integrating with mutt==
 
==Integrating with mutt==
If you use [[mutt]] as your MUA, then notmuch is an excellent complementary tool to index and search your mail. A script to integrate notmuch with mutt, notmuch-mutt, is now included upstream in {{ic|/contrib/notmuch-mutt}}.  
+
If you use [[mutt]] as your MUA, then notmuch is an excellent complementary tool to index and search your mail. The {{Pkg|notmuch-mutt}} package provides a script to integrate notmuch with mutt.
  
This [http://jasonwryan.com/blog/2012/05/23/notmuch/ blogpost] steps through how to setup notmuch with mutt.
+
After installing the {{Pkg|notmuch-mutt}} package and configuring notmuch, the only thing left before using notmuch to search from mutt is adding keybindings to call the <code>notmuch-mutt</code> perl script from mutt. Adding the following to your <code>.muttrc</code> is what is recommended in notmuch contrib source:
 +
 
 +
macro index <F8> \
 +
      "<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 <F9> \
 +
      "<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"
 +
macro index <F6> \
 +
      "<enter-command>unset wait_key<enter><pipe-message>notmuch-mutt tag -inbox<enter>" \
 +
      "notmuch: remove message from inbox"
 +
 
 +
The above uses <code>F8</code> to search your inbox using notmuch, <code>F9</code> to create threads from search results, and <code>F6</code> to tag search results.
 +
 
 +
===notmuch-mutt problems===
 +
There can sometimes be disagreement between pacman-installed and managed perl modules and perl modules installed via cpan/cpanm. An error message of the format:
 +
Gnu.c: loadable library and perl binaries are mismatched (got handshake key 0xdb00080, needed 0xdb80080)
 +
can indicate that some of the notmuch-mutt dependencies are installed via cpan while some are installed and managed via pacman, and that you should install all dependencies via one or the other method.
 +
 
 +
==Integrating with NeoMutt ==
 +
 
 +
If you use {{Pkg|neomutt}}, the {{Pkg|notmuch-mutt}} package is not required. Instead, create a {{Ic|~/.mailboxes}} with some basic (virtual) mailboxes. A virtual mailbox is not an actual folder, but the result of a notmuch query for a specific tag:
 +
{{hc|~/.mailboxes|2=
 +
virtual-mailboxes "inbox" "notmuch://?query=tag:inbox"
 +
virtual-mailboxes "archive" "notmuch://?query=tag:archive"
 +
virtual-mailboxes "sent" "notmuch://?query=tag:sent"
 +
virtual-mailboxes "newsletters" "notmuch://?query=tag:newsletters"
 +
}}
 +
Next, make mutt aware of your virtual mailboxes by enabling virtual spoolfile and sourcing the latter:
 +
{{hc|~/.muttrc|2=
 +
set virtual_spoolfile=yes
 +
source ~/.mailboxes
 +
}}
 +
At this point, mutt will still list your mailboxes as empty, because your mails are not yet tagged and thus, notmuch querys are empty. To fill your virtual mailboxes, you need to initially tag the messages in your maildir. A very simple approach is to create a shell script like the following:
 +
{{hc|~/.scripts/notmuch-hook.sh|2=
 +
#!/bin/sh
 +
notmuch new
 +
# retag all "new" messages "inbox" and "unread"
 +
notmuch tag +inbox +unread -new -- tag:new
 +
# tag all messages from "me" as sent and remove tags inbox and unread
 +
notmuch tag -new -inbox +sent -- from:me@example.org or from:me@myself.com
 +
# tag newsletters, but dont show them in inbox
 +
notmuch tag +newsletters +unread -new -- from:newsletter@example.org or subject:'newsletter*'
 +
}}
 +
Make the shell script executable and run it:
 +
  chmod +x ~/.scripts/notmuch-hook.sh
 +
  ~/.scripts/notmuch-hook.sh
 +
For the above example to work, make sure that notmuch tags new messages as 'new':
 +
{{hc|~/.notmuch-config|2=
 +
[new]
 +
tags=new
 +
}}
 +
Finally, your hook script needs to rerun on new mail arrival. If you use {{Pkg|offlineimap}} to sync IMAP to a local maildir, create a post sync hook:
 +
{{hc|~/.offlineimaprc|2=
 +
[Account myaccount]
 +
postsynchook = ~/.scripts/notmuch-hook.sh
 +
}}
 +
Some useful key bindings:
 +
{{hc|~/.muttrc|2=
 +
macro index A "<modify-labels>+archive -unread -inbox\\n" "Archive message"
 +
macro index c "<change-vfolder>?" "Change to vfolder overview"
 +
macro index \\\\ "<vfolder-from-query>" "Search mailbox"
 +
}}
 +
 
 +
==Permanently delete emails==
 +
 
 +
One choice is to maintain a tag of emails you wish to remove from your disk, for example, "killed". Then, you can run this to delete them permanently:
 +
  notmuch search --output=files tag:killed | xargs -r rm
 +
  notmuch new

Latest revision as of 07:38, 30 October 2017

Notmuch is a mail indexer. Essentially, is a very thin front end on top of xapian. Much like Sup, it focuses on one thing: indexing your email messages. Notmuch can be used as an email reader, or simply as an indexer and search tool for other MUAs, like mutt.

Overview

Notmuch is written in C and an order of magnitude faster than sup-mail. Notmuch can be terminated during the indexing process, on the next run it will continue where it left off. Also like sup-mail, it does not provide a way to permanently delete unwanted email messages (however, see #Permanently delete emails). It doesn't fetch or send mails, nor does it store your email addresses, you'll need to use programs like OfflineIMAP, msmtp and abook for those tasks.

Notmuch is available in the official repositories: notmuch or notmuch-gitAUR[broken link: package not found] from the AUR

It provides python, vim, and emacs bindings.

First time Usage

After installation, you enter an interactive setup by running:

 notmuch setup

The program prompts you for the location of your maildir and your primary and secondary email addresses. You can also edit the config file directly which is created by default at $HOME/.notmuch-config.

Subsequent re-indexing of the mail directories is done with:

 notmuch new

Frontends

There are a range of ways to use notmuch, including cli, or with one of the Unix $EDITORS:

Emacs

The default frontend for notmuch is Emacs. It is developed by the same people that develop notmuch.

Vim

There's a vim interface available and included in notmuch. To start it, type:

vim -c NotMuch

alot

alot is a standalone CLI interface for notmuch, written in python. It is available from AUR as alotAUR or alot-gitAUR.

Alot uses mailcap for handling different kinds of files. This currently includes html mails, which means that you need to configure a ~/.mailcap file in order to view html mails. As minimum, put this line into your ~/.mailcap:

 text/html; w3m -dump -o -document_charset=%{charset} %s; nametemplate=%s.html; copiousoutput

This uses w3m, some other text based clients such as links or lynx can be used instead, although their arguments might differ.

More file handlers can be configured of course.

bower

bower is another CLI interface, this one is written in Mercury. It is available from AUR as bower-mailAUR.

Neomutt

Neomutt - Another mutt fork which includes many feature patches, among them the Notmuch integration patch. Install the neomutt or the neomutt-gitAUR package.

astroid

Astroid is a graphical MUA and interface to notmuch written using C++ and GTK+. astroidAUR (stable) and astroid-gitAUR (VCS) packages are available in AUR. The GUI is designed to be very fast, preview HTML and attachments, be navigable by keyboard. It is extensively configurable and you use your favorite editor either embedded or launch it externally. Check out the Tour to see how astroid can be used and for a description of the complete setup, or check out the README for more information.

ner

Note: Ner does not seem to be actively developed anymore. The latest commit on github is from May 2012.

ner - notmuch email reader - is yet another CLI interface, apparently written in C++.

ner-gitAUR[broken link: archived in aur-mirror] is available from the AUR.

Integrating with mutt

If you use mutt as your MUA, then notmuch is an excellent complementary tool to index and search your mail. The notmuch-mutt package provides a script to integrate notmuch with mutt.

After installing the notmuch-mutt package and configuring notmuch, the only thing left before using notmuch to search from mutt is adding keybindings to call the notmuch-mutt perl script from mutt. Adding the following to your .muttrc is what is recommended in notmuch contrib source:

macro index <F8> \
     "<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 <F9> \
     "<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"
macro index <F6> \
     "<enter-command>unset wait_key<enter><pipe-message>notmuch-mutt tag -inbox<enter>" \
     "notmuch: remove message from inbox"

The above uses F8 to search your inbox using notmuch, F9 to create threads from search results, and F6 to tag search results.

notmuch-mutt problems

There can sometimes be disagreement between pacman-installed and managed perl modules and perl modules installed via cpan/cpanm. An error message of the format:

Gnu.c: loadable library and perl binaries are mismatched (got handshake key 0xdb00080, needed 0xdb80080)

can indicate that some of the notmuch-mutt dependencies are installed via cpan while some are installed and managed via pacman, and that you should install all dependencies via one or the other method.

Integrating with NeoMutt

If you use neomutt, the notmuch-mutt package is not required. Instead, create a ~/.mailboxes with some basic (virtual) mailboxes. A virtual mailbox is not an actual folder, but the result of a notmuch query for a specific tag:

~/.mailboxes
virtual-mailboxes "inbox" "notmuch://?query=tag:inbox"
virtual-mailboxes "archive" "notmuch://?query=tag:archive"
virtual-mailboxes "sent" "notmuch://?query=tag:sent"
virtual-mailboxes "newsletters" "notmuch://?query=tag:newsletters"

Next, make mutt aware of your virtual mailboxes by enabling virtual spoolfile and sourcing the latter:

~/.muttrc
set virtual_spoolfile=yes
source ~/.mailboxes

At this point, mutt will still list your mailboxes as empty, because your mails are not yet tagged and thus, notmuch querys are empty. To fill your virtual mailboxes, you need to initially tag the messages in your maildir. A very simple approach is to create a shell script like the following:

~/.scripts/notmuch-hook.sh
#!/bin/sh
notmuch new
# retag all "new" messages "inbox" and "unread"
notmuch tag +inbox +unread -new -- tag:new
# tag all messages from "me" as sent and remove tags inbox and unread
notmuch tag -new -inbox +sent -- from:me@example.org or from:me@myself.com
# tag newsletters, but dont show them in inbox
notmuch tag +newsletters +unread -new -- from:newsletter@example.org or subject:'newsletter*'

Make the shell script executable and run it:

 chmod +x ~/.scripts/notmuch-hook.sh
 ~/.scripts/notmuch-hook.sh

For the above example to work, make sure that notmuch tags new messages as 'new':

~/.notmuch-config
[new]
tags=new

Finally, your hook script needs to rerun on new mail arrival. If you use offlineimap to sync IMAP to a local maildir, create a post sync hook:

~/.offlineimaprc
[Account myaccount]
postsynchook = ~/.scripts/notmuch-hook.sh

Some useful key bindings:

~/.muttrc
macro index A "<modify-labels>+archive -unread -inbox\\n" "Archive message"
macro index c "<change-vfolder>?" "Change to vfolder overview"
macro index \\\\ "<vfolder-from-query>" "Search mailbox"

Permanently delete emails

One choice is to maintain a tag of emails you wish to remove from your disk, for example, "killed". Then, you can run this to delete them permanently:

 notmuch search --output=files tag:killed | xargs -r rm
 notmuch new