]> git.notmuchmail.org Git - notmuch-wiki/blob - howto.mdwn
reference the new notmuch-mutt page
[notmuch-wiki] / howto.mdwn
1 # How to...
2
3 Some tips about how to do some useful things with notmuch, and the
4 various "third party" notmuch utilities.
5
6 [[!toc levels=2]]
7
8 ## <span id="debian_packages">**Debian squeeze packages outdated**</span>
9
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/).
13
14 ## <span id="receive_mail">**Receive mail**</span>
15
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
18 below.
19
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:
27
28 * [offlineimap](http://offlineimap.org/) -
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.
35
36 * [mbsync](http://isync.sourceforge.net/)
37
38 * [getmail](http://pyropus.ca/software/getmail/)
39
40 * [fetchmail](http://fetchmail.berlios.de/)
41
42 See the [[initial_tagging]] page for more info on initial tagging of
43 messages.
44
45 ## <span id="sync_maildir_flags">**Sync notmuch tags and maildir flags**</span>
46
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:
52
53         $ notmuch config set maildir.synchronize_flags false
54
55 The maildir flags may, in turn, be synchronized with IMAP flags by another tool,
56 such as offlineimap.
57
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.
62
63 ## <span id="python">**Use notmuch from python**</span>
64
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/).
68
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
73 expression:
74
75         >>> import notmuch
76         >>> db = notmuch.Database()
77         >>> query = db.create_query('tag:inbox AND NOT tag:killed')
78         >>> list(query.search_messages()) # doctest:+ELLIPSIS
79         [...]
80
81 ## <span id="print_filenames">**Using notmuch with Mutt**</span>
82
83 See [[notmuch-mutt]].
84
85 ## <span id="reapply_auto">**Automatically retagging the database (e.g., when upgrading versions)**</span>
86
87 Certain versions of notmuch include new automatic tags (for example, between
88 0.3 and 0.10, automatic tagging of signed and encrypted messages was added).
89 However, for users running with databases created in older versions of
90 notmuch, these tags are missing in pre-existing messages and need to be
91 added.  One way to do this is as follows:
92
93         $ notmuch dump --output=~/out.nm
94         $ mv ~/Mail/.notmuch ~/.notmuch.bak
95         $ notmuch new
96         $ notmuch tag -inbox -unread '*'
97         $ notmuch restore --accumulate --input=~/out.nm
98
99 At this point, one should run a sanity check on the tags, and if everything
100 has merged correctly, the ~/.notmuch.bak directory is expendable, as is
101 ~/out.nm.
102
103 ## <span id="mbox">**Dealing with mbox and other formats**</span>
104
105 notmuch by itself is unable to handle non-maildir mail archives.  One tool
106 to solve this is called mb2md.  Assuming an mbox in ~/test.mbox and ones
107 mail archives to be in ~/Mail, an invocation would look like
108
109         $ mb2md -s ~/test.mbox -d ~/Mail/mynewmaildirname
110
111 Note that specifying the paths for -s and -d is necessary.  This will create
112 a new maildir in ~/Mail/mynewmaildirname from the mbox at ~/test.mbox.
113
114 Often the formats are more convoluted, however.  Many lists provide an
115 almost-but-not-quite-mbox format that mailman produces, as can be seen, for
116 example, [here](http://lists.xapian.org/pipermail/xapian-devel/).  These
117 files can be converted with some degree of success to mbox using the script
118 found
119 [here](http://www.hermann-uwe.de/blog/converting-mailman-gzipd-text-archive-files-to-proper-mbox-files),
120 and from mbox to maildir as above.
121
122 However, many of these lists also have a gmane version, which, where it
123 exists, achieves far better results than dealing with the messy mailman
124 output.  Using the instructions from [Gmane's
125 site](http://gmane.org/export.php), we can download an mbox file, which we
126 can then convert to maildir using mb2md or other utility.
127
128 ## <span id="special_tags">**Take advantage of tags that are special to notmuch**</span>
129
130 See [[tags special to notmuch|special-tags]].