]> git.cworth.org Git - notmuch-wiki/blob - howto.mdwn
mention muchsync
[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 [[!toc levels=2]]
8
9 ## <span id="debian_packages">**Debian squeeze packages outdated**</span>
10
11 The notmuch package(s) in Debian squeeze are very old (version 0.3).
12 It's better to start off with an up to date version from
13 [backports](http://backports-master.debian.org/).
14
15 ## <span id="receive_mail">**Receive mail**</span>
16
17 Notmuch does not fetch mail for you.  For that, you need to use an
18 external mail syncing utility.  Some recommended utilities are listed
19 below.
20
21 Notmuch requires that every individual message be in it's own file.
22 The well-supported [maildir](http://cr.yp.to/proto/maildir.html) or
23 "mh"-style storage formats are compatible with notmuch.  Basically any
24 setup in which each mail is in a file of its own will work.  The older
25 mbox mail store formats is not supported, but fortunately it is very
26 easy to [[convert mbox to maildir|howto/#mbox]] .  The following
27 utilities support these formats:
28
29 * [offlineimap](http://offlineimap.org/) -
30   quite useful and widely tested, it also offers a handy hook that
31   will come in useful a bit later in our setup.  Also supports
32   "presynchook" and "postsynchook" command that will get run
33   whenever you sync.  Point _postsynchook_ to a script that gets run
34   on every sync and that will do the automatic updating and tagging
35   of your notmuch database.
36
37 * [mbsync](http://isync.sourceforge.net/)
38
39 * [getmail](http://pyropus.ca/software/getmail/)
40
41 * [fetchmail](http://fetchmail.berlios.de/)
42
43 * [muchsync](http://www.muchsync.org/) - replicate and synchronize
44   your notmuch database (mail and tags) across machines
45
46 See the [[initial_tagging]] page for more info on initial tagging of
47 messages.
48
49 ## <span id="sync_maildir_flags">**Sync notmuch tags and maildir flags**</span>
50
51 notmuch has the ability to synchronize maildir flags and respective tags in both
52 directions. For more information on maildir flags see the [maildir
53 page](http://cr.yp.to/proto/maildir.html), and for the respective tags see your
54 notmuch configuration file. This feature is enabled by default, but if you don't
55 need it, it is simple to disable it with the 'notmuch config' command:
56
57         $ notmuch config set maildir.synchronize_flags false
58
59 The maildir flags may, in turn, be synchronized with IMAP flags by another tool,
60 such as offlineimap.
61
62 For safety reasons, and because
63 [[notmuch does not support delete operations|deleting]], notmuch does
64 not sync the "trashed" flag.  For discussion on this topic please
65 refer to the mailing list.
66
67 ## <span id="python">**Use notmuch from python**</span>
68
69 Notmuch includes python bindings to the notmuch shared library. Please
70 refer to the nice and extensive
71 [notmuch python API documentation](http://notmuch.readthedocs.org/).
72
73 The bindings are very simple to use.  As an example, given you have
74 the python bindings installed (or simply set your PYTHONPATH
75 environment variable to point to the .../bindings/python directory),
76 this snippet will produce a list of mails matching the given
77 expression:
78
79         >>> import notmuch
80         >>> db = notmuch.Database()
81         >>> query = db.create_query('tag:inbox AND NOT tag:killed')
82         >>> list(query.search_messages()) # doctest:+ELLIPSIS
83         [...]
84
85 ## <span id="print_filenames">**Using notmuch with Mutt**</span>
86
87 See [[notmuch-mutt]].
88
89 ## <span id="reapply_auto">**Automatically retagging the database (e.g., when upgrading versions)**</span>
90
91 Certain versions of notmuch include new automatic tags (for example, between
92 0.3 and 0.10, automatic tagging of signed and encrypted messages was added).
93 However, for users running with databases created in older versions of
94 notmuch, these tags are missing in pre-existing messages and need to be
95 added.  One way to do this is as follows:
96
97         $ notmuch dump --output=~/out.nm
98         $ mv ~/Mail/.notmuch ~/.notmuch.bak
99         $ notmuch new
100         $ notmuch tag -inbox -unread '*'
101         $ notmuch restore --accumulate --input=~/out.nm
102
103 At this point, one should run a sanity check on the tags, and if everything
104 has merged correctly, the ~/.notmuch.bak directory is expendable, as is
105 ~/out.nm.
106
107 ## <span id="mbox">**Dealing with mbox and other formats**</span>
108
109 notmuch by itself is unable to handle non-maildir mail archives.  One tool
110 to solve this is called mb2md.  Assuming an mbox in ~/test.mbox and ones
111 mail archives to be in ~/Mail, an invocation would look like
112
113         $ mb2md -s ~/test.mbox -d ~/Mail/mynewmaildirname
114
115 Note that specifying the paths for -s and -d is necessary.  This will create
116 a new maildir in ~/Mail/mynewmaildirname from the mbox at ~/test.mbox.
117
118 Often the formats are more convoluted, however.  Many lists provide an
119 almost-but-not-quite-mbox format that mailman produces, as can be seen, for
120 example, [here](http://lists.xapian.org/pipermail/xapian-devel/).  These
121 files can be converted with some degree of success to mbox using the script
122 found
123 [here](http://www.hermann-uwe.de/blog/converting-mailman-gzipd-text-archive-files-to-proper-mbox-files),
124 and from mbox to maildir as above.
125
126 However, many of these lists also have a gmane version, which, where it
127 exists, achieves far better results than dealing with the messy mailman
128 output.  Using the instructions from [Gmane's
129 site](http://gmane.org/export.php), we can download an mbox file, which we
130 can then convert to maildir using mb2md or other utility.
131
132 Please note that mail delivered by Postfix will have envelope headers
133 that may cause notmuch to complain about "single-message mbox files".
134 Removing the first line from the message or passing it through
135 reformail will solve the problem.
136
137 ## <span id="special_tags">**Take advantage of tags that are special to notmuch**</span>
138
139 See [[tags special to notmuch|special-tags]].