1NOTMUCH-SEARCH-TERMS(7)             notmuch            NOTMUCH-SEARCH-TERMS(7)
2
3
4

NAME

6       notmuch-search-terms - syntax for notmuch queries
7

SYNOPSIS

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

DESCRIPTION

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 as well as any
73              other tag values added manually with notmuch-tag.
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
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 notmuch-search
150              to find messages that have changed since an earlier query.
151
152       query:<name>
153              The query: prefix allows queries to refer  to  previously  saved
154              queries added with notmuch-config.
155
156       property:<key>=<value>
157              The  property:  prefix  searches  for messages with a particular
158              <key>=<value> property pair. Properties are used  internally  by
159              notmuch  (and  extensions)  to add metadata to messages. A given
160              key can be present on a given  message  with  several  different
161              values.  See notmuch-properties for more details.
162
163       sexp:<subquery>
164              The  sexp:  prefix allows subqueries in the format documented in
165              notmuch-sexp-queries. Note  that  subqueries  containing  spaces
166              must  be  quoted, and any embedded double quotes must be escaped
167              (see Quoting).
168
169       User defined prefixes are also supported, see  notmuch-config  for  de‐
170       tails.
171
172   Operators
173       In  addition  to  individual terms, multiple terms can be combined with
174       Boolean operators (and, or, not, and xor). Each term in the query  will
175       be  implicitly  connected  by  a logical AND if no explicit operator is
176       provided (except that terms with a common  prefix  will  be  implicitly
177       combined  with  OR).   The  shorthand  '-<term>'  can  be used for 'not
178       <term>' but unfortunately this does not work at the start of an expres‐
179       sion.   Parentheses  can also be used to control the combination of the
180       Boolean operators, but will have to be protected from interpretation by
181       the shell, (such as by putting quotation marks around any parenthesized
182       expression).
183
184       In addition to the standard boolean operators, Xapian provides  several
185       operators specific to text searching.
186
187          notmuch search term1 NEAR term2
188
189       will  return  results  where  term1  is  within  10 words of term2. The
190       threshold can be set like this:
191
192          notmuch search term1 NEAR/2 term2
193
194       The search
195
196          notmuch search term1 ADJ term2
197
198       will return results where term1 is within 10 words of term2, but in the
199       same  order  as in the query. The threshold can be set the same as with
200       NEAR:
201
202          notmuch search term1 ADJ/7 term2
203
204   Stemming
205       Stemming in notmuch means that these searches
206
207          notmuch search detailed
208          notmuch search details
209          notmuch search detail
210
211       will all return identical results, because Xapian first  "reduces"  the
212       term to the common stem (here 'detail') and then performs the search.
213
214       There  are  two  ways to turn this off: a search for a capitalized word
215       will be performed unstemmed, so that one can search for "John" and  not
216       get  results for "Johnson"; phrase searches are also unstemmed (see be‐
217       low for details).  Stemming is currently only  supported  for  English.
218       Searches for words in other languages will be performed unstemmed.
219
220   Wildcards
221       It  is  possible  to  use  a  trailing  '*' as a wildcard. A search for
222       'wildc*' will match 'wildcard', 'wildcat', etc.
223
224   Boolean and Probabilistic Prefixes
225       Xapian (and hence notmuch) prefixes are either boolean, supporting  ex‐
226       act matches like "tag:inbox" or probabilistic, supporting a more flexi‐
227       ble term based searching. Certain special  prefixes  are  processed  by
228       notmuch  in  a  way  not  strictly  fitting either of Xapian's built in
229       styles. The prefixes currently supported by notmuch are as follows.
230
231       Boolean
232              tag:, id:, thread:, folder:, path:, property:
233
234       Probabilistic
235              body:, to:, attachment:, mimetype:
236
237       Special
238              from:, query:, subject:, sexp:
239
240   Terms and phrases
241       In general Xapian distinguishes between lists  of  terms  and  phrases.
242       Phrases are indicated by double quotes (but beware you probably need to
243       protect those from your shell) and insist that  those  unstemmed  words
244       occur  in  that  order. One useful, but initially surprising feature is
245       that the following are equivalent ways to write the same phrase.
246
247       • "a list of words"
248
249       • a-list-of-words
250
251       • a/list/of/words
252
253       • a.list.of.words
254
255       Both parenthesised lists of terms and quoted phrases are ok with proba‐
256       bilistic  prefixes such as to:, from:, and subject:.  For prefixes sup‐
257       porting regex search, the parenthesised list should be quoted.  In par‐
258       ticular
259
260          subject:"(pizza free)"
261
262       is equivalent to
263
264          subject:pizza and subject:free
265
266       Both of these will match a subject "Free Delicious Pizza" while
267
268          subject:"pizza free"
269
270       will not.
271
272   Quoting
273       Double  quotes  are  also  used  by the notmuch query parser to protect
274       boolean terms, regular expressions, or subqueries containing spaces  or
275       other special characters, e.g.
276
277          tag:"a tag"
278
279          folder:"/^.*/(Junk|Spam)$/"
280
281          thread:"{from:mallory and date:2009}"
282
283       As  with  phrases, you need to protect the double quotes from the shell
284       e.g.
285
286          % notmuch search 'folder:"/^.*/(Junk|Spam)$/"'
287          % notmuch search 'thread:"{from:mallory and date:2009}" and thread:{to:mallory}'
288
289       Double quotes within query strings need to be doubled to escape them.
290
291          % notmuch search 'tag:"""quoted tag"""'
292          % notmuch search 'sexp:"(or ""wizard"" ""php"")"'
293
295       notmuch understands a variety of standard and natural ways of  express‐
296       ing dates and times, both in absolute terms ("2012-10-24") and in rela‐
297       tive terms ("yesterday"). Any number of relative terms can be  combined
298       ("1  hour  25  minutes") and an absolute date/time can be combined with
299       relative terms to further adjust it. A  non-exhaustive  description  of
300       the syntax supported for absolute and relative terms is given below.
301
302   The range expression
303       date:<since>..<until>
304
305       The  above  expression  restricts  the  results  to  only messages from
306       <since> to <until>, based on the Date: header.
307
308       <since> and <until> can describe imprecise times, such as  "yesterday".
309       In  this  case, <since> is taken as the earliest time it could describe
310       (the beginning of yesterday) and <until> is taken as the latest time it
311       could  describe (the end of yesterday). Similarly, date:january..febru‐
312       ary matches from the beginning of January to the end of February.
313
314       If specifying a time range using timestamps  in  conjunction  with  the
315       date  prefix,  each  timestamp must be preceded by @ (ASCII hex 40). As
316       above, each timestamp is a number representing the  number  of  seconds
317       since 1970-01-01 00:00:00 UTC. For example:
318          date:@<initial-timestamp>..@<final-timestamp>
319
320       Currently,  spaces  in range expressions are not supported. You can re‐
321       place the spaces with '_', or (in most cases) '-', or (in  some  cases)
322       leave  the  spaces out altogether. Examples in this man page use spaces
323       for clarity.
324
325       Open-ended  ranges  are  supported.  I.e.  it's  possible  to   specify
326       date:..<until>  or  date:<since>..  to not limit the start or end time,
327       respectively.
328
329   Single expression
330       date:<expr> works as a shorthand for date:<expr>..<expr>.  For example,
331       date:monday  matches from the beginning of Monday until the end of Mon‐
332       day.
333
334   Relative date and time
335       [N|number]         (years|months|weeks|days|hours|hrs|minutes|mins|sec‐
336       onds|secs) [...]
337
338       All refer to past, can be repeated and will be accumulated.
339
340       Units  can  be  abbreviated to any length, with the otherwise ambiguous
341       single m being m for minutes and M for months.
342
343       Number can also be written out one, two, ..., ten, dozen, hundred.  Ad‐
344       ditionally,  the  unit may be preceded by "last" or "this" (e.g., "last
345       week" or "this month").
346
347       When combined with absolute date and time, the relative date  and  time
348       specification  will  be  relative  from the specified absolute date and
349       time.
350
351       Examples: 5M2d, two weeks
352
353   Supported absolute time formats
354       • H[H]:MM[:SS] [(am|a.m.|pm|p.m.)]
355
356       • H[H] (am|a.m.|pm|p.m.)
357
358       • HHMMSS
359
360       • now
361
362       • noon
363
364       • midnight
365
366       • Examples: 17:05, 5pm
367
368   Supported absolute date formats
369       • YYYY-MM[-DD]
370
371       • DD-MM[-[YY]YY]
372
373       • MM-YYYY
374
375       • M[M]/D[D][/[YY]YY]
376
377       • M[M]/YYYY
378
379       • D[D].M[M][.[YY]YY]
380
381       • D[D][(st|nd|rd|th)] Mon[thname] [YYYY]
382
383       • Mon[thname] D[D][(st|nd|rd|th)] [YYYY]
384
385       • Wee[kday]
386
387       Month names can be abbreviated at three or more characters.
388
389       Weekday names can be abbreviated at three or more characters.
390
391       Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
392
393   Time zones
394       • (+|-)HH:MM
395
396       • (+|-)HH[MM]
397
398       Some time zone codes, e.g. UTC, EET.
399

SEE ALSO

401       notmuch, notmuch-config,  notmuch-count,  notmuch-dump,  notmuch-hooks,
402       notmuch-insert,   notmuch-new,   notmuch-properties,   notmuch-reindex,
403       notmuch-reply,    notmuch-restore,    notmuch-search,     notmuch-show,
404       notmuch-tag
405

AUTHOR

407       Carl Worth and many others
408
410       2009-2023, Carl Worth and many others
411
412
413
414
4150.37                             Jan 19, 2023          NOTMUCH-SEARCH-TERMS(7)
Impressum