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