]> git.cworth.org Git - notmuch-wiki/blob - howto.mdwn
Hm, ikiwikis markdown did not honor my code block... here we go again...
[notmuch-wiki] / howto.mdwn
1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2 #How to...
3
4 Some tips about how to do some useful things with notmuch, and the
5 various "third party" notmuch utilities.
6
7 * <span id="receive_mail">**Receive mail**</span>
8
9   Notmuch requires either [maildir
10   flag](http://cr.yp.to/proto/maildir.html) or a "mh"-style
11   maildirectory to operate on.  Basically any setup in which each mail
12   is in a file of its own will work.  Here are some generally
13   well-regarded mail retrieval tools:
14
15   * [offlineimap](https://github.com/nicolas33/offlineimap/) -
16     quite useful and widely tested, it also offers a handy hook that
17     will come in useful a bit later in our setup.  Also supports
18     "presynchook" and "postsynchook" command that will get run
19     whenever you sync.  Point _postsynchook_ to a script that gets run
20     on every sync and that will do the automatic updating and tagging
21     of your notmuch database.
22
23   * [mbsync](http://isync.sourceforge.net/)
24
25   * [getmail](http://pyropus.ca/software/getmail/)
26
27   * [fetchmail](http://fetchmail.berlios.de/)
28
29   See the [[initial_tagging]] page for more info on intial tagging of messages.
30
31 * <span id="print_filenames">**Print only filenames of a search (python bindings)**</span>
32
33   Notmuch includes python bindings to the notmuch shared
34   library. Extensive API documentation [is
35   available](http://notmuchmail.readthedocs.org/).
36
37   The bindings are very simple to use.  As an example, given you have
38   the python bindings installed (or simply set your PYTHONPATH
39   environment variable to point to the .../bindings/python directory),
40   this script will print the filenames of a matching search:
41
42           >>> import notmuch
43           >>> db = notmuch.Database()
44           >>> query = db.create_query('tag:inbox AND NOT tag:killed')
45           >>> list(query.search_messages()) # doctest:+ELLIPSIS
46           [...]
47
48 * <span id="sync_maildir_flags">**Sync notmuch tags and maildir flags**</span>
49
50   notmuch **since version 0.5** syncs maildir flags and respective
51   tags in both directions. This part applies only to notmuch prior to
52   version 0.5:
53
54   Some IMAP users rely on maildir flags that convey the status "seen",
55   "replied", "trashed", in order to synchronize the status of their
56   mail across mail clients (a [maildir
57   flag](http://cr.yp.to/proto/maildir.html) is simply a defined part
58   of their filename).  Notmuch will by default happily ignore those
59   flags and will never modify them either, as there is no built-in
60   support for synchronizing your notmuch tags with your imap maildir
61   flags (seen, replied, trashed, etc). However there are currently 2
62   ways in which you can achieve synchronization.
63
64   [notmuchsync](http://spaetz.github.com/notmuchsync/) is a utility
65   (based on the cnotmuch python bindings) that allows synchronization
66   in either direction, as well as pruning of deleted files.
67
68   The second solution allows for fast maildir flag to notmuch tag
69   synchronization (and only in that direction) requires patching the
70   notmuch source code. The patch has been posted in this mail
71   *id:1267450136-31749-1-git-send-email-Sebastian@SSpaeth.de* and can
72   be viewed as a [source diff in this git
73   repository](http://github.com/spaetz/notmuch-all-feature/commit/df3b087cefb85e9d16fd17540e348bcb854dd7ee).
74
75 * <span id="print_filenames">**Using notmuch with Mutt**</span>
76
77   Notmuch is a great mail indexing tool that can also be used *in conjunction*
78   with existing Mail User Agents (MUA) instead of replacing them. The advantage
79   of such mixed solutions is that users can benefit from notmuch features (such
80   as full-text search and thread reconstruction) without *having to* change
81   MUA.
82
83   A popular geek MUA is [the Mutt e-mail client](http://www.mutt.org);
84   integrating notmuch with Mutt is fairly straightforward. An
85   [**how to use Notmuch with Mutt**](http://upsilon.cc/~zack/blog/posts/2011/01/how_to_use_Notmuch_with_Mutt/)
86   has been written by Stefano Zacchiroli, together with some glue code. Check
87   out the
88   [howto](http://upsilon.cc/~zack/blog/posts/2011/01/how_to_use_Notmuch_with_Mutt/)
89   for more information.
90
91   <small>(Note by the howto author: I've linked the howto from this wiki rather
92   than splicing it in, in order to avoid duplication of information. If you
93   think it would be better to have it here, feel free to copy the text
94   here. The howto is
95   [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)
96   in markdown syntax from the Git repository of my homepage.)</small>
97
98 * <span id="reapply_auto">**Automatically retagging the database (e.g., when upgrading versions)**</span>
99
100   Certain versions of notmuch include new automatic tags (for example, between
101   0.3 and 0.10, automatic tagging of signed and encrypted messages was added).
102   However, for users running with databases created in older versions of
103   notmuch, these tags are missing in pre-existing messages and need to be
104   added.  One way to do this is as follows:
105
106                            $ notmuch dump ~/out.nm
107                            $ mv ~/Mail/.notmuch ~/.notmuch.bak
108                            $ notmuch new
109                            $ notmuch tag -inbox -unread '*'
110                            $ notmuch restore --accumulate ~/out.nm
111
112   At this point, one should run a sanity check on the tags, and if everything
113   has merged correctly, the ~/.notmuch.bak directory is expendable, as is
114   ~/out.nm.
115
116 * <span id="nbox">**Dealing with mbox and other formats**</span>
117
118   notmuch by itself is unable to handle non-maildir mail archives.  One tool
119   to solve this is called mb2md.  Assuming an mbox in ~/test.mbox and ones
120   mail archives to be in ~/Mail, an invocation would look like
121
122                            $ mb2md -s ~/test.mbox -d ~/Mail/mynewmaildirname
123
124   Note that specifying the paths for -s and -d is necessary.  This will create
125   a new maildir in ~/Mail/mynewmaildirname from the mbox at ~/test.mbox.
126
127   Often the formats are more convoluted, however.  Many lists provide an
128   almost-but-not-quite-mbox format that mailman produces, as can be seen, for
129   example, [here](http://lists.xapian.org/pipermail/xapian-devel/).  These
130   files can be converted with some degree of success to mbox using the script
131   found
132   [here](http://www.hermann-uwe.de/blog/converting-mailman-gzipd-text-archive-files-to-proper-mbox-files),
133   and from mbox to maildir as above.
134
135   However, many of these lists also have a gmane version, which, where it
136   exists, achieves far better results than dealing with the messy mailman
137   output.  Using the instructions from [Gmane's
138   site](http://gmane.org/export.php), we can download an mbox file, which we
139   can then convert to maildir using mb2md or other utility.