3 Some tips about how to do some useful things with notmuch, and the
4 various "third party" notmuch utilities.
8 ## <span id="debian_packages">**Debian squeeze packages outdated**</span>
10 The notmuch package(s) in Debian squeeze are very old (version 0.3).
11 It's better to start off with an up to date version from
12 [backports](http://backports-master.debian.org/).
14 ## <span id="receive_mail">**Receive mail**</span>
16 Notmuch does not fetch mail for you. For that, you need to use an
17 external mail syncing utility. Some recommended utilities are listed
20 Notmuch requires that every individual message be in it's own file.
21 The well-supported [maildir](http://cr.yp.to/proto/maildir.html) or
22 "mh"-style storage formats are compatible with notmuch. Basically any
23 setup in which each mail is in a file of its own will work. The older
24 mbox mail store formats is not supported, but fortunately it is very
25 easy to [[convert mbox to maildir|howto/#mbox]] . The following
26 utilities support these formats:
28 * [offlineimap](https://github.com/nicolas33/offlineimap/) -
29 quite useful and widely tested, it also offers a handy hook that
30 will come in useful a bit later in our setup. Also supports
31 "presynchook" and "postsynchook" command that will get run
32 whenever you sync. Point _postsynchook_ to a script that gets run
33 on every sync and that will do the automatic updating and tagging
34 of your notmuch database.
36 * [mbsync](http://isync.sourceforge.net/)
38 * [getmail](http://pyropus.ca/software/getmail/)
40 * [fetchmail](http://fetchmail.berlios.de/)
42 See the [[initial_tagging]] page for more info on initial tagging of
45 ## <span id="sync_maildir_flags">**Sync notmuch tags and maildir flags**</span>
47 notmuch has the ability to synchronize maildir flags and respective tags in both
48 directions. For more information on maildir flags see the [maildir
49 page](http://cr.yp.to/proto/maildir.html), and for the respective tags see your
50 notmuch configuration file. This feature is enabled by default, but if you don't
51 need it, it is simple to disable it with the 'notmuch config' command:
53 $ notmuch config set maildir.synchronize_flags false
55 The maildir flags may, in turn, be synchronized with IMAP flags by another tool,
58 For safety reasons, and because
59 [[notmuch does not support delete operations|deleting]], notmuch does
60 not sync the "trashed" flag. For discussion on this topic please
61 refer to the mailing list.
63 ## <span id="python">**Use notmuch from python**</span>
65 Notmuch includes python bindings to the notmuch shared library. Please
66 refer to the nice and extensive
67 [notmuch python API documentation](http://notmuch.readthedocs.org/).
69 The bindings are very simple to use. As an example, given you have
70 the python bindings installed (or simply set your PYTHONPATH
71 environment variable to point to the .../bindings/python directory),
72 this snippet will produce a list of mails matching the given
76 >>> db = notmuch.Database()
77 >>> query = db.create_query('tag:inbox AND NOT tag:killed')
78 >>> list(query.search_messages()) # doctest:+ELLIPSIS
81 ## <span id="print_filenames">**Using notmuch with Mutt**</span>
83 Notmuch is a great mail indexing tool that can also be used *in conjunction*
84 with existing Mail User Agents (MUA) instead of replacing them. The advantage
85 of such mixed solutions is that users can benefit from notmuch features (such
86 as full-text search and thread reconstruction) without *having to* change
89 A popular geek MUA is [the Mutt e-mail client](http://www.mutt.org);
90 integrating notmuch with Mutt is not seamless, but fairly straightforward.
91 There are two principal possibilities, each with its own ups and downs:
93 * Using mutt-notmuch, which will create a "virtual" maildir folder with
94 search results whenever a search is made. The upside is that you can
95 search all your folders simultanously; the downside is that your
96 modifications in the results listing do not carry over, also having
97 to switch folders comes with some more annoyances.
100 [**how to use Notmuch with Mutt**](http://upsilon.cc/~zack/blog/posts/2011/01/how_to_use_Notmuch_with_Mutt/)
101 has been written by Stefano Zacchiroli. Check out the
102 [howto](http://upsilon.cc/~zack/blog/posts/2011/01/how_to_use_Notmuch_with_Mutt/)
103 for more information.
105 <small>(Note by the howto author: I've linked the howto from this wiki rather
106 than splicing it in, in order to avoid duplication of information. If you
107 think it would be better to have it here, feel free to copy the text
109 [available](http://git.upsilon.cc/cgi-bin/gitweb.cgi?p=zack-homepage.git;a=history;f=blog/posts/2011/01/how_to_use_Notmuch_with_Mutt.mdwn)
110 in markdown syntax from the Git repository of my homepage.)</small>
112 * Using a simple macro that will emulate the "limit" mutt functionality
115 See the [**alternative notmuch integration**](http://log.or.cz/?p=228)
116 blog post for instructions and details,
117 or simply put these two macros to your muttrc:
119 # 'L' performs a notmuch query, showing only the results
120 macro index L "<enter-command>unset wait_key<enter><shell-escape>read -p 'notmuch query: ' x; echo \$x >~/.cache/mutt_terms<enter><limit>~i \"\`notmuch search --output=messages \$(cat ~/.cache/mutt_terms) | head -n 600 | perl -le '@a=<>;chomp@a;s/\^id:// for@a;$,=\"|\";print@a'\`\"<enter>" "show only messages matching a notmuch pattern"
121 # 'a' shows all messages again (supersedes default <alias> binding)
122 macro index a "<limit>all\n" "show all messages (undo limit)"
124 The upside (if you are used to working in the context of a single folder)
125 is that this really does use the limit functionality of mutt
126 and you are still in your original folder.
127 The downside is that this approach has scaling problems
128 and works well only for reasonably specific queries.
131 ## <span id="reapply_auto">**Automatically retagging the database (e.g., when upgrading versions)**</span>
133 Certain versions of notmuch include new automatic tags (for example, between
134 0.3 and 0.10, automatic tagging of signed and encrypted messages was added).
135 However, for users running with databases created in older versions of
136 notmuch, these tags are missing in pre-existing messages and need to be
137 added. One way to do this is as follows:
139 $ notmuch dump ~/out.nm
140 $ mv ~/Mail/.notmuch ~/.notmuch.bak
142 $ notmuch tag -inbox -unread '*'
143 $ notmuch restore --accumulate ~/out.nm
145 At this point, one should run a sanity check on the tags, and if everything
146 has merged correctly, the ~/.notmuch.bak directory is expendable, as is
149 ## <span id="mbox">**Dealing with mbox and other formats**</span>
151 notmuch by itself is unable to handle non-maildir mail archives. One tool
152 to solve this is called mb2md. Assuming an mbox in ~/test.mbox and ones
153 mail archives to be in ~/Mail, an invocation would look like
155 $ mb2md -s ~/test.mbox -d ~/Mail/mynewmaildirname
157 Note that specifying the paths for -s and -d is necessary. This will create
158 a new maildir in ~/Mail/mynewmaildirname from the mbox at ~/test.mbox.
160 Often the formats are more convoluted, however. Many lists provide an
161 almost-but-not-quite-mbox format that mailman produces, as can be seen, for
162 example, [here](http://lists.xapian.org/pipermail/xapian-devel/). These
163 files can be converted with some degree of success to mbox using the script
165 [here](http://www.hermann-uwe.de/blog/converting-mailman-gzipd-text-archive-files-to-proper-mbox-files),
166 and from mbox to maildir as above.
168 However, many of these lists also have a gmane version, which, where it
169 exists, achieves far better results than dealing with the messy mailman
170 output. Using the instructions from [Gmane's
171 site](http://gmane.org/export.php), we can download an mbox file, which we
172 can then convert to maildir using mb2md or other utility.
174 ## <span id="special_tags">**Take advantage of tags that are special to notmuch**</span>
176 See [[tags special to notmuch|special-tags]].