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