]> git.cworth.org Git - notmuch/blob - test/T081-sexpr-search.sh
lib/parse-sexp: parse user headers
[notmuch] / test / T081-sexpr-search.sh
1 #!/usr/bin/env bash
2 test_description='"notmuch search" in several variations'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 if [ $NOTMUCH_HAVE_SFSEXP -ne 1 ]; then
6     printf "Skipping due to missing sfsexp library\n"
7     test_done
8 fi
9
10 add_email_corpus
11
12 for query in '()' '(not)' '(and)' '(or ())' '(or (not))' '(or (and))' \
13             '(or (and) (or) (not (and)))'; do
14     test_begin_subtest "all messages: $query"
15     notmuch search '*' > EXPECTED
16     notmuch search --query=sexp "$query" > OUTPUT
17     test_expect_equal_file EXPECTED OUTPUT
18 done
19
20 for query in '(or)' '(not ())' '(not (not))' '(not (and))' \
21                    '(not (or (and) (or) (not (and))))'; do
22     test_begin_subtest "no messages: $query"
23     notmuch search --query=sexp "$query" > OUTPUT
24     test_expect_equal_file /dev/null OUTPUT
25 done
26
27 test_begin_subtest "and of exact terms"
28 notmuch search --query=sexp '(and "wonderful" "wizard")' | notmuch_search_sanitize > OUTPUT
29 cat <<EOF > EXPECTED
30 thread:XXX   2009-11-18 [1/3] Carl Worth| Jan Janak; [notmuch] What a great idea! (inbox unread)
31 EOF
32 test_expect_equal_file EXPECTED OUTPUT
33
34 test_begin_subtest "or of exact terms"
35 notmuch search --query=sexp '(or "php" "wizard")' | notmuch_search_sanitize > OUTPUT
36 cat <<EOF > EXPECTED
37 thread:XXX   2010-12-29 [1/1] François Boulogne; [aur-general] Guidelines: cp, mkdir vs install (inbox unread)
38 thread:XXX   2009-11-18 [1/3] Carl Worth| Jan Janak; [notmuch] What a great idea! (inbox unread)
39 EOF
40 test_expect_equal_file EXPECTED OUTPUT
41
42 test_begin_subtest "single term in body"
43 notmuch search --query=sexp 'wizard' | notmuch_search_sanitize>OUTPUT
44 cat <<EOF > EXPECTED
45 thread:XXX   2009-11-18 [1/3] Carl Worth| Jan Janak; [notmuch] What a great idea! (inbox unread)
46 EOF
47 test_expect_equal_file EXPECTED OUTPUT
48
49 test_begin_subtest "single term in body (case insensitive)"
50 notmuch search --query=sexp 'Wizard' | notmuch_search_sanitize>OUTPUT
51 cat <<EOF > EXPECTED
52 thread:XXX   2009-11-18 [1/3] Carl Worth| Jan Janak; [notmuch] What a great idea! (inbox unread)
53 EOF
54 test_expect_equal_file EXPECTED OUTPUT
55
56 test_begin_subtest "single term in body, stemmed version"
57 notmuch search arriv > EXPECTED
58 notmuch search --query=sexp arriv > OUTPUT
59 test_expect_equal_file EXPECTED OUTPUT
60
61 test_begin_subtest "single term in body, unstemmed version"
62 notmuch search --query=sexp '"arriv"' > OUTPUT
63 test_expect_equal_file /dev/null OUTPUT
64
65 test_begin_subtest "Search by 'subject'"
66 add_message [subject]=subjectsearchtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
67 output=$(notmuch search --query=sexp '(subject subjectsearchtest)' | notmuch_search_sanitize)
68 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)"
69
70 test_begin_subtest "Search by 'subject' (case insensitive)"
71 notmuch search tag:inbox and subject:maildir | notmuch_search_sanitize > EXPECTED
72 notmuch search --query=sexp '(subject "Maildir")' | notmuch_search_sanitize > OUTPUT
73 test_expect_equal_file EXPECTED OUTPUT
74
75 test_begin_subtest "Search by 'subject' (utf-8):"
76 add_message [subject]=utf8-sübjéct '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
77 output=$(notmuch search --query=sexp '(subject utf8 sübjéct)' | notmuch_search_sanitize)
78 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
79
80 test_begin_subtest "Search by 'subject' (utf-8, and):"
81 output=$(notmuch search --query=sexp '(subject (and utf8 sübjéct))' | notmuch_search_sanitize)
82 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
83
84 test_begin_subtest "Search by 'subject' (utf-8, and outside):"
85 output=$(notmuch search --query=sexp '(and (subject utf8) (subject sübjéct))' | notmuch_search_sanitize)
86 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
87
88 test_begin_subtest "Search by 'subject' (utf-8, or):"
89 notmuch search --query=sexp '(subject (or utf8 subjectsearchtest))' | notmuch_search_sanitize > OUTPUT
90 cat <<EOF > EXPECTED
91 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)
92 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)
93 EOF
94 test_expect_equal_file EXPECTED OUTPUT
95
96 test_begin_subtest "Search by 'subject' (utf-8, or outside):"
97 notmuch search --query=sexp '(or (subject utf8) (subject subjectsearchtest))' | notmuch_search_sanitize > OUTPUT
98 cat <<EOF > EXPECTED
99 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)
100 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)
101 EOF
102 test_expect_equal_file EXPECTED OUTPUT
103
104 test_begin_subtest "Search by 'attachment'"
105 notmuch search attachment:notmuch-help.patch > EXPECTED
106 notmuch search --query=sexp '(attachment notmuch-help.patch)' > OUTPUT
107 test_expect_equal_file EXPECTED OUTPUT
108
109 test_begin_subtest "Search by 'body'"
110 add_message '[subject]="body search"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [body]=bodysearchtest
111 output=$(notmuch search --query=sexp '(body bodysearchtest)' | notmuch_search_sanitize)
112 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)"
113
114 test_begin_subtest "Search by 'body' (phrase)"
115 add_message '[subject]="body search (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="body search (phrase)"'
116 add_message '[subject]="negative result"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="This phrase should not match the body search"'
117 output=$(notmuch search --query=sexp '(body "body search phrase")' | notmuch_search_sanitize)
118 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)"
119
120 test_begin_subtest "Search by 'body' (utf-8):"
121 add_message '[subject]="utf8-message-body-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="message body utf8: bödý"'
122 output=$(notmuch search --query=sexp '(body bödý)' | notmuch_search_sanitize)
123 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)"
124
125 add_message "[body]=thebody-1" "[subject]=kryptonite-1"
126 add_message "[body]=nothing-to-see-here-1" "[subject]=thebody-1"
127
128 test_begin_subtest 'search without body: prefix'
129 notmuch search thebody > EXPECTED
130 notmuch search --query=sexp '(and thebody)' > OUTPUT
131 test_expect_equal_file EXPECTED OUTPUT
132
133 test_begin_subtest 'negated body: prefix'
134 notmuch search thebody and not body:thebody > EXPECTED
135 notmuch search --query=sexp '(and (not (body thebody)) thebody)' > OUTPUT
136 test_expect_equal_file EXPECTED OUTPUT
137
138 test_begin_subtest 'search unprefixed for prefixed term'
139 notmuch search kryptonite > EXPECTED
140 notmuch search --query=sexp '(and kryptonite)' > OUTPUT
141 test_expect_equal_file EXPECTED OUTPUT
142
143 test_begin_subtest 'search with body: prefix for term only in subject'
144 notmuch search body:kryptonite > EXPECTED
145 notmuch search --query=sexp '(body kryptonite)' > OUTPUT
146 test_expect_equal_file EXPECTED OUTPUT
147
148 test_begin_subtest "Search by 'from'"
149 add_message '[subject]="search by from"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom
150 output=$(notmuch search --query=sexp '(from searchbyfrom)' | notmuch_search_sanitize)
151 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)"
152
153 test_begin_subtest "Search by 'from' (address)"
154 add_message '[subject]="search by from (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom@example.com
155 output=$(notmuch search --query=sexp '(from searchbyfrom@example.com)' | notmuch_search_sanitize)
156 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)"
157
158 test_begin_subtest "Search by 'from' (name)"
159 add_message '[subject]="search by from (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[from]="Search By From Name <test@example.com>"'
160 output=$(notmuch search --query=sexp '(from "Search By From Name")' | notmuch_search_sanitize)
161 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
162
163 test_begin_subtest "Search by 'from' (name and address)"
164 output=$(notmuch search --query=sexp '(from "Search By From Name <test@example.com>")' | notmuch_search_sanitize)
165 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
166
167 add_message '[dir]=bad' '[subject]="To the bone"'
168 add_message '[dir]=.' '[subject]="Top level"'
169 add_message '[dir]=bad/news' '[subject]="Bears"'
170 mkdir -p "${MAIL_DIR}/duplicate/bad/news"
171 cp "$gen_msg_filename" "${MAIL_DIR}/duplicate/bad/news"
172
173 add_message '[dir]=things' '[subject]="These are a few"'
174 add_message '[dir]=things/favorite' '[subject]="Raindrops, whiskers, kettles"'
175 add_message '[dir]=things/bad' '[subject]="Bites, stings, sad feelings"'
176
177 test_begin_subtest "Search by 'folder' (multiple)"
178 output=$(notmuch search --query=sexp '(folder bad bad/news things/bad)' | notmuch_search_sanitize)
179 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; To the bone (inbox unread)
180 thread:XXX   2001-01-05 [1/1(2)] Notmuch Test Suite; Bears (inbox unread)
181 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Bites, stings, sad feelings (inbox unread)"
182
183 test_begin_subtest "Search by 'folder': top level."
184 notmuch search folder:'""' > EXPECTED
185 notmuch search --query=sexp '(folder "")'  > OUTPUT
186 test_expect_equal_file EXPECTED OUTPUT
187
188 test_begin_subtest "Search by 'id'"
189 add_message '[subject]="search by id"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
190 output=$(notmuch search --query=sexp "(id ${gen_msg_id})" | notmuch_search_sanitize)
191 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
192
193 test_begin_subtest "Search by 'id' (or)"
194 add_message '[subject]="search by id"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
195 output=$(notmuch search --query=sexp "(id non-existent-mid ${gen_msg_id})" | notmuch_search_sanitize)
196 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
197
198 test_begin_subtest "Search by 'is' (multiple)"
199 notmuch tag -inbox tag:searchbytag
200 notmuch search is:inbox AND is:unread | notmuch_search_sanitize > EXPECTED
201 notmuch search --query=sexp '(is inbox unread)' | notmuch_search_sanitize > OUTPUT
202 notmuch tag +inbox tag:searchbytag
203 test_expect_equal_file EXPECTED OUTPUT
204
205 test_begin_subtest "Search by 'mid'"
206 add_message '[subject]="search by mid"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
207 output=$(notmuch search --query=sexp "(mid ${gen_msg_id})" | notmuch_search_sanitize)
208 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by mid (inbox unread)"
209
210 test_begin_subtest "Search by 'mid' (or)"
211 add_message '[subject]="search by mid"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
212 output=$(notmuch search --query=sexp "(mid non-existent-mid ${gen_msg_id})" | notmuch_search_sanitize)
213 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by mid (inbox unread)"
214
215 test_begin_subtest "Search by 'mimetype'"
216 notmuch search mimetype:text/html > EXPECTED
217 notmuch search --query=sexp '(mimetype text html)'  > OUTPUT
218 test_expect_equal_file EXPECTED OUTPUT
219
220 test_begin_subtest "Search by 'subject' (utf-8, phrase-token):"
221 output=$(notmuch search --query=sexp '(subject utf8-sübjéct)' | notmuch_search_sanitize)
222 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
223
224 test_begin_subtest "Search by 'subject' (utf-8, quoted string):"
225 output=$(notmuch search --query=sexp '(subject "utf8 sübjéct")' | notmuch_search_sanitize)
226 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
227
228 test_begin_subtest "Search by 'subject' (combine phrase, term):"
229 output=$(notmuch search --query=sexp '(subject Mac "compatibility issues")' | notmuch_search_sanitize)
230 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
231
232 test_begin_subtest "Search by 'subject' (combine phrase, term 2):"
233 notmuch search --query=sexp '(subject (or utf8 "compatibility issues"))' | notmuch_search_sanitize > OUTPUT
234 cat <<EOF > EXPECTED
235 thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)
236 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)
237 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)
238 EOF
239 test_expect_equal_file EXPECTED OUTPUT
240
241 test_begin_subtest "Search by 'subject' (combine phrase, term 3):"
242 notmuch search --query=sexp '(subject issues X/Darwin)' | notmuch_search_sanitize > OUTPUT
243 cat <<EOF > EXPECTED
244 thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)
245 EOF
246 test_expect_equal_file EXPECTED OUTPUT
247
248 test_begin_subtest "Search by 'tag'"
249 add_message '[subject]="search by tag"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
250 notmuch tag +searchbytag id:${gen_msg_id}
251 output=$(notmuch search --query=sexp '(tag searchbytag)' | notmuch_search_sanitize)
252 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)"
253
254 test_begin_subtest "Search by 'tag' (multiple)"
255 notmuch tag -inbox tag:searchbytag
256 notmuch search tag:inbox AND tag:unread | notmuch_search_sanitize > EXPECTED
257 notmuch search --query=sexp '(tag inbox unread)' | notmuch_search_sanitize > OUTPUT
258 notmuch tag +inbox tag:searchbytag
259 test_expect_equal_file EXPECTED OUTPUT
260
261 test_begin_subtest "Search by 'tag' and 'subject'"
262 notmuch search tag:inbox and subject:maildir | notmuch_search_sanitize > EXPECTED
263 notmuch search --query=sexp '(and (tag inbox) (subject maildir))' | notmuch_search_sanitize > OUTPUT
264 test_expect_equal_file EXPECTED OUTPUT
265
266 test_begin_subtest "Search by 'thread'"
267 add_message '[subject]="search by thread"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
268 thread_id=$(notmuch search id:${gen_msg_id} | sed -e "s/thread:\([a-f0-9]*\).*/\1/")
269 output=$(notmuch search --query=sexp "(thread ${thread_id})" | notmuch_search_sanitize)
270 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)"
271
272 test_begin_subtest "Search by 'to'"
273 add_message '[subject]="search by to"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto
274 output=$(notmuch search --query=sexp '(to searchbyto)' | notmuch_search_sanitize)
275 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)"
276
277 test_begin_subtest "Search by 'to' (address)"
278 add_message '[subject]="search by to (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto@example.com
279 output=$(notmuch search --query=sexp '(to searchbyto@example.com)' | notmuch_search_sanitize)
280 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)"
281
282 test_begin_subtest "Search by 'to' (name)"
283 add_message '[subject]="search by to (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[to]="Search By To Name <test@example.com>"'
284 output=$(notmuch search --query=sexp '(to "Search By To Name")' | notmuch_search_sanitize)
285 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
286
287 test_begin_subtest "Search by 'to' (name and address)"
288 output=$(notmuch search --query=sexp '(to "Search By To Name <test@example.com>")' | notmuch_search_sanitize)
289 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
290
291 test_begin_subtest "starts-with, no prefix"
292 output=$(notmuch search --query=sexp '(starts-with prelim)' | notmuch_search_sanitize)
293 test_expect_equal "$output" "thread:XXX   2009-11-17 [2/2] Alex Botero-Lowry, Carl Worth; [notmuch] preliminary FreeBSD support (attachment inbox unread)"
294
295 test_begin_subtest "starts-with, case-insensitive"
296 notmuch search --query=sexp '(starts-with FreeB)' | notmuch_search_sanitize > OUTPUT
297 cat <<EOF > EXPECTED
298 thread:XXX   2009-11-18 [3/4] Alexander Botero-Lowry, Jjgod Jiang; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)
299 thread:XXX   2009-11-17 [2/2] Alex Botero-Lowry, Carl Worth; [notmuch] preliminary FreeBSD support (attachment inbox unread)
300 EOF
301 test_expect_equal_file EXPECTED OUTPUT
302
303 test_begin_subtest "starts-with, no prefix, all messages"
304 notmuch search --query=sexp '(starts-with "")' | notmuch_search_sanitize > OUTPUT
305 notmuch search '*' | notmuch_search_sanitize > EXPECTED
306 test_expect_equal_file EXPECTED OUTPUT
307
308 test_begin_subtest "starts-with, attachment"
309 output=$(notmuch search --query=sexp '(attachment (starts-with not))' | notmuch_search_sanitize)
310 test_expect_equal "$output" 'thread:XXX   2009-11-18 [2/2] Lars Kellogg-Stedman; [notmuch] "notmuch help" outputs to stderr? (attachment inbox signed unread)'
311
312 test_begin_subtest "starts-with, folder"
313 notmuch search --output=files --query=sexp '(folder (starts-with bad))' | notmuch_dir_sanitize | sed 's/[0-9]*$/XXX/' > OUTPUT
314 cat <<EOF > EXPECTED
315 MAIL_DIR/bad/msg-XXX
316 MAIL_DIR/bad/news/msg-XXX
317 MAIL_DIR/duplicate/bad/news/msg-XXX
318 EOF
319 test_expect_equal_file EXPECTED OUTPUT
320
321 test_begin_subtest "starts-with, from"
322 notmuch search --query=sexp '(from (starts-with Mik))' | notmuch_search_sanitize > OUTPUT
323 cat <<EOF > EXPECTED
324 thread:XXX   2009-11-17 [1/1] Mikhail Gusarov; [notmuch] [PATCH] Handle rename of message file (inbox unread)
325 thread:XXX   2009-11-17 [2/7] Mikhail Gusarov| Lars Kellogg-Stedman, Keith Packard, Carl Worth; [notmuch] Working with Maildir storage? (inbox signed unread)
326 thread:XXX   2009-11-17 [2/5] Mikhail Gusarov| Carl Worth, Keith Packard; [notmuch] [PATCH 2/2] Include <stdint.h> to get uint32_t in C++ file with gcc 4.4 (inbox unread)
327 EOF
328 test_expect_equal_file EXPECTED OUTPUT
329
330 test_begin_subtest "starts-with, id"
331 notmuch search --query=sexp --output=messages '(id (starts-with 877))' > OUTPUT
332 cat <<EOF > EXPECTED
333 id:877h1wv7mg.fsf@inf-8657.int-evry.fr
334 id:877htoqdbo.fsf@yoom.home.cworth.org
335 EOF
336 test_expect_equal_file EXPECTED OUTPUT
337
338 test_begin_subtest "starts-with, is"
339 output=$(notmuch search --query=sexp '(is (starts-with searchby))' | notmuch_search_sanitize)
340 test_expect_equal "$output" 'thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)'
341
342 test_begin_subtest "starts-with, mid"
343 notmuch search --query=sexp --output=messages '(mid (starts-with 877))' > OUTPUT
344 cat <<EOF > EXPECTED
345 id:877h1wv7mg.fsf@inf-8657.int-evry.fr
346 id:877htoqdbo.fsf@yoom.home.cworth.org
347 EOF
348 test_expect_equal_file EXPECTED OUTPUT
349
350 test_begin_subtest "starts-with, mimetype"
351 notmuch search --query=sexp '(mimetype (starts-with sig))' | notmuch_search_sanitize > OUTPUT
352 cat <<EOF > EXPECTED
353 thread:XXX   2009-11-18 [2/2] Lars Kellogg-Stedman; [notmuch] "notmuch help" outputs to stderr? (attachment inbox signed unread)
354 thread:XXX   2009-11-18 [4/7] Lars Kellogg-Stedman, Mikhail Gusarov| Keith Packard, Carl Worth; [notmuch] Working with Maildir storage? (inbox signed unread)
355 thread:XXX   2009-11-17 [1/3] Adrian Perez de Castro| Keith Packard, Carl Worth; [notmuch] Introducing myself (inbox signed unread)
356 EOF
357 test_expect_equal_file EXPECTED OUTPUT
358
359 add_message '[subject]="message with properties"'
360 notmuch restore <<EOF
361 #= ${gen_msg_id} foo=bar
362 EOF
363
364 test_begin_subtest "starts-with, property"
365 notmuch search --query=sexp '(property (starts-with foo=))' | notmuch_search_sanitize > OUTPUT
366 cat <<EOF > EXPECTED
367 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; message with properties (inbox unread)
368 EOF
369 test_expect_equal_file EXPECTED OUTPUT
370
371 test_begin_subtest "starts-with, subject"
372 notmuch search --query=sexp '(subject (starts-with FreeB))' | notmuch_search_sanitize > OUTPUT
373 cat <<EOF > EXPECTED
374 thread:XXX   2009-11-17 [2/2] Alex Botero-Lowry, Carl Worth; [notmuch] preliminary FreeBSD support (attachment inbox unread)
375 EOF
376 test_expect_equal_file EXPECTED OUTPUT
377
378 test_begin_subtest "starts-with, tag"
379 output=$(notmuch search --query=sexp '(tag (starts-with searchby))' | notmuch_search_sanitize)
380 test_expect_equal "$output" 'thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)'
381
382 add_message '[subject]="no tags"'
383 notag_mid=${gen_msg_id}
384 notmuch tag -unread -inbox id:${notag_mid}
385
386 test_begin_subtest "negated starts-with, tag"
387 output=$(notmuch search --query=sexp '(tag (not (starts-with in)))' | notmuch_search_sanitize)
388 test_expect_equal "$output" 'thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; no tags ()'
389
390 test_begin_subtest "negated starts-with, tag 2"
391 output=$(notmuch search --query=sexp '(not (tag (starts-with in)))' | notmuch_search_sanitize)
392 test_expect_equal "$output" 'thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; no tags ()'
393
394 test_begin_subtest "negated starts-with, tag 3"
395 output=$(notmuch search --query=sexp '(not (tag (starts-with "")))' | notmuch_search_sanitize)
396 test_expect_equal "$output" 'thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; no tags ()'
397
398 test_begin_subtest "starts-with, thread"
399 notmuch search --query=sexp '(thread (starts-with "00"))' > OUTPUT
400 notmuch search '*' > EXPECTED
401 test_expect_equal_file EXPECTED OUTPUT
402
403 test_begin_subtest "starts-with, to"
404 notmuch search --query=sexp '(to (starts-with "search"))' | notmuch_search_sanitize > OUTPUT
405 cat <<EOF > EXPECTED
406 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)
407 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)
408 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)
409 EOF
410 test_expect_equal_file EXPECTED OUTPUT
411
412 test_begin_subtest "wildcard search for 'is'"
413 notmuch search not id:${notag_mid} > EXPECTED
414 notmuch search --query=sexp '(is *)' > OUTPUT
415 test_expect_equal_file EXPECTED OUTPUT
416
417 test_begin_subtest "negated wildcard search for 'is'"
418 notmuch search id:${notag_mid} > EXPECTED
419 notmuch search --query=sexp '(not (is *))' > OUTPUT
420 test_expect_equal_file EXPECTED OUTPUT
421
422 test_begin_subtest "wildcard search for 'property'"
423 notmuch search property:foo=bar > EXPECTED
424 notmuch search --query=sexp '(property *)' > OUTPUT
425 test_expect_equal_file EXPECTED OUTPUT
426
427 test_begin_subtest "wildcard search for 'tag'"
428 notmuch search not id:${notag_mid} > EXPECTED
429 notmuch search --query=sexp '(tag *)' > OUTPUT
430 test_expect_equal_file EXPECTED OUTPUT
431
432 test_begin_subtest "negated wildcard search for 'tag'"
433 notmuch search id:${notag_mid} > EXPECTED
434 notmuch search --query=sexp '(not (tag *))' > OUTPUT
435 test_expect_equal_file EXPECTED OUTPUT
436
437 add_message '[subject]="message with tag \"*\""'
438 notmuch tag '+*' id:${gen_msg_id}
439
440 test_begin_subtest "search for 'tag' \"*\""
441 output=$(notmuch search --query=sexp --output=messages '(tag "*")')
442 test_expect_equal "$output" "id:$gen_msg_id"
443
444 test_begin_subtest "search for missing / empty to"
445 add_message [to]="undisclosed-recipients:"
446 notmuch search --query=sexp '(not (to *))' | notmuch_search_sanitize > OUTPUT
447 cat <<EOF > EXPECTED
448 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; search for missing / empty to (inbox unread)
449 EOF
450 test_expect_equal_file EXPECTED OUTPUT
451
452 test_begin_subtest "Unbalanced parens"
453 # A code 1 indicates the error was handled (a crash will return e.g. 139).
454 test_expect_code 1 "notmuch search --query=sexp '('"
455
456 test_begin_subtest "Unbalanced parens, error message"
457 notmuch search --query=sexp '(' >OUTPUT 2>&1
458 cat <<EOF > EXPECTED
459 notmuch search: Syntax error in query
460 invalid s-expression: '('
461 EOF
462 test_expect_equal_file EXPECTED OUTPUT
463
464 test_begin_subtest "unknown prefix"
465 notmuch search --query=sexp '(foo)' >OUTPUT 2>&1
466 cat <<EOF > EXPECTED
467 notmuch search: Syntax error in query
468 unknown prefix 'foo'
469 EOF
470 test_expect_equal_file EXPECTED OUTPUT
471
472 test_begin_subtest "list as prefix"
473 notmuch search --query=sexp '((foo))' >OUTPUT 2>&1
474 cat <<EOF > EXPECTED
475 notmuch search: Syntax error in query
476 unexpected list in field/operation position
477 EOF
478 test_expect_equal_file EXPECTED OUTPUT
479
480 test_begin_subtest "illegal nesting"
481 notmuch search --query=sexp '(subject (subject foo))' >OUTPUT 2>&1
482 cat <<EOF > EXPECTED
483 notmuch search: Syntax error in query
484 nested field: 'subject' inside 'subject'
485 EOF
486 test_expect_equal_file EXPECTED OUTPUT
487
488 test_begin_subtest "starts-with, no argument"
489 notmuch search --query=sexp '(starts-with)' >OUTPUT 2>&1
490 cat <<EOF > EXPECTED
491 notmuch search: Syntax error in query
492 'starts-with' expects single atom as argument
493 EOF
494 test_expect_equal_file EXPECTED OUTPUT
495
496 test_begin_subtest "starts-with, list argument"
497 notmuch search --query=sexp '(starts-with (stuff))' >OUTPUT 2>&1
498 cat <<EOF > EXPECTED
499 notmuch search: Syntax error in query
500 'starts-with' expects single atom as argument
501 EOF
502 test_expect_equal_file EXPECTED OUTPUT
503
504 test_begin_subtest "starts-with, too many arguments"
505 notmuch search --query=sexp '(starts-with a b c)' >OUTPUT 2>&1
506 cat <<EOF > EXPECTED
507 notmuch search: Syntax error in query
508 'starts-with' expects single atom as argument
509 EOF
510 test_expect_equal_file EXPECTED OUTPUT
511
512 test_begin_subtest "starts-with, illegal field"
513 notmuch search --query=sexp '(body (starts-with foo))' >OUTPUT 2>&1
514 cat <<EOF > EXPECTED
515 notmuch search: Syntax error in query
516 'body' does not support wildcard queries
517 EOF
518 test_expect_equal_file EXPECTED OUTPUT
519
520 test_begin_subtest "wildcard, illegal field"
521 notmuch search --query=sexp '(body *)' >OUTPUT 2>&1
522 cat <<EOF > EXPECTED
523 notmuch search: Syntax error in query
524 'body' does not support wildcard queries
525 EOF
526 test_expect_equal_file EXPECTED OUTPUT
527
528 test_begin_subtest "Search, exclude \"deleted\" messages from search"
529 notmuch config set search.exclude_tags deleted
530 generate_message '[subject]="Not deleted"'
531 not_deleted_id=$gen_msg_id
532 generate_message '[subject]="Deleted"'
533 notmuch new > /dev/null
534 notmuch tag +deleted id:$gen_msg_id
535 deleted_id=$gen_msg_id
536 output=$(notmuch search --query=sexp '(subject deleted)' | notmuch_search_sanitize)
537 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)"
538
539 test_begin_subtest "Search, exclude \"deleted\" messages from message search --exclude=false"
540 output=$(notmuch search --query=sexp --exclude=false --output=messages '(subject deleted)' | notmuch_search_sanitize)
541 test_expect_equal "$output" "id:$not_deleted_id
542 id:$deleted_id"
543
544 test_begin_subtest "Search, exclude \"deleted\" messages from search, overridden"
545 notmuch search --query=sexp '(and (subject deleted) (tag deleted))' | notmuch_search_sanitize > OUTPUT
546 cat <<EOF > EXPECTED
547 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Deleted (deleted inbox unread)
548 EOF
549 test_expect_equal_file EXPECTED OUTPUT
550
551 test_begin_subtest "Search, exclude \"deleted\" messages from threads"
552 add_message '[subject]="Not deleted reply"' '[in-reply-to]="<$gen_msg_id>"'
553 output=$(notmuch search --query=sexp '(subject deleted)' | notmuch_search_sanitize)
554 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)
555 thread:XXX   2001-01-05 [1/2] Notmuch Test Suite; Not deleted reply (deleted inbox unread)"
556
557 test_begin_subtest "Search, don't exclude \"deleted\" messages when --exclude=flag specified"
558 output=$(notmuch search --query=sexp --exclude=flag '(subject deleted)' | notmuch_search_sanitize)
559 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)
560 thread:XXX   2001-01-05 [1/2] Notmuch Test Suite; Deleted (deleted inbox unread)"
561
562 test_begin_subtest "Search, don't exclude \"deleted\" messages from search if not configured"
563 notmuch config set search.exclude_tags
564 output=$(notmuch search --query=sexp '(subject deleted)' | notmuch_search_sanitize)
565 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)
566 thread:XXX   2001-01-05 [2/2] Notmuch Test Suite; Deleted (deleted inbox unread)"
567
568 test_begin_subtest "regex at top level"
569 notmuch search --query=sexp '(rx foo)' >& OUTPUT
570 cat <<EOF > EXPECTED
571 notmuch search: Syntax error in query
572 illegal 'rx' outside field
573 EOF
574 test_expect_equal_file EXPECTED OUTPUT
575
576 test_begin_subtest "regex in illegal field"
577 notmuch search --query=sexp '(body (regex foo))' >& OUTPUT
578 cat <<EOF > EXPECTED
579 notmuch search: Syntax error in query
580 'regex' not supported in field 'body'
581 EOF
582 test_expect_equal_file EXPECTED OUTPUT
583
584 notmuch search --output=messages from:cworth > cworth.msg-ids
585
586 test_begin_subtest "regexp 'from' search"
587 notmuch search --output=messages --query=sexp '(from (rx cworth))' > OUTPUT
588 test_expect_equal_file cworth.msg-ids OUTPUT
589
590 test_begin_subtest "regexp search for 'from' 2"
591 notmuch search from:/cworth@cworth.org/ and subject:patch | notmuch_search_sanitize > EXPECTED
592 notmuch search --query=sexp '(and (from (rx cworth@cworth.org)) (subject patch))' \
593     | notmuch_search_sanitize > OUTPUT
594 test_expect_equal_file EXPECTED OUTPUT
595
596 test_begin_subtest "regexp 'folder' search"
597 notmuch search 'folder:/^bar$/' | notmuch_search_sanitize > EXPECTED
598 notmuch search --query=sexp '(folder (rx ^bar$))' | notmuch_search_sanitize > OUTPUT
599 test_expect_equal_file EXPECTED OUTPUT
600
601 test_begin_subtest "regexp 'id' search"
602 notmuch search --output=messages --query=sexp '(id (rx yoom))' > OUTPUT
603 test_expect_equal_file cworth.msg-ids OUTPUT
604
605 test_begin_subtest "unanchored 'is' search"
606 notmuch search tag:signed or tag:inbox > EXPECTED
607 notmuch search --query=sexp '(is (rx i))' > OUTPUT
608 test_expect_equal_file EXPECTED OUTPUT
609
610 test_begin_subtest "anchored 'is' search"
611 notmuch search tag:signed > EXPECTED
612 notmuch search --query=sexp '(is (rx ^si))' > OUTPUT
613 test_expect_equal_file EXPECTED OUTPUT
614
615 test_begin_subtest "combine regexp mid and subject"
616 notmuch search subject:/-C/ and mid:/y..m/ | notmuch_search_sanitize > EXPECTED
617 notmuch search --query=sexp '(and (subject (rx -C)) (mid (rx y..m)))' | notmuch_search_sanitize > OUTPUT
618 test_expect_equal_file EXPECTED OUTPUT
619
620 test_begin_subtest "regexp 'path' search"
621 notmuch search 'path:/^bar$/' | notmuch_search_sanitize > EXPECTED
622 notmuch search --query=sexp '(path (rx ^bar$))' | notmuch_search_sanitize > OUTPUT
623 test_expect_equal_file EXPECTED OUTPUT
624
625 test_begin_subtest "regexp 'property' search"
626 notmuch search property:foo=bar > EXPECTED
627 notmuch search --query=sexp '(property (rx foo=.*))' > OUTPUT
628 test_expect_equal_file EXPECTED OUTPUT
629
630 test_begin_subtest "anchored 'tag' search"
631 notmuch search tag:signed > EXPECTED
632 notmuch search --query=sexp '(tag (rx ^si))' > OUTPUT
633 test_expect_equal_file EXPECTED OUTPUT
634
635 test_begin_subtest "regexp 'thread' search"
636 notmuch search --output=threads '*' | grep '7$' > EXPECTED
637 notmuch search --output=threads --query=sexp '(thread (rx 7$))' > OUTPUT
638 test_expect_equal_file EXPECTED OUTPUT
639
640 test_begin_subtest "Basic query that matches no messages"
641 count=$(notmuch count from:keithp and to:keithp)
642 test_expect_equal 0 "$count"
643
644 test_begin_subtest "Same query against threads"
645 notmuch search --query=sexp '(and (thread (of (from keithp))) (thread (matching (to keithp))))' \
646     | notmuch_search_sanitize > OUTPUT
647 cat<<EOF > EXPECTED
648 thread:XXX   2009-11-18 [7/7] Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard, Carl Worth; [notmuch] Working with Maildir storage? (inbox signed unread)
649 EOF
650 test_expect_equal_file EXPECTED OUTPUT
651
652 test_begin_subtest "Mix thread and non-threads query"
653 notmuch search --query=sexp '(and (thread (matching keithp)) (to keithp))' | notmuch_search_sanitize > OUTPUT
654 cat<<EOF > EXPECTED
655 thread:XXX   2009-11-18 [1/7] Lars Kellogg-Stedman| Mikhail Gusarov, Keith Packard, Carl Worth; [notmuch] Working with Maildir storage? (inbox signed unread)
656 EOF
657 test_expect_equal_file EXPECTED OUTPUT
658
659 test_begin_subtest "Compound subquery"
660 notmuch search --query=sexp '(thread (of (from keithp) (subject Maildir)))' | notmuch_search_sanitize > OUTPUT
661 cat<<EOF > EXPECTED
662 thread:XXX   2009-11-18 [7/7] Lars Kellogg-Stedman, Mikhail Gusarov, Keith Packard, Carl Worth; [notmuch] Working with Maildir storage? (inbox signed unread)
663 EOF
664 test_expect_equal_file EXPECTED OUTPUT
665
666 test_begin_subtest "empty subquery"
667 notmuch search --query=sexp '(thread (of))' 1>OUTPUT 2>&1
668 notmuch search '*' > EXPECTED
669 test_expect_equal_file EXPECTED OUTPUT
670
671 test_begin_subtest "illegal expansion"
672 notmuch search --query=sexp '(id (of ego))' 1>OUTPUT 2>&1
673 cat<<EOF > EXPECTED
674 notmuch search: Syntax error in query
675 'of' unsupported inside 'id'
676 EOF
677 test_expect_equal_file EXPECTED OUTPUT
678
679 test_begin_subtest "(folder (of subquery))"
680 notmuch search --query=sexp --output=messages '(folder (of (id yun3a4cegoa.fsf@aiko.keithp.com)))' > OUTPUT
681 cat <<EOF > EXPECTED
682 id:yun1vjwegii.fsf@aiko.keithp.com
683 id:yun3a4cegoa.fsf@aiko.keithp.com
684 id:1258509400-32511-1-git-send-email-stewart@flamingspork.com
685 id:1258506353-20352-1-git-send-email-stewart@flamingspork.com
686 id:20091118010116.GC25380@dottiness.seas.harvard.edu
687 id:20091118005829.GB25380@dottiness.seas.harvard.edu
688 id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com
689 EOF
690 test_expect_equal_file EXPECTED OUTPUT
691
692 test_begin_subtest "infix query"
693 notmuch search to:searchbyto | notmuch_search_sanitize > EXPECTED
694 notmuch search --query=sexp '(infix "to:searchbyto")' |  notmuch_search_sanitize > OUTPUT
695 test_expect_equal_file EXPECTED OUTPUT
696
697 test_begin_subtest "bad infix query 1"
698 notmuch search --query=sexp '(infix "from:/unbalanced")' 2>&1|  notmuch_search_sanitize > OUTPUT
699 cat <<EOF > EXPECTED
700 notmuch search: Syntax error in query
701 Syntax error in infix query: from:/unbalanced
702 EOF
703 test_expect_equal_file EXPECTED OUTPUT
704
705 test_begin_subtest "bad infix query 2"
706 notmuch search --query=sexp '(infix "thread:{unbalanced")' 2>&1|  notmuch_search_sanitize > OUTPUT
707 cat <<EOF > EXPECTED
708 notmuch search: Syntax error in query
709 Syntax error in infix query: thread:{unbalanced
710 EOF
711 test_expect_equal_file EXPECTED OUTPUT
712
713 test_begin_subtest "bad infix query 3: bad nesting"
714 notmuch search --query=sexp '(subject (infix "tag:inbox"))' 2>&1|  notmuch_search_sanitize > OUTPUT
715 cat <<EOF > EXPECTED
716 notmuch search: Syntax error in query
717 'infix' not supported inside 'subject'
718 EOF
719 test_expect_equal_file EXPECTED OUTPUT
720
721 test_begin_subtest "infix query that matches no messages"
722 notmuch search --query=sexp '(and (infix "from:keithp") (infix "to:keithp"))' > OUTPUT
723 test_expect_equal_file /dev/null OUTPUT
724
725 test_begin_subtest "compound infix query"
726 notmuch search date:2009-11-18..2009-11-18 and tag:unread > EXPECTED
727 notmuch search --query=sexp  '(infix "date:2009-11-18..2009-11-18 and tag:unread")' > OUTPUT
728 test_expect_equal_file EXPECTED OUTPUT
729
730 test_begin_subtest "compound infix query 2"
731 notmuch search date:2009-11-18..2009-11-18 and tag:unread > EXPECTED
732 notmuch search --query=sexp  '(and (infix "date:2009-11-18..2009-11-18") (infix "tag:unread"))' > OUTPUT
733 test_expect_equal_file EXPECTED OUTPUT
734
735 test_begin_subtest "user header (unknown header)"
736 notmuch search --query=sexp '(FooBar)' >& OUTPUT
737 cat <<EOF > EXPECTED
738 notmuch search: Syntax error in query
739 unknown prefix 'FooBar'
740 EOF
741 test_expect_equal_file EXPECTED OUTPUT
742
743 test_begin_subtest "adding user header"
744 test_expect_code 0 "notmuch config set index.header.List \"List-Id\""
745
746 test_begin_subtest "reindexing"
747 test_expect_code 0 'notmuch reindex "*"'
748
749 test_begin_subtest "wildcard search for user header"
750 grep -Ril List-Id ${MAIL_DIR} | sort | notmuch_dir_sanitize > EXPECTED
751 notmuch search --output=files --query=sexp '(List *)' | sort | notmuch_dir_sanitize > OUTPUT
752 test_expect_equal_file EXPECTED OUTPUT
753
754 test_begin_subtest "wildcard search for user header 2"
755 grep -Ril List-Id ${MAIL_DIR} | sort | notmuch_dir_sanitize > EXPECTED
756 notmuch search --output=files --query=sexp '(List (starts-with not))' | sort | notmuch_dir_sanitize > OUTPUT
757 test_expect_equal_file EXPECTED OUTPUT
758
759 test_begin_subtest "search for user header"
760 notmuch search List:notmuch | notmuch_search_sanitize > EXPECTED
761 notmuch search --query=sexp '(List notmuch)' | notmuch_search_sanitize > OUTPUT
762 test_expect_equal_file EXPECTED OUTPUT
763
764 test_begin_subtest "search for user header (list token)"
765 notmuch search List:notmuch | notmuch_search_sanitize > EXPECTED
766 notmuch search --query=sexp '(List notmuch.notmuchmail.org)' | notmuch_search_sanitize > OUTPUT
767 test_expect_equal_file EXPECTED OUTPUT
768
769 test_begin_subtest "search for user header (quoted string)"
770 notmuch search 'List:"notmuch notmuchmail org"' | notmuch_search_sanitize > EXPECTED
771 notmuch search --query=sexp '(List "notmuch notmuchmail org")' | notmuch_search_sanitize > OUTPUT
772 test_expect_equal_file EXPECTED OUTPUT
773
774 test_begin_subtest "search for user header (atoms)"
775 notmuch search 'List:"notmuch notmuchmail org"' | notmuch_search_sanitize > EXPECTED
776 notmuch search --query=sexp '(List notmuch notmuchmail org)' | notmuch_search_sanitize > OUTPUT
777 test_expect_equal_file EXPECTED OUTPUT
778
779 test_done