1NOTMUCH-SEARCH-TERMS(7) notmuch NOTMUCH-SEARCH-TERMS(7)
2
3
4
6 notmuch-search-terms - syntax for notmuch queries
7
9 notmuch count [option ...] <search-term> ...
10
11 notmuch dump [--gzip] [--format=(batch-tag|sup)] [--output=<file>] [--]
12 [<search-term> ...]
13
14 notmuch reindex [option ...] <search-term> ...
15
16 notmuch search [option ...] <search-term> ...
17
18 notmuch show [option ...] <search-term> ...
19
20 notmuch tag +<tag> ... -<tag> [--] <search-term> ...
21
23 Several notmuch commands accept a common syntax for search terms.
24
25 The search terms can consist of free-form text (and quoted phrases)
26 which will match all messages that contain all of the given
27 terms/phrases in the body, the subject, or any of the sender or recipi‐
28 ent headers.
29
30 As a special case, a search string consisting of exactly a single
31 asterisk ("*") will match all messages.
32
33 Search prefixes
34 In addition to free text, the following prefixes can be used to force
35 terms to match against specific portions of an email, (where <brackets>
36 indicate user-supplied values).
37
38 If notmuch is built with Xapian Field Processors (see below) some of
39 the prefixes with <regex> forms can be also used to restrict the
40 results to those whose value matches a regular expression (see
41 regex(7)) delimited with //, for example:
42
43 notmuch search 'from:"/bob@.*[.]example[.]com/"'
44
45 body:<word-or-quoted-phrase>
46 Match terms in the body of messages.
47
48 from:<name-or-address> or from:/<regex>/
49 The from: prefix is used to match the name or address of the
50 sender of an email message.
51
52 to:<name-or-address>
53 The to: prefix is used to match the names or addresses of any
54 recipient of an email message, (whether To, Cc, or Bcc).
55
56 subject:<word-or-quoted-phrase> or subject:/<regex>/
57 Any term prefixed with subject: will match only text from the
58 subject of an email. Searching for a phrase in the subject is
59 supported by including quotation marks around the phrase, imme‐
60 diately following subject:.
61
62 attachment:<word>
63 The attachment: prefix can be used to search for specific file‐
64 names (or extensions) of attachments to email messages.
65
66 mimetype:<word>
67 The mimetype: prefix will be used to match text from the con‐
68 tent-types of MIME parts within email messages (as specified by
69 the sender).
70
71 tag:<tag> or tag:/<regex>/ or is:<tag> or is:/<regex>/
72 For tag: and is: valid tag values include inbox and unread by
73 default for new messages added by notmuch new as well as any
74 other tag values added manually with notmuch tag.
75
76 id:<message-id> or mid:<message-id> or mid:/<regex>/
77 For id: and mid:, message ID values are the literal contents of
78 the Message-ID: header of email messages, but without the '<',
79 '>' delimiters.
80
81 thread:<thread-id>
82 The thread: prefix can be used with the thread ID values that
83 are generated internally by notmuch (and do not appear in email
84 messages). These thread ID values can be seen in the first col‐
85 umn of output from notmuch search
86
87 thread:{<notmuch query>}
88 If notmuch is built with Xapian Field Processors (see below),
89 threads may be searched for indirectly by providing an arbitrary
90 notmuch query in {}. For example, the following returns threads
91 containing a message from mallory and one (not necessarily the
92 same message) with Subject containing the word "crypto".
93
94 % notmuch search 'thread:"{from:mallory}" and thread:"{subject:crypto}"'
95
96 The performance of such queries can vary wildly. To understand
97 this, the user should think of the query thread:{<something>} as
98 expanding to all of the thread IDs which match <something>; not‐
99 much then performs a second search using the expanded query.
100
101 path:<directory-path> or path:<directory-path>/** or path:/<regex>/
102 The path: prefix searches for email messages that are in partic‐
103 ular directories within the mail store. The directory must be
104 specified relative to the top-level maildir (and without the
105 leading slash). By default, path: matches messages in the speci‐
106 fied directory only. The "/**" suffix can be used to match mes‐
107 sages in the specified directory and all its subdirectories
108 recursively. path:"" matches messages in the root of the mail
109 store and, likewise, path:** matches all messages.
110
111 path: will find a message if any copy of that message is in the
112 specific directory.
113
114 folder:<maildir-folder> or folder:/<regex>/
115 The folder: prefix searches for email messages by maildir or MH
116 folder. For MH-style folders, this is equivalent to path:. For
117 maildir, this includes messages in the "new" and "cur" subdirec‐
118 tories. The exact syntax for maildir folders depends on your
119 mail configuration. For maildir++, folder:"" matches the inbox
120 folder (which is the root in maildir++), other folder names
121 always start with ".", and nested folders are separated by "."s,
122 such as folder:.classes.topology. For "file system" maildir, the
123 inbox is typically folder:INBOX and nested folders are separated
124 by slashes, such as folder:classes/topology.
125
126 folder: will find a message if any copy of that message is in
127 the specific folder.
128
129 date:<since>..<until> or date:<date>
130 The date: prefix can be used to restrict the results to only
131 messages within a particular time range (based on the Date:
132 header).
133
134 See DATE AND TIME SEARCH below for details on the range expres‐
135 sion, and supported syntax for <since> and <until> date and time
136 expressions.
137
138 The time range can also be specified using timestamps without
139 including the date prefix using a syntax of:
140
141 <initial-timestamp>..<final-timestamp>
142
143 Each timestamp is a number representing the number of seconds
144 since 1970-01-01 00:00:00 UTC. Specifying a time range this way
145 is considered legacy and predates the date prefix.
146
147 lastmod:<initial-revision>..<final-revision>
148 The lastmod: prefix can be used to restrict the result by the
149 database revision number of when messages were last modified
150 (tags were added/removed or filenames changed). This is usually
151 used in conjunction with the --uuid argument to notmuch search
152 to find messages that have changed since an earlier query.
153
154 query:<name>
155 The query: prefix allows queries to refer to previously saved
156 queries added with notmuch-config(1). Named queries are only
157 available if notmuch is built with Xapian Field Processors (see
158 below).
159
160 property:<key>=<value>
161 The property: prefix searches for messages with a particular
162 <key>=<value> property pair. Properties are used internally by
163 notmuch (and extensions) to add metadata to messages. A given
164 key can be present on a given message with several different
165 values. See notmuch-properties(7) for more details.
166
167 User defined prefixes are also supported, see notmuch-config(1) for
168 details.
169
170 Operators
171 In addition to individual terms, multiple terms can be combined with
172 Boolean operators (and, or, not, and xor). Each term in the query will
173 be implicitly connected by a logical AND if no explicit operator is
174 provided (except that terms with a common prefix will be implicitly
175 combined with OR). The shorthand '-<term>' can be used for 'not
176 <term>' but unfortunately this does not work at the start of an expres‐
177 sion. Parentheses can also be used to control the combination of the
178 Boolean operators, but will have to be protected from interpretation by
179 the shell, (such as by putting quotation marks around any parenthesized
180 expression).
181
182 In addition to the standard boolean operators, Xapian provides several
183 operators specific to text searching.
184
185 notmuch search term1 NEAR term2
186
187 will return results where term1 is within 10 words of term2. The
188 threshold can be set like this:
189
190 notmuch search term1 NEAR/2 term2
191
192 The search
193
194 notmuch search term1 ADJ term2
195
196 will return results where term1 is within 10 words of term2, but in the
197 same order as in the query. The threshold can be set the same as with
198 NEAR:
199
200 notmuch search term1 ADJ/7 term2
201
202 Stemming
203 Stemming in notmuch means that these searches
204
205 notmuch search detailed
206 notmuch search details
207 notmuch search detail
208
209 will all return identical results, because Xapian first "reduces" the
210 term to the common stem (here 'detail') and then performs the search.
211
212 There are two ways to turn this off: a search for a capitalized word
213 will be performed unstemmed, so that one can search for "John" and not
214 get results for "Johnson"; phrase searches are also unstemmed (see
215 below for details). Stemming is currently only supported for English.
216 Searches for words in other languages will be performed unstemmed.
217
218 Wildcards
219 It is possible to use a trailing '*' as a wildcard. A search for
220 'wildc*' will match 'wildcard', 'wildcat', etc.
221
222 Boolean and Probabilistic Prefixes
223 Xapian (and hence notmuch) prefixes are either boolean, supporting
224 exact matches like "tag:inbox" or probabilistic, supporting a more
225 flexible term based searching. Certain special prefixes are processed
226 by notmuch in a way not strictly fitting either of Xapian's built in
227 styles. The prefixes currently supported by notmuch are as follows.
228
229 Boolean
230 tag:, id:, thread:, folder:, path:, property:
231
232 Probabilistic
233 body:, to:, attachment:, mimetype:
234
235 Special
236 from:, query:, subject:
237
238 Terms and phrases
239 In general Xapian distinguishes between lists of terms and phrases.
240 Phrases are indicated by double quotes (but beware you probably need to
241 protect those from your shell) and insist that those unstemmed words
242 occur in that order. One useful, but initially surprising feature is
243 that the following are equivalent ways to write the same phrase.
244
245 · "a list of words"
246
247 · a-list-of-words
248
249 · a/list/of/words
250
251 · a.list.of.words
252
253 Both parenthesised lists of terms and quoted phrases are ok with proba‐
254 bilistic prefixes such as to:, from:, and subject:. In particular
255
256 subject:(pizza free)
257
258 is equivalent to
259
260 subject:pizza and subject:free
261
262 Both of these will match a subject "Free Delicious Pizza" while
263
264 subject:"pizza free"
265
266 will not.
267
268 Quoting
269 Double quotes are also used by the notmuch query parser to protect
270 boolean terms, regular expressions, or subqueries containing spaces or
271 other special characters, e.g.
272
273 tag:"a tag"
274
275 folder:"/^.*/(Junk|Spam)$/"
276
277 thread:"{from:mallory and date:2009}"
278
279 As with phrases, you need to protect the double quotes from the shell
280 e.g.
281
282 % notmuch search 'folder:"/^.*/(Junk|Spam)$/"'
283 % notmuch search 'thread:"{from:mallory and date:2009}" and thread:{to:mallory}'
284
286 notmuch understands a variety of standard and natural ways of express‐
287 ing dates and times, both in absolute terms ("2012-10-24") and in rela‐
288 tive terms ("yesterday"). Any number of relative terms can be combined
289 ("1 hour 25 minutes") and an absolute date/time can be combined with
290 relative terms to further adjust it. A non-exhaustive description of
291 the syntax supported for absolute and relative terms is given below.
292
293 The range expression
294 date:<since>..<until>
295
296 The above expression restricts the results to only messages from
297 <since> to <until>, based on the Date: header.
298
299 <since> and <until> can describe imprecise times, such as "yesterday".
300 In this case, <since> is taken as the earliest time it could describe
301 (the beginning of yesterday) and <until> is taken as the latest time it
302 could describe (the end of yesterday). Similarly, date:january..febru‐
303 ary matches from the beginning of January to the end of February.
304
305 If specifying a time range using timestamps in conjunction with the
306 date prefix, each timestamp must be preceded by @ (ASCII hex 40). As
307 above, each timestamp is a number representing the number of seconds
308 since 1970-01-01 00:00:00 UTC. For example:
309 date:@<initial-timestamp>..@<final-timestamp>
310
311 date:<expr>..! can be used as a shorthand for date:<expr>..<expr>. The
312 expansion takes place before interpretation, and thus, for example,
313 date:monday..! matches from the beginning of Monday until the end of
314 Monday. With Xapian Field Processor support (see below), non-range
315 date queries such as date:yesterday will work, but otherwise will give
316 unexpected results; if in doubt use date:yesterday..!
317
318 Currently, we do not support spaces in range expressions. You can
319 replace the spaces with '_', or (in most cases) '-', or (in some cases)
320 leave the spaces out altogether. Examples in this man page use spaces
321 for clarity.
322
323 Open-ended ranges are supported (since Xapian 1.2.1), i.e. it's possi‐
324 ble to specify date:..<until> or date:<since>.. to not limit the start
325 or end time, respectively. Pre-1.2.1 Xapian does not report an error on
326 open ended ranges, but it does not work as expected either.
327
328 Relative date and time
329 [N|number] (years|months|weeks|days|hours|hrs|minutes|mins|sec‐
330 onds|secs) [...]
331
332 All refer to past, can be repeated and will be accumulated.
333
334 Units can be abbreviated to any length, with the otherwise ambiguous
335 single m being m for minutes and M for months.
336
337 Number can also be written out one, two, ..., ten, dozen, hundred.
338 Additionally, the unit may be preceded by "last" or "this" (e.g., "last
339 week" or "this month").
340
341 When combined with absolute date and time, the relative date and time
342 specification will be relative from the specified absolute date and
343 time.
344
345 Examples: 5M2d, two weeks
346
347 Supported absolute time formats
348 · H[H]:MM[:SS] [(am|a.m.|pm|p.m.)]
349
350 · H[H] (am|a.m.|pm|p.m.)
351
352 · HHMMSS
353
354 · now
355
356 · noon
357
358 · midnight
359
360 · Examples: 17:05, 5pm
361
362 Supported absolute date formats
363 · YYYY-MM[-DD]
364
365 · DD-MM[-[YY]YY]
366
367 · MM-YYYY
368
369 · M[M]/D[D][/[YY]YY]
370
371 · M[M]/YYYY
372
373 · D[D].M[M][.[YY]YY]
374
375 · D[D][(st|nd|rd|th)] Mon[thname] [YYYY]
376
377 · Mon[thname] D[D][(st|nd|rd|th)] [YYYY]
378
379 · Wee[kday]
380
381 Month names can be abbreviated at three or more characters.
382
383 Weekday names can be abbreviated at three or more characters.
384
385 Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
386
387 Time zones
388 · (+|-)HH:MM
389
390 · (+|-)HH[MM]
391
392 Some time zone codes, e.g. UTC, EET.
393
395 Certain optional features of the notmuch query processor rely on the
396 presence of the Xapian field processor API. You can determine if your
397 notmuch was built against a sufficiently recent version of Xapian by
398 running
399
400 % notmuch config get built_with.field_processor
401
402 Currently the following features require field processor support:
403
404 · non-range date queries, e.g. "date:today"
405
406 · named queries e.g. "query:my_special_query"
407
408 · regular expression searches, e.g. "subject:/^\[SPAM\]/"
409
410 · thread subqueries, e.g. "thread:{from:bob}"
411
413 notmuch(1), notmuch-config(1), notmuch-count(1), notmuch-dump(1), not‐
414 much-hooks(5), notmuch-insert(1), notmuch-new(1), notmuch-reindex(1),
415 notmuch-properties(1), *notmuch-reply(1), notmuch-restore(1), not‐
416 much-search(1), *notmuch-show(1), notmuch-tag(1)
417
419 Carl Worth and many others
420
422 2009-2020, Carl Worth and many others
423
424
425
426
4270.29.3 Jan 29, 2020 NOTMUCH-SEARCH-TERMS(7)