1NOTMUCH-SEXP-QUERIES(7)             notmuch            NOTMUCH-SEXP-QUERIES(7)
2
3
4

NAME

6       notmuch-sexp-queries - s-expression syntax for notmuch queries
7

SYNOPSIS

9       notmuch subcommand --query=sexp [option ...]  -- '(and (to santa) (date
10       december))'
11

DESCRIPTION

13       Notmuch supports an alternative query syntax based on  S-expressions  .
14       It  can  be selected with the command line --query=sexp or with the ap‐
15       propriate option to the library function notmuch_query_create_with_syn‐
16       tax().   Support for this syntax is currently optional, you can test if
17       your build of notmuch supports it with
18
19          $ notmuch config get built_with.sexp_queries
20
21   S-EXPRESSIONS
22       An s-expression is either an atom,  or  list  of  whitespace  delimited
23       s-expressions inside parentheses. Atoms are either
24
25       basic value
26          A basic value is an unquoted string containing no whitespace, double
27          quotes, or parentheses.
28
29       quoted string
30          Double quotes (") delimit strings possibly containing whitespace  or
31          parentheses.  These  can contain double quote characters by escaping
32          with backslash. E.g. "this is a quote \"".
33
34   S-EXPRESSION QUERIES
35       An s-expression query is either an atom, the empty list, or a  compound
36       query  consisting  of  a  prefix atom (first element) defining a field,
37       logical operation, or modifier, and 0 or more subqueries.
38
39       *
40          "*" matches any non-empty string in the current field.
41
42       ()
43          The empty list matches all messages
44
45       term
46          Match all messages  containing  term,  possibly  after  stemming  or
47          phrase   splitting.  For  discussion  of  stemming  in  notmuch  see
48          notmuch-search-terms. Stemming only applies to unquoted terms (basic
49          values)  in  s-expression queries.  For information on phrase split‐
50          ting see FIELDS.
51
52       ( field q1 q2 ... qn )
53          Restrict the queries q1 to qn to field, and combine  with  and  (for
54          most fields) or or. See FIELDS for more information.
55
56       ( operator q1 q2 ... qn )
57          Combine queries q1 to qn. Currently supported operators are and, or,
58          and not. (not q1 ... qn ) is equivalent to (and (not q1 )  ...  (not
59          qn )).
60
61       ( modifier q1 q2 ... qn )
62          Combine queries q1 to qn, and reinterpret the result (e.g. as a reg‐
63          ular expression).  See MODIFIERS for more information.
64
65       (macro ( p1 ... pn ) body)
66          Define saved query with parameter substitution. The syntax is recog‐
67          nized   only   in   saved  s-expression  queries  (see  squery.*  in
68          notmuch-config). Parameter names in body must be prefixed with ,  to
69          be expanded (see MACRO EXAMPLES).  Macros may refer to other macros,
70          but only to their own parameters [1].
71
72   FIELDS
73       Fields [2] correspond to attributes of mail messages. Some are inherent
74       (and  immutable)  like  subject, while others tag and property are set‐
75       table by the user.  Each concrete field in the table below is discussed
76       further  under  "Search prefixes" in notmuch-search-terms. The row user
77       refers to user defined fields, described in notmuch-config.
78
79       Most fields are either phrase fields  [3]  (which  match  sequences  of
80       words),  or  term fields [4] (which match exact strings). Phrase split‐
81       ting breaks the term (basic value or quoted string) into words,  ignore
82       punctuation.  Phrase  splitting  is  applied to terms in phrase (proba‐
83       bilistic) fields. Both phrase splitting  and  stemming  apply  only  in
84       phrase fields.
85
86       Each  term or phrase field has an associated combining operator (and or
87       or) used to combine the queries from each element of the  tail  of  the
88       list.  This  is  generally  or for those fields where a message has one
89       such attribute, and and otherwise.
90
91       Term or phrase fields can contain arbitrarily complex queries  made  up
92       from terms, operators, and modifiers, but not other fields.
93
94       Range  fields  take  one  or  two  arguments specifying lower and upper
95       bounds.  One argument is  interpreted  as  identical  upper  and  lower
96       bounds.  Either  upper  or  lower  bound may be specified as "" or * to
97       specify the lowest possible  lower  bound  or  highest  possible  upper
98       bound.
99
100   Fields with supported modifiers
101             ┌───────────┬─────────┬────────┬────────┬──────────┬───────┐
102             │field      │ combine │ type   │ expand │ wildcard │ regex │
103             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
104none       │ and     │        │ no     │ yes      │ no    │
105             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
106user       │ and     │ phrase │ no     │ yes      │ no    │
107             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
108             │attachment │ and     │ phrase │ yes    │ yes      │ no    │
109             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
110             │body       │ and     │ phrase │ no     │ no       │ no    │
111             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
112             │date       │         │ range  │ no     │ no       │ no    │
113             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
114             │folder     │ or      │ phrase │ yes    │ yes      │ yes   │
115             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
116             │from       │ and     │ phrase │ yes    │ yes      │ yes   │
117             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
118             │id         │ or      │ term   │ no     │ yes      │ yes   │
119             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
120             │is         │ and     │ term   │ yes    │ yes      │ yes   │
121             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
122             │lastmod    │         │ range  │ no     │ no       │ no    │
123             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
124             │mid        │ or      │ term   │ no     │ yes      │ yes   │
125             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
126             │mimetype   │ or      │ phrase │ yes    │ yes      │ no    │
127             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
128             │path       │ or      │ term   │ no     │ yes      │ yes   │
129             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
130             │property   │ and     │ term   │ yes    │ yes      │ yes   │
131             └───────────┴─────────┴────────┴────────┴──────────┴───────┘
132
133             │subject    │ and     │ phrase │ yes    │ yes      │ yes   │
134             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
135             │tag        │ and     │ term   │ yes    │ yes      │ yes   │
136             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
137             │thread     │ or      │ term   │ yes    │ yes      │ yes   │
138             ├───────────┼─────────┼────────┼────────┼──────────┼───────┤
139             │to         │ and     │ phrase │ yes    │ yes      │ no    │
140             └───────────┴─────────┴────────┴────────┴──────────┴───────┘
141
142   MODIFIERS
143       Modifiers  refer  to  any prefixes (first elements of compound queries)
144       that are neither operators nor fields.
145
146       (infix atom )
147          Interpret atom as an infix notmuch query (see notmuch-search-terms).
148          Not supported inside fields.
149
150       (matching q1 q2 ... qn ) (of q1 q2 ... qn  )
151          Match  all  messages  have  the  same values of the current field as
152          those matching all of q1 ... qn.  Supported  in  most  term  [7]  or
153          phrase fields. Most commonly used in the thread field.
154
155       (query atom )
156          Expand  to  the  saved  query  named by atom. See notmuch-config for
157          more. Note  that  the  saved  query  must  be  in  infix  syntax  (‐
158          notmuch-search-terms). Not supported inside fields.
159
160       (regex atom ) (rx atom )
161          Interpret  atom as a POSIX.2 regular expression (see regex(7)). This
162          applies in term fields and a subset [5] of phrase fields (see Fields
163          with supported modifiers).
164
165       (starts-with subword )
166          Matches  any  term  starting  with  subword.  This applies in either
167          phrase or term fields,  or  outside  of  fields  [6].  Note  that  a
168          starts-with  query  cannot be part of a phrase. The atom * is a syn‐
169          onym for (starts-with "").
170

EXAMPLES

172       Wizard
173          Match all messages containing the word "wizard", ignoring case.
174
175       added
176          Match all messages containing "added",  but  also  those  containing
177          "add", "additional", "Additional", "adds", etc... via stemming.
178
179       (and Bob Marley)
180          Match  messages  containing words "Bob" and "Marley", or their stems
181          The words need not be adjacent.
182
183       (not Bob Marley)
184          Match messages containing neither  "Bob"  nor  "Marley",  nor  their
185          stems.
186
187       "quick fox" quick-fox quick@fox
188          Match the phrase "quick" followed by "fox" in phrase fields (or out‐
189          side a field). Match the literal string in a term field.
190
191       (folder (of (id 1234@invalid)))
192          Match any message in the same folder  as  the  one  with  Message-Id
193          "1234@invalid".
194
195       (id 1234@invalid blah@test)
196          Matches Message-Id "1234@invalid" or Message-Id "blah@test".
197
198       (and (infix "date:2009-11-18..2009-11-18") (tag unread))
199          Match messages in the given date range with tag unread.
200
201       (and (date 2009-11-18 2009-11-18) (tag unread))
202          Match messages in the given date range with tag unread.
203
204       (and (date 2009-11-18 *) (tag unread))
205          Match messages from 2009-11-18 or later with tag unread.
206
207       (and (date * 2009-11-18) (tag unread))
208          Match messages from 2009-11-18 or earlier with tag unread.
209
210       (starts-with prelim)
211          Match any words starting with "prelim".
212
213       (subject quick "brown fox")
214          Match  messages  whose  subject contains "quick" (anywhere, stemmed)
215          and the phrase "brown fox".
216
217       (subject (starts-with prelim))
218          Matches any word starting with "prelim", inside a message subject.
219
220       (subject (starts-wih quick) "brown fox")
221          Match messages whose subject contains "quick brown  fox",  but  also
222          "brown fox quicksand".
223
224       (thread (of (id 1234@invalid)))
225          Match  any  message  in  the  same thread as the one with Message-Id
226          "1234@invalid".
227
228       (thread (matching (from bob@example.com) (to bob@example.com)))
229          Match any (messages in) a thread containing a message from  "bob@ex‐
230          ample.com" and a (possibly distinct) message to "bob@example.com".
231
232       (to  (or bob@example.com mallory@example.org)) (or (to bob@example.com)
233       (to mallory@example.org))
234          Match in the "To" or "Cc" headers, "bob@example.com", "mallory@exam‐
235          ple.org",  and also "bob@example.com.au" since it contains the adja‐
236          cent triple "bob", "example", "com".
237
238       (not (to *))
239          Match messages with an empty or invalid 'To' and 'Cc' field.
240
241       (List *)
242          Match messages with a non-empty List-Id header, assuming  configura‐
243          tion index.header.List=List-Id.
244
245   MACRO EXAMPLES
246       A macro that takes two parameters and applies different fields to them.
247
248          $ notmuch config set squery.TagSubject '(macro (tagname subj) (and (tag ,tagname) (subject ,subj)))'
249          $ notmuch search --query=sexp '(TagSubject inbox maildir)'
250
251       Nested macros are allowed.
252
253          $ notmuch config set squery.Inner '(macro (x) (subject ,x))'
254          $ notmuch config set squery.Outer  '(macro (x y) (and (tag ,x) (Inner ,y)))'
255          $ notmuch search --query=sexp '(Outer inbox maildir)'
256
257       Parameters  can  be re-used to reduce boilerplate. Any field, including
258       user defined fields is permitted within a macro.
259
260          $ notmuch config set squery.About '(macro (name) (or (subject ,name) (List ,name)))'
261          $ notmuch search --query=sexp '(About notmuch)'
262

NOTES

264       [1]  Technically macros impliment lazy evaluation  and  lexical  scope.
265            There is one top level scope containing all macro definitions, but
266            all parameter definitions are local to a given macro.
267
268       [2]  a.k.a. prefixes
269
270       [3]  a.k.a. probabilistic prefixes
271
272       [4]  a.k.a. boolean prefixes
273
274       [5]  Due to the implemention of phrase fields in Xapian, regex  queries
275            could only match individual words.
276
277       [6]  Due  the  the way body is implemented in notmuch, this modifier is
278            not supported in the body field.
279
280       [7]  Due to the way recursive path queries are implemented in  notmuch,
281            this modifier is not supported in the path field.
282

AUTHOR

284       Carl Worth and many others
285
287       2009-2022, Carl Worth and many others
288
289
290
291
2920.37                             Aug 22, 2022          NOTMUCH-SEXP-QUERIES(7)
Impressum