]> git.cworth.org Git - notmuch-wiki/blob - howto.mdwn
fix link
[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="receive_mail">**Receive mail**</span>
10
11 Notmuch does not fetch mail for you.  For that, you need to use an
12 external mail syncing utility.  Some recommended utilities are listed
13 below.
14
15 Notmuch requires that every individual message be in its own file.
16 The well-supported [maildir](http://cr.yp.to/proto/maildir.html) or
17 "mh"-style storage formats are compatible with notmuch.  Basically any
18 setup in which each mail is in a file of its own will work.  The older
19 mbox mail store formats is not supported, but fortunately it is very
20 easy to [[convert mbox to maildir|howto/#mbox]] .  The following
21 utilities support these formats:
22
23 * [offlineimap](http://offlineimap.org/) -
24   quite useful and widely tested, it also offers a handy hook that
25   will come in useful a bit later in our setup.  Also supports
26   "presynchook" and "postsynchook" command that will get run
27   whenever you sync.  Point _postsynchook_ to a script that gets run
28   on every sync and that will do the automatic updating and tagging
29   of your notmuch database.
30
31 * [mbsync](http://isync.sourceforge.net/)
32
33 * [getmail](http://pyropus.ca/software/getmail/)
34
35 * [fetchmail](http://www.fetchmail.info/)
36
37 * [muchsync](http://www.muchsync.org/) - replicate and synchronize
38   your notmuch database (mail and tags) across machines
39
40 * [lieer](https://github.com/gauteh/lieer) - Fast email-fetching and two-way tag
41   synchronization between notmuch and GMail (Note that lieer was formerly known
42   as gmailieer.)
43
44 * [mujmap](https://github.com/elizagamedev/mujmap/) - synchronize
45   notmuch mail with a JMAP server, i.e. synchronizing tags with keywords
46   and mailboxes. Analogous to lieer, but for [JMAP](https://jmap.io)
47   supporting mail hosts.
48
49 See more exhaustive list of [[software]] notmuch works with and the
50 [[initial_tagging]] page for more info on initial tagging of messages.
51
52
53 ## <span id="send_mail">**Send mail**</span>
54
55 Notmuch does not send your mail. The frontends (MUAs) that utilize notmuch
56 does that. Often these MUAs use sendmail(8) to send your mail.
57
58 If you prefer a simpler solution like msmtp, first
59 [install and configure msmtp](http://msmtp.sourceforge.net/).
60
61 Then create a symbolic link so that msmtp will be called instead of sendmail
62 when you press the keyboard shortcut to send your message.
63
64     $ sudo ln -s /usr/bin/msmtp /usr/sbin/sendmail
65
66
67 ## <span id="sync_maildir_flags">**Sync notmuch tags and maildir flags**</span>
68
69 notmuch has the ability to synchronize maildir flags and respective tags in both
70 directions. For more information on maildir flags see the [maildir
71 page](http://cr.yp.to/proto/maildir.html) and [[Special tags|special-tags]], and for the respective tags see your
72 notmuch configuration file. This feature is enabled by default, but if you don't
73 need it, it is simple to disable it with the 'notmuch config' command:
74
75         $ notmuch config set maildir.synchronize_flags false
76
77 The maildir flags may, in turn, be synchronized with IMAP flags by another tool,
78 such as offlineimap.
79
80 For safety reasons, and because
81 [[notmuch does not support delete operations|deleting]], notmuch does
82 not sync the "trashed" flag.  For discussion on this topic please
83 refer to the mailing list.
84
85 ## <span id="python">**Use notmuch from python**</span>
86
87 See the [[Notmuch Library Language Bindings|bindings]] page.
88
89 ## <span id="print_filenames">**Using notmuch with Mutt**</span>
90
91 See [[notmuch-mutt]].
92
93 ## <span id="reapply_auto">**Automatically retagging the database (e.g., when upgrading versions)**</span>
94
95 Certain versions of notmuch include new automatic tags (for example, between
96 0.3 and 0.10, automatic tagging of signed and encrypted messages was added).
97 However, for users running with databases created in older versions of
98 notmuch, these tags are missing in pre-existing messages and need to be
99 added.  One way to do this is as follows:
100
101         $ notmuch dump --output=$HOME/out.nm
102         $ mv ~/Mail/.notmuch ~/.notmuch.bak
103         $ notmuch new
104         $ notmuch tag -inbox -unread '*'
105         $ notmuch restore --accumulate --input=$HOME/out.nm
106
107 At this point, one should run a sanity check on the tags, and if everything
108 has merged correctly, the ~/.notmuch.bak directory is expendable, as is
109 $HOME/out.nm.
110
111 ## <span id="mbox">**Dealing with mbox and other formats**</span>
112
113 notmuch by itself is unable to handle non-maildir mail archives.  One tool
114 to solve this is called mb2md.  Assuming an mbox in ~/test.mbox and ones
115 mail archives to be in ~/Mail, an invocation would look like
116
117         $ mb2md -s ~/test.mbox -d ~/Mail/mynewmaildirname
118
119 Note that specifying the paths for -s and -d is necessary.  This will create
120 a new maildir in ~/Mail/mynewmaildirname from the mbox at ~/test.mbox.
121
122 Often the formats are more convoluted, however.  Many lists provide an
123 almost-but-not-quite-mbox format that mailman produces, as can be seen, for
124 example, [here](http://lists.xapian.org/pipermail/xapian-devel/).  These
125 files can be converted with some degree of success to mbox using the script
126 found
127 [here](http://www.hermann-uwe.de/blog/converting-mailman-gzipd-text-archive-files-to-proper-mbox-files),
128 and from mbox to maildir as above.
129
130 However, many of these lists also have a gmane version, which, where it
131 exists, achieves far better results than dealing with the messy mailman
132 output.  Using the instructions from [Gmane's
133 site](http://gmane.org/export.php), we can download an mbox file, which we
134 can then convert to maildir using mb2md or other utility.
135
136 Please note that mail delivered by Postfix will have envelope headers
137 that may cause notmuch to complain about "single-message mbox files".
138 Removing the first line from the message or passing it through
139 reformail will solve the problem.
140
141 ## <span id="special_tags">**Take advantage of tags that are special to notmuch**</span>
142
143 See [[tags special to notmuch|special-tags]].
144
145
146 ## <span id="special_tags">**Index all your gpg-encrypted email**</span>
147
148 If you don't mind replacing your encrypted emails with cleartext versions and
149 re-indexing them, there are some scripts that do that at
150 [github](https://github.com/mmehnert/maildir-decrypt) . That would make sense
151 in a scenario where you have encrypted your hard disk anyway and are
152 comfortable with the security implications (and until notmuch can index
153 encrypted email itself).
154
155 ## <span id="special_tags">**Index and search emails written in CJK scripts**</span>
156
157 CJK (Chinese, Japanese and Korean) languages do not use spaces for word
158 separation. The full-text indexer (Xapian) must first perform word segmentation
159 on the sentence in its TermGenerator. Otherwise, large amount of long terms
160 will be included in the database, leading to extremely slow indexing and
161 ineffective searching with CJK search terms.
162
163 Xapian supports [N-gram](https://xapian.org/docs/sourcedoc/html/classXapian_1_1TermGenerator.html)
164 term generator [since 2011](https://u7fa9.org/memo/HEAD/archives/2012-06/2012-06-01.rst)
165 to as a simple substitute for word segmentation. It can be turned on by
166 setting the environment variable
167
168         $ export XAPIAN_CJK_NGRAM=1
169         $ notmuch new
170
171 For existing databases, one can reindex the database (since notmuch 0.26)
172 with
173
174         $ export XAPIAN_CJK_NGRAM=1
175         $ notmuch reindex '*'
176
177 Xapian has an on-going [pull-request](https://github.com/xapian/xapian/pull/114)
178 that adds support for real CJK word-segmentation based on the ICU library.
179 When it gets merged, one probably will gets better indexing and searching
180 results with this new method.
181
182 ## Translations
183
184 - A translation of this page into [[Russian|howto-ru]]