'\" t .\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "NOTMUCH-SEXP-QUERIES" "7" "Oct 03, 2024" "0.38.3" "notmuch" .SH NAME notmuch-sexp-queries \- s-expression syntax for notmuch queries .SH SYNOPSIS .sp \fBnotmuch\fP \fIsubcommand\fP \fB\-\-query=sexp\fP [option ...] \fB\-\-\fP \(aq(and (to santa) (date december))\(aq .SH DESCRIPTION .sp Notmuch supports an alternative query syntax based on \X'tty: link https://en.wikipedia.org/wiki/S-expression'\fI\%S\-expressions\fP\X'tty: link' . It can be selected with the command line \fB\-\-query=sexp\fP or with the appropriate option to the library function \fBnotmuch_query_create_with_syntax()\fP\&. Support for this syntax is currently optional, you can test if your build of notmuch supports it with .INDENT 0.0 .INDENT 3.5 .sp .EX $ notmuch config get built_with.sexp_queries .EE .UNINDENT .UNINDENT .SS S\-EXPRESSIONS .sp An \fIs\-expression\fP is either an atom, or list of whitespace delimited s\-expressions inside parentheses. Atoms are either .sp \fIbasic value\fP .INDENT 0.0 .INDENT 3.5 A basic value is an unquoted string containing no whitespace, double quotes, or parentheses. .UNINDENT .UNINDENT .sp \fIquoted string\fP .INDENT 0.0 .INDENT 3.5 Double quotes (\(dq) delimit strings possibly containing whitespace or parentheses. These can contain double quote characters by escaping with backslash. E.g. \fB\(dqthis is a quote \e\(dq\(dq\fP\&. .UNINDENT .UNINDENT .SS S\-EXPRESSION QUERIES .sp An s\-expression query is either an atom, the empty list, or a \fIcompound query\fP consisting of a prefix atom (first element) defining a \fIfield\fP, \fIlogical operation\fP, or \fImodifier\fP, and 0 or more subqueries. .sp \fB*\fP .INDENT 0.0 .INDENT 3.5 \(dq*\(dq matches any non\-empty string in the current field. .UNINDENT .UNINDENT .sp \fB()\fP .INDENT 0.0 .INDENT 3.5 The empty list matches all messages .UNINDENT .UNINDENT .sp \fIterm\fP .INDENT 0.0 .INDENT 3.5 Match all messages containing \fIterm\fP, possibly after stemming or phrase splitting. For discussion of stemming in notmuch see \fI\%notmuch\-search\-terms\fP\&. Stemming only applies to unquoted terms (basic values) in s\-expression queries. For information on phrase splitting see \fI\%FIELDS\fP\&. .UNINDENT .UNINDENT .sp \fB(\fP \fIfield\fP \fIq\fP\s-2\d1\u\s0 \fIq\fP\s-2\d2\u\s0 ... \fIq\fP\s-2\dn\u\s0 \fB)\fP .INDENT 0.0 .INDENT 3.5 Restrict the queries \fIq\fP\s-2\d1\u\s0 to \fIq\fP\s-2\dn\u\s0 to \fIfield\fP, and combine with \fIand\fP (for most fields) or \fIor\fP\&. See \fI\%FIELDS\fP for more information. .UNINDENT .UNINDENT .sp \fB(\fP \fIoperator\fP \fIq\fP\s-2\d1\u\s0 \fIq\fP\s-2\d2\u\s0 ... \fIq\fP\s-2\dn\u\s0 \fB)\fP .INDENT 0.0 .INDENT 3.5 Combine queries \fIq\fP\s-2\d1\u\s0 to \fIq\fP\s-2\dn\u\s0\&. Currently supported operators are \fBand\fP, \fBor\fP, and \fBnot\fP\&. \fB(not\fP \fIq\fP\s-2\d1\u\s0 ... \fIq\fP\s-2\dn\u\s0 \fB)\fP is equivalent to \fB(and (not\fP \fIq\fP\s-2\d1\u\s0 \fB) ... (not\fP \fIq\fP\s-2\dn\u\s0 \fB))\fP\&. .UNINDENT .UNINDENT .sp \fB(\fP \fImodifier\fP \fIq\fP\s-2\d1\u\s0 \fIq\fP\s-2\d2\u\s0 ... \fIq\fP\s-2\dn\u\s0 \fB)\fP .INDENT 0.0 .INDENT 3.5 Combine queries \fIq\fP\s-2\d1\u\s0 to \fIq\fP\s-2\dn\u\s0, and reinterpret the result (e.g. as a regular expression). See \fI\%MODIFIERS\fP for more information. .UNINDENT .UNINDENT .sp \fB(macro (\fP \fIp\fP\s-2\d1\u\s0 ... \fIp\fP\s-2\dn\u\s0 \fB) body)\fP .INDENT 0.0 .INDENT 3.5 Define saved query with parameter substitution. The syntax is recognized only in saved s\-expression queries (see \fBsquery.*\fP in \fI\%notmuch\-config\fP). Parameter names in \fBbody\fP must be prefixed with \fB,\fP to be expanded (see \fI\%MACRO EXAMPLES\fP). Macros may refer to other macros, but only to their own parameters [1]\&. .UNINDENT .UNINDENT .SS FIELDS .sp \fIFields\fP [2] correspond to attributes of mail messages. Some are inherent (and immutable) like \fBsubject\fP, while others \fBtag\fP and \fBproperty\fP are settable by the user. Each concrete field in \fI\%the table below\fP is discussed further under \(dqSearch prefixes\(dq in \fI\%notmuch\-search\-terms\fP\&. The row \fIuser\fP refers to user defined fields, described in \fI\%notmuch\-config\fP\&. .sp Most fields are either \fIphrase fields\fP [3] (which match sequences of words), or \fIterm fields\fP [4] (which match exact strings). \fIPhrase splitting\fP breaks the term (basic value or quoted string) into words, ignore punctuation. Phrase splitting is applied to terms in phrase (probabilistic) fields. Both phrase splitting and stemming apply only in phrase fields. .sp Each term or phrase field has an associated combining operator (\fBand\fP or \fBor\fP) used to combine the queries from each element of the tail of the list. This is generally \fBor\fP for those fields where a message has one such attribute, and \fBand\fP otherwise. .sp Term or phrase fields can contain arbitrarily complex queries made up from terms, operators, and modifiers, but not other fields. .sp Range fields take one or two arguments specifying lower and upper bounds. One argument is interpreted as identical upper and lower bounds. Either upper or lower bound may be specified as \fB\(dq\(dq\fP or \fB*\fP to specify the lowest possible lower bound or highest possible upper bound. .sp \fBlastmod\fP ranges support negative arguments, interpreted relative to the most recent database revision (see \fI\%count \-\-lastmod\fP). .SS Fields with supported modifiers .TS box center; l|l|l|l|l|l. T{ field T} T{ combine T} T{ type T} T{ expand T} T{ wildcard T} T{ regex T} _ T{ \fInone\fP T} T{ and T} T{ T} T{ no T} T{ yes T} T{ no T} _ T{ \fIuser\fP T} T{ and T} T{ phrase T} T{ no T} T{ yes T} T{ no T} _ T{ attachment T} T{ and T} T{ phrase T} T{ yes T} T{ yes T} T{ no T} _ T{ body T} T{ and T} T{ phrase T} T{ no T} T{ no T} T{ no T} _ T{ date T} T{ T} T{ range T} T{ no T} T{ no T} T{ no T} _ T{ folder T} T{ or T} T{ phrase T} T{ yes T} T{ yes T} T{ yes T} _ T{ from T} T{ and T} T{ phrase T} T{ yes T} T{ yes T} T{ yes T} _ T{ id T} T{ or T} T{ term T} T{ no T} T{ yes T} T{ yes T} _ T{ is T} T{ and T} T{ term T} T{ yes T} T{ yes T} T{ yes T} _ T{ lastmod T} T{ T} T{ range T} T{ no T} T{ no T} T{ no T} _ T{ mid T} T{ or T} T{ term T} T{ no T} T{ yes T} T{ yes T} _ T{ mimetype T} T{ or T} T{ phrase T} T{ yes T} T{ yes T} T{ no T} _ T{ path T} T{ or T} T{ term T} T{ no T} T{ yes T} T{ yes T} _ T{ property T} T{ and T} T{ term T} T{ yes T} T{ yes T} T{ yes T} _ T{ subject T} T{ and T} T{ phrase T} T{ yes T} T{ yes T} T{ yes T} _ T{ tag T} T{ and T} T{ term T} T{ yes T} T{ yes T} T{ yes T} _ T{ thread T} T{ or T} T{ term T} T{ yes T} T{ yes T} T{ yes T} _ T{ to T} T{ and T} T{ phrase T} T{ yes T} T{ yes T} T{ no T} .TE .SS MODIFIERS .sp \fIModifiers\fP refer to any prefixes (first elements of compound queries) that are neither operators nor fields. .sp \fB(infix\fP \fIatom\fP \fB)\fP .INDENT 0.0 .INDENT 3.5 Interpret \fIatom\fP as an infix notmuch query (see \fI\%notmuch\-search\-terms\fP). Not supported inside fields. .UNINDENT .UNINDENT .sp \fB(matching\fP \fIq\fP\s-2\d1\u\s0 \fIq\fP\s-2\d2\u\s0 ... \fIq\fP\s-2\dn\u\s0 \fB)\fP \fB(of\fP \fIq\fP\s-2\d1\u\s0 \fIq\fP\s-2\d2\u\s0 ... \fIq\fP\s-2\dn\u\s0 \fB)\fP .INDENT 0.0 .INDENT 3.5 Match all messages have the same values of the current field as those matching all of \fIq\fP\s-2\d1\u\s0 ... \fIq\fP\s-2\dn\u\s0\&. Supported in most term [7] or phrase fields. Most commonly used in the \fBthread\fP field. .UNINDENT .UNINDENT .sp \fB(query\fP \fIatom\fP \fB)\fP .INDENT 0.0 .INDENT 3.5 Expand to the saved query named by \fIatom\fP\&. See \fI\%notmuch\-config\fP for more. Note that the saved query must be in infix syntax (\fI\%notmuch\-search\-terms\fP). Not supported inside fields. .UNINDENT .UNINDENT .sp \fB(regex\fP \fIatom\fP \fB)\fP \fB(rx\fP \fIatom\fP \fB)\fP .INDENT 0.0 .INDENT 3.5 Interpret \fIatom\fP as a POSIX.2 regular expression (see \fB\X'tty: link https://manpages.debian.org/regex.7.html'\fI\%regex(7)\fP\X'tty: link'\fP). This applies in term fields and a subset [5] of phrase fields (see \fI\%Fields with supported modifiers\fP). .UNINDENT .UNINDENT .sp \fB(starts\-with\fP \fIsubword\fP \fB)\fP .INDENT 0.0 .INDENT 3.5 Matches any term starting with \fIsubword\fP\&. This applies in either phrase or term \fI\%fields\fP, or outside of fields [6]\&. Note that a \fBstarts\-with\fP query cannot be part of a phrase. The atom \fB*\fP is a synonym for \fB(starts\-with \(dq\(dq)\fP\&. .UNINDENT .UNINDENT .SH EXAMPLES .sp \fBWizard\fP .INDENT 0.0 .INDENT 3.5 Match all messages containing the word \(dqwizard\(dq, ignoring case. .UNINDENT .UNINDENT .sp \fBadded\fP .INDENT 0.0 .INDENT 3.5 Match all messages containing \(dqadded\(dq, but also those containing \(dqadd\(dq, \(dqadditional\(dq, \(dqAdditional\(dq, \(dqadds\(dq, etc... via stemming. .UNINDENT .UNINDENT .sp \fB(and Bob Marley)\fP .INDENT 0.0 .INDENT 3.5 Match messages containing words \(dqBob\(dq and \(dqMarley\(dq, or their stems The words need not be adjacent. .UNINDENT .UNINDENT .sp \fB(not Bob Marley)\fP .INDENT 0.0 .INDENT 3.5 Match messages containing neither \(dqBob\(dq nor \(dqMarley\(dq, nor their stems. .UNINDENT .UNINDENT .sp \fB\(dqquick fox\(dq\fP \fBquick\-fox\fP \fBquick@fox\fP .INDENT 0.0 .INDENT 3.5 Match the \fIphrase\fP \(dqquick\(dq followed by \(dqfox\(dq in phrase fields (or outside a field). Match the literal string in a term field. .UNINDENT .UNINDENT .sp \fB(folder (of (id 1234@invalid)))\fP .INDENT 0.0 .INDENT 3.5 Match any message in the same folder as the one with Message\-Id \(dq1234@invalid\(dq. .UNINDENT .UNINDENT .sp \fB(id 1234@invalid blah@test)\fP .INDENT 0.0 .INDENT 3.5 Matches Message\-Id \(dq1234@invalid\(dq \fIor\fP Message\-Id \(dqblah@test\(dq. .UNINDENT .UNINDENT .sp \fB(and (infix \(dqdate:2009\-11\-18..2009\-11\-18\(dq) (tag unread))\fP .INDENT 0.0 .INDENT 3.5 Match messages in the given date range with tag unread. .UNINDENT .UNINDENT .sp \fB(and (date 2009\-11\-18 2009\-11\-18) (tag unread))\fP .INDENT 0.0 .INDENT 3.5 Match messages in the given date range with tag unread. .UNINDENT .UNINDENT .sp \fB(and (date 2009\-11\-18 *) (tag unread))\fP .INDENT 0.0 .INDENT 3.5 Match messages from 2009\-11\-18 or later with tag unread. .UNINDENT .UNINDENT .sp \fB(and (date * 2009\-11\-18) (tag unread))\fP .INDENT 0.0 .INDENT 3.5 Match messages from 2009\-11\-18 or earlier with tag unread. .UNINDENT .UNINDENT .sp \fB(starts\-with prelim)\fP .INDENT 0.0 .INDENT 3.5 Match any words starting with \(dqprelim\(dq. .UNINDENT .UNINDENT .sp \fB(subject quick \(dqbrown fox\(dq)\fP .INDENT 0.0 .INDENT 3.5 Match messages whose subject contains \(dqquick\(dq (anywhere, stemmed) and the phrase \(dqbrown fox\(dq. .UNINDENT .UNINDENT .sp \fB(subject (starts\-with prelim))\fP .INDENT 0.0 .INDENT 3.5 Matches any word starting with \(dqprelim\(dq, inside a message subject. .UNINDENT .UNINDENT .sp \fB(subject (starts\-with quick) \(dqbrown fox\(dq)\fP .INDENT 0.0 .INDENT 3.5 Match messages whose subject contains \(dqquick brown fox\(dq, but also \(dqbrown fox quicksand\(dq. .UNINDENT .UNINDENT .sp \fB(thread (of (id 1234@invalid)))\fP .INDENT 0.0 .INDENT 3.5 Match any message in the same thread as the one with Message\-Id \(dq1234@invalid\(dq. .UNINDENT .UNINDENT .sp \fB(thread (matching (from bob@example.com) (to bob@example.com)))\fP .INDENT 0.0 .INDENT 3.5 Match any (messages in) a thread containing a message from \(dqbob@example.com\(dq and a (possibly distinct) message to \(dqbob@example.com\(dq. .UNINDENT .UNINDENT .sp \fB(to (or bob@example.com mallory@example.org))\fP \fB(or (to bob@example.com) (to mallory@example.org))\fP .INDENT 0.0 .INDENT 3.5 Match in the \(dqTo\(dq or \(dqCc\(dq headers, \(dqbob@example.com\(dq, \(dqmallory@example.org\(dq, and also \(dqbob@example.com.au\(dq since it contains the adjacent triple \(dqbob\(dq, \(dqexample\(dq, \(dqcom\(dq. .UNINDENT .UNINDENT .sp \fB(not (to *))\fP .INDENT 0.0 .INDENT 3.5 Match messages with an empty or invalid \(aqTo\(aq and \(aqCc\(aq field. .UNINDENT .UNINDENT .sp \fB(List *)\fP .INDENT 0.0 .INDENT 3.5 Match messages with a non\-empty List\-Id header, assuming configuration \fBindex.header.List=List\-Id\fP\&. .UNINDENT .UNINDENT .SS MACRO EXAMPLES .sp A macro that takes two parameters and applies different fields to them. .INDENT 0.0 .INDENT 3.5 .sp .EX $ notmuch config set squery.TagSubject \(aq(macro (tagname subj) (and (tag ,tagname) (subject ,subj)))\(aq $ notmuch search \-\-query=sexp \(aq(TagSubject inbox maildir)\(aq .EE .UNINDENT .UNINDENT .sp Nested macros are allowed. .INDENT 0.0 .INDENT 3.5 .sp .EX $ notmuch config set squery.Inner \(aq(macro (x) (subject ,x))\(aq $ notmuch config set squery.Outer \(aq(macro (x y) (and (tag ,x) (Inner ,y)))\(aq $ notmuch search \-\-query=sexp \(aq(Outer inbox maildir)\(aq .EE .UNINDENT .UNINDENT .sp Parameters can be re\-used to reduce boilerplate. Any field, including user defined fields is permitted within a macro. .INDENT 0.0 .INDENT 3.5 .sp .EX $ notmuch config set squery.About \(aq(macro (name) (or (subject ,name) (List ,name)))\(aq $ notmuch search \-\-query=sexp \(aq(About notmuch)\(aq .EE .UNINDENT .UNINDENT .SH NOTES .IP [1] 5 Technically macros implement lazy evaluation and lexical scope. There is one top level scope containing all macro definitions, but all parameter definitions are local to a given macro. .IP [2] 5 a.k.a. prefixes .IP [3] 5 a.k.a. probabilistic prefixes .IP [4] 5 a.k.a. boolean prefixes .IP [5] 5 Due to the implementation of phrase fields in Xapian, regex queries could only match individual words. .IP [6] 5 Due to the way \fBbody\fP is implemented in notmuch, this modifier is not supported in the \fBbody\fP field. .IP [7] 5 Due to the way recursive \fBpath\fP queries are implemented in notmuch, this modifier is not supported in the \fBpath\fP field. .SH AUTHOR Carl Worth and many others .SH COPYRIGHT 2009-2024, Carl Worth and many others .\" Generated by docutils manpage writer. .