]> git.notmuchmail.org Git - notmuch/blob - test/notmuch-test
test: Put the json tests into their own section.
[notmuch] / test / notmuch-test
1 #!/bin/bash
2 set -e
3
4 find_notmuch_binary ()
5 {
6     dir=$1
7
8     while [ -n "$dir" ]; do
9         bin=$dir/notmuch
10         if [ -x $bin ]; then
11             echo $bin
12             return
13         fi
14         dir=$(dirname $dir)
15         if [ "$dir" = "/" ]; then
16             break
17         fi
18     done
19
20     echo notmuch
21 }
22
23 increment_mtime_amount=0
24 increment_mtime ()
25 {
26     dir=$1
27
28     increment_mtime_amount=$((increment_mtime_amount + 1))
29     touch -d "+${increment_mtime_amount} seconds" $dir
30 }
31
32 # Generate a new message in the mail directory, with a unique message
33 # ID and subject. The message is not added to the index.
34 #
35 # After this function returns, the filename of the generated message
36 # is available as $gen_msg_filename and the message ID is available as
37 # $gen_msg_id .
38 #
39 # This function supports named parameters with the bash syntax for
40 # assigning a value to an associative array ([name]=value). The
41 # supported parameters are:
42 #
43 #  [dir]=directory/of/choice
44 #
45 #       Generate the message in directory 'directory/of/choice' within
46 #       the mail store. The directory will be created if necessary.
47 #
48 #  [body]=text
49 #
50 #       Text to use as the body of the email message
51 #
52 #  '[from]="Some User <user@example.com>"'
53 #  '[to]="Some User <user@example.com>"'
54 #  '[subject]="Subject of email message"'
55 #  '[date]="RFC 822 Date"'
56 #
57 #       Values for email headers. If not provided, default values will
58 #       be generated instead.
59 #
60 #  '[cc]="Some User <user@example.com>"'
61 #  [reply-to]=some-address
62 #  [in-reply-to]=<message-id>
63 #
64 #       Additional values for email headers. If these are not provided
65 #       then the relevant headers will simply not appear in the
66 #       message.
67 #
68 #  '[id]=<message-id>'
69 #
70 #       Controls the message-id of the created message.
71 gen_msg_cnt=0
72 gen_msg_filename=""
73 gen_msg_id=""
74 generate_message ()
75 {
76     # This is our (bash-specific) magic for doing named parameters
77     local -A template="($@)"
78     local additional_headers
79
80     if [ -z "${template[id]}" ]; then
81         gen_msg_cnt=$((gen_msg_cnt + 1))
82         gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
83         gen_msg_id="${gen_msg_name}@notmuch-test-suite"
84     else
85         gen_msg_name="msg-${template[id]}"
86         gen_msg_id="${template[id]}"
87     fi
88
89     if [ -z "${template[dir]}" ]; then
90         gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
91     else
92         gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
93         mkdir -p $(dirname $gen_msg_filename)
94     fi
95
96     if [ -z "${template[body]}" ]; then
97         template[body]="This is just a test message (#${gen_msg_cnt})"
98     fi
99
100     if [ -z "${template[from]}" ]; then
101         template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
102     fi
103
104     if [ -z "${template[to]}" ]; then
105         template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
106     fi
107
108     if [ -z "${template[subject]}" ]; then
109         template[subject]="Test message #${gen_msg_cnt}"
110     fi
111
112     if [ -z "${template[date]}" ]; then
113         template[date]="Tue, 05 Jan 2001 15:43:57 -0800"
114     fi
115
116     additional_headers=""
117     if [ ! -z "${template[reply-to]}" ]; then
118         additional_headers="Reply-To: ${template[reply-to]}
119 ${additional_headers}"
120     fi
121
122     if [ ! -z "${template[in-reply-to]}" ]; then
123         additional_headers="In-Reply-To: ${template[in-reply-to]}
124 ${additional_headers}"
125     fi
126
127     if [ ! -z "${template[cc]}" ]; then
128         additional_headers="Cc: ${template[cc]}
129 ${additional_headers}"
130     fi
131
132 cat <<EOF >$gen_msg_filename
133 From: ${template[from]}
134 To: ${template[to]}
135 Message-Id: <${gen_msg_id}>
136 Subject: ${template[subject]}
137 Date: ${template[date]}
138 ${additional_headers}
139 ${template[body]}
140 EOF
141
142     # Ensure that the mtime of the containing directory is updated
143     increment_mtime $(dirname ${gen_msg_filename})
144 }
145
146 # Generate a new message and add it to the index.
147 #
148 # All of the arguments and return values supported by generate_message
149 # are also supported here, so see that function for details.
150 add_message ()
151 {
152     generate_message "$@"
153
154     $NOTMUCH new > /dev/null
155 }
156
157 tests=0
158 test_failures=0
159
160 pass_if_equal ()
161 {
162     output=$1
163     expected=$2
164
165     tests=$((tests + 1))
166
167     if [ "$output" = "$expected" ]; then
168         echo "  PASS"
169     else
170         echo "  FAIL"
171         testname=test-$(printf "%03d" $tests)
172         echo "$expected" > $testname.expected
173         echo "$output" > $testname.output
174         diff -u $testname.expected $testname.output || true
175         test_failures=$((test_failures + 1))
176     fi
177 }
178
179 TEST_DIR=$(pwd)/test.$$
180 MAIL_DIR=${TEST_DIR}/mail
181 export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
182 NOTMUCH=$(find_notmuch_binary $(pwd))
183
184 NOTMUCH_NEW ()
185 {
186     $NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
187 }
188
189 notmuch_search_sanitize ()
190 {
191     sed -r -e 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
192 }
193
194 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
195 notmuch_show_sanitize ()
196 {
197     sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
198 }
199
200 rm -rf ${TEST_DIR}
201 mkdir ${TEST_DIR}
202 cd ${TEST_DIR}
203
204 mkdir ${MAIL_DIR}
205
206 cat <<EOF > ${NOTMUCH_CONFIG}
207 [database]
208 path=${MAIL_DIR}
209
210 [user]
211 name=Notmuch Test Suite
212 primary_email=test_suite@notmuchmail.org
213 other_email=test_suite_other@notmuchmail.org
214 EOF
215
216 printf "Testing \"notmuch new\" in several variations:\n"
217 printf " No new messages...\t\t\t\t"
218 output=$(NOTMUCH_NEW)
219 pass_if_equal "$output" "No new mail."
220
221 printf " Single new message...\t\t\t\t"
222 generate_message
223 output=$(NOTMUCH_NEW)
224 pass_if_equal "$output" "Added 1 new message to the database."
225
226 printf " Multiple new messages...\t\t\t"
227 generate_message
228 generate_message
229 output=$(NOTMUCH_NEW)
230 pass_if_equal "$output" "Added 2 new messages to the database."
231
232 printf " No new messages (non-empty DB)...\t\t"
233 output=$(NOTMUCH_NEW)
234 pass_if_equal "$output" "No new mail."
235
236 printf " New directories...\t\t\t\t"
237 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
238 mkdir ${MAIL_DIR}/def
239 mkdir ${MAIL_DIR}/ghi
240 generate_message [dir]=def
241
242 output=$(NOTMUCH_NEW)
243 pass_if_equal "$output" "Added 1 new message to the database."
244
245 printf " Alternate inode order...\t\t\t"
246
247 rm -rf ${MAIL_DIR}/.notmuch
248 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
249 rm ${MAIL_DIR}/def/*
250 generate_message [dir]=abc
251
252 output=$(NOTMUCH_NEW)
253 pass_if_equal "$output" "Added 1 new message to the database."
254
255 printf " Message moved in...\t\t\t\t"
256 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
257 generate_message
258 tmp_msg_filename=tmp/$gen_msg_filename
259 mkdir -p $(dirname $tmp_msg_filename)
260 mv $gen_msg_filename $tmp_msg_filename
261 increment_mtime ${MAIL_DIR}
262 $NOTMUCH new > /dev/null
263 mv $tmp_msg_filename $gen_msg_filename
264 increment_mtime ${MAIL_DIR}
265 output=$(NOTMUCH_NEW)
266 pass_if_equal "$output" "Added 1 new message to the database."
267
268 printf " Renamed message...\t\t\t\t"
269
270 generate_message
271 $NOTMUCH new > /dev/null
272 mv $gen_msg_filename ${gen_msg_filename}-renamed
273 increment_mtime ${MAIL_DIR}
274 output=$(NOTMUCH_NEW)
275 pass_if_equal "$output" "No new mail. Detected 1 file rename."
276
277 printf " Deleted message...\t\t\t\t"
278
279 rm ${gen_msg_filename}-renamed
280 increment_mtime ${MAIL_DIR}
281 output=$(NOTMUCH_NEW)
282 pass_if_equal "$output" "No new mail. Removed 1 message."
283
284 printf " Renamed directory...\t\t\t\t"
285
286 generate_message [dir]=dir
287 generate_message [dir]=dir
288 generate_message [dir]=dir
289
290 $NOTMUCH new > /dev/null
291
292 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
293 increment_mtime ${MAIL_DIR}
294
295 output=$(NOTMUCH_NEW)
296 pass_if_equal "$output" "No new mail. Detected 3 file renames."
297
298 printf " Deleted directory...\t\t\t\t"
299
300 rm -rf ${MAIL_DIR}/dir-renamed
301 increment_mtime ${MAIL_DIR}
302
303 output=$(NOTMUCH_NEW)
304 pass_if_equal "$output" "No new mail. Removed 3 messages."
305
306 printf " New directory (at end of list)...\t\t"
307
308 generate_message [dir]=zzz
309 generate_message [dir]=zzz
310 generate_message [dir]=zzz
311
312 output=$(NOTMUCH_NEW)
313 pass_if_equal "$output" "Added 3 new messages to the database."
314
315 printf " Deleted directory (end of list)...\t\t"
316
317 rm -rf ${MAIL_DIR}/zzz
318 increment_mtime ${MAIL_DIR}
319
320 output=$(NOTMUCH_NEW)
321 pass_if_equal "$output" "No new mail. Removed 3 messages."
322
323 printf " New symlink to directory...\t\t\t"
324
325 rm -rf ${MAIL_DIR}/.notmuch
326 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
327
328 mkdir ${MAIL_DIR}
329 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
330
331 output=$(NOTMUCH_NEW)
332 pass_if_equal "$output" "Added 1 new message to the database."
333
334 printf " New symlink to a file...\t\t\t"
335 generate_message
336 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
337 mkdir -p $(dirname $external_msg_filename)
338 mv $gen_msg_filename $external_msg_filename
339 ln -s $external_msg_filename $gen_msg_filename
340 increment_mtime ${MAIL_DIR}
341 output=$(NOTMUCH_NEW)
342 pass_if_equal "$output" "Added 1 new message to the database."
343
344 printf " New two-level directory...\t\t\t"
345
346 generate_message [dir]=two/levels
347 generate_message [dir]=two/levels
348 generate_message [dir]=two/levels
349
350 output=$(NOTMUCH_NEW)
351 pass_if_equal "$output" "Added 3 new messages to the database."
352
353 printf " Deleted two-level directory...\t\t\t"
354
355 rm -rf ${MAIL_DIR}/two
356 increment_mtime ${MAIL_DIR}
357
358 output=$(NOTMUCH_NEW)
359 pass_if_equal "$output" "No new mail. Removed 3 messages."
360
361 printf "\nTesting \"notmuch search\" in several variations:\n"
362
363 printf " Search body...\t\t\t\t\t"
364 add_message '[subject]="body search"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [body]=bodysearchtest
365 output=$($NOTMUCH search bodysearchtest | notmuch_search_sanitize)
366 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)"
367
368 printf " Search by from:...\t\t\t\t"
369 add_message '[subject]="search by from"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom
370 output=$($NOTMUCH search from:searchbyfrom | notmuch_search_sanitize)
371 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)"
372
373 printf " Search by to:...\t\t\t\t"
374 add_message '[subject]="search by to"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto
375 output=$($NOTMUCH search to:searchbyto | notmuch_search_sanitize)
376 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)"
377
378 printf " Search by subject:...\t\t\t\t"
379 add_message [subject]=subjectsearchtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
380 output=$($NOTMUCH search subject:subjectsearchtest | notmuch_search_sanitize)
381 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)"
382
383 printf " Search by id:...\t\t\t\t"
384 add_message '[subject]="search by id"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
385 output=$($NOTMUCH search id:${gen_msg_id} | notmuch_search_sanitize)
386 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
387
388 printf " Search by tag:...\t\t\t\t"
389 add_message '[subject]="search by tag"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
390 $NOTMUCH tag +searchbytag id:${gen_msg_id}
391 output=$($NOTMUCH search tag:searchbytag | notmuch_search_sanitize)
392 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)"
393
394 printf " Search by thread:...\t\t\t\t"
395 add_message '[subject]="search by thread"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
396 thread_id=$($NOTMUCH search id:${gen_msg_id} | sed -e 's/thread:\([a-f0-9]*\).*/\1/')
397 output=$($NOTMUCH search thread:${thread_id} | notmuch_search_sanitize)
398 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)"
399
400 printf " Search body (phrase)...\t\t\t"
401 add_message '[subject]="body search (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="body search (phrase)"'
402 add_message '[subject]="negative result"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="This phrase should not match the body search"'
403 output=$($NOTMUCH search '\"body search (phrase)\"' | notmuch_search_sanitize)
404 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)"
405
406 printf " Search by from: (address)...\t\t\t"
407 add_message '[subject]="search by from (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom@example.com
408 output=$($NOTMUCH search from:searchbyfrom@example.com | notmuch_search_sanitize)
409 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)"
410
411 printf " Search by from: (name)...\t\t\t"
412 add_message '[subject]="search by from (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[from]="Search By From Name <test@example.com>"'
413 output=$($NOTMUCH search from:'Search By From Name' | notmuch_search_sanitize)
414 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
415
416 printf " Search by to: (address)...\t\t\t"
417 add_message '[subject]="search by to (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto@example.com
418 output=$($NOTMUCH search to:searchbyto@example.com | notmuch_search_sanitize)
419 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)"
420
421 printf " Search by to: (name)...\t\t\t"
422 add_message '[subject]="search by to (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[to]="Search By To Name <test@example.com>"'
423 output=$($NOTMUCH search to:'Search By To Name' | notmuch_search_sanitize)
424 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
425
426 printf " Search by subject: (phrase)...\t\t\t"
427 add_message '[subject]="subject search test (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
428 add_message '[subject]="this phrase should not match the subject search test"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
429 output=$($NOTMUCH search 'subject:\"subject search test (phrase)\"' | notmuch_search_sanitize)
430 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)"
431
432 printf " Search for all messages (\"*\"):...\t\t"
433 output=$($NOTMUCH search '*' | notmuch_search_sanitize)
434 pass_if_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #6 (inbox unread)
435 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #14 (inbox unread)
436 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)
437 thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)
438 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)
439 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)
440 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)
441 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)
442 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)
443 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)
444 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; negative result (inbox unread)
445 thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)
446 thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)
447 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)
448 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)
449 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)
450 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; this phrase should not match the subject search test (inbox unread)"
451
452 printf " Search body (utf-8):...\t\t\t"
453 add_message '[subject]="utf8-message-body-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="message body utf8: bödý"'
454 output=$($NOTMUCH search 'bödý' | notmuch_search_sanitize)
455 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)"
456
457 printf "\nTesting --format=json output:\n"
458
459 printf " Show message: json...\t\t\t\t"
460 add_message '[subject]="json-show-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="json-show-message"'
461 output=$($NOTMUCH show --format=json 'json-show-message')
462 pass_if_equal "$output" '[[[{"id": "'${gen_msg_id}'", "match": true, "filename": "'${gen_msg_filename}'", "timestamp": 946728000, "date_relative": "2000-01-01", "tags": ["inbox","unread"], "headers": {"Subject": "json-show-subject", "From": "Notmuch Test Suite <test_suite@notmuchmail.org>", "To": "Notmuch Test Suite <test_suite@notmuchmail.org>", "Cc": "", "Bcc": "", "Date": "Sat, 01 Jan 2000 12:00:00 -0000"}, "body": [{"id": 1, "content-type": "text/plain", "content": "json-show-message\n"}]}, []]]]'
463
464 printf " Search message: json...\t\t\t"
465 add_message '[subject]="json-search-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="json-search-message"'
466 output=$($NOTMUCH search --format=json 'json-search-message' | notmuch_search_sanitize)
467 pass_if_equal "$output" '[{"thread": "XXX",
468 "timestamp": 946728000,
469 "matched": 1,
470 "total": 1,
471 "authors": "Notmuch Test Suite",
472 "subject": "json-search-subject",
473 "tags": ["inbox", "unread"]}]'
474
475 printf " Search by subject (utf-8):...\t\t\t"
476 add_message [subject]=utf8-sübjéct '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
477 output=$($NOTMUCH search subject:utf8-sübjéct | notmuch_search_sanitize)
478 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
479
480 printf " Show message: json, utf-8...\t\t\t"
481 add_message '[subject]="json-show-utf8-body-sübjéct"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="jsön-show-méssage"'
482 output=$($NOTMUCH show --format=json 'jsön-show-méssage')
483 pass_if_equal "$output" '[[[{"id": "'${gen_msg_id}'", "match": true, "filename": "'${gen_msg_filename}'", "timestamp": 946728000, "date_relative": "2000-01-01", "tags": ["inbox","unread"], "headers": {"Subject": "json-show-utf8-body-sübjéct", "From": "Notmuch Test Suite <test_suite@notmuchmail.org>", "To": "Notmuch Test Suite <test_suite@notmuchmail.org>", "Cc": "", "Bcc": "", "Date": "Sat, 01 Jan 2000 12:00:00 -0000"}, "body": [{"id": 1, "content-type": "text/plain", "content": "jsön-show-méssage\n"}]}, []]]]'
484
485 printf " Search message: json, utf-8...\t\t\t"
486 add_message '[subject]="json-search-utf8-body-sübjéct"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="jsön-search-méssage"'
487 output=$($NOTMUCH search --format=json 'jsön-search-méssage' | notmuch_search_sanitize)
488 pass_if_equal "$output" '[{"thread": "XXX",
489 "timestamp": 946728000,
490 "matched": 1,
491 "total": 1,
492 "authors": "Notmuch Test Suite",
493 "subject": "json-search-utf8-body-sübjéct",
494 "tags": ["inbox", "unread"]}]'
495
496 printf "\nTesting naming of threads with changing subject:\n"
497 add_message '[subject]="thread-naming: Initial thread subject"' \
498             '[date]="Fri, 05 Jan 2001 15:43:56 -0800"'
499 first=${gen_msg_cnt}
500 parent=${gen_msg_id}
501 add_message '[subject]="thread-naming: Older changed subject"' \
502             '[date]="Sat, 06 Jan 2001 15:43:56 -0800"' \
503             "[in-reply-to]=\<$parent\>"
504 add_message '[subject]="thread-naming: Newer changed subject"' \
505             '[date]="Sun, 07 Jan 2001 15:43:56 -0800"' \
506             "[in-reply-to]=\<$parent\>"
507 add_message '[subject]="thread-naming: Final thread subject"' \
508             '[date]="Mon, 08 Jan 2001 15:43:56 -0800"' \
509             "[in-reply-to]=\<$parent\>"
510 final=${gen_msg_id}
511
512 printf " Initial thread name (oldest-first search)...\t"
513 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
514 pass_if_equal "$output" "thread:XXX   2001-01-05 [4/4] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
515
516 printf " Initial thread name (newest-first search)...\t"
517 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
518 pass_if_equal "$output" "thread:XXX   2001-01-08 [4/4] Notmuch Test Suite; thread-naming: Final thread subject (inbox unread)"
519
520 # Remove oldest and newest messages from search results
521 $NOTMUCH tag -inbox id:$parent or id:$final
522
523 printf " Changed thread name (oldest-first search)...\t"
524 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
525 pass_if_equal "$output" "thread:XXX   2001-01-06 [2/4] Notmuch Test Suite; thread-naming: Older changed subject (inbox unread)"
526
527 printf " Changed thread name (newest-first search)...\t"
528 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
529 pass_if_equal "$output" "thread:XXX   2001-01-07 [2/4] Notmuch Test Suite; thread-naming: Newer changed subject (inbox unread)"
530
531 printf " Ignore added reply prefix (Re:)...\t\t"
532 add_message '[subject]="Re: thread-naming: Initial thread subject"' \
533             '[date]="Tue, 09 Jan 2001 15:43:45 -0800"' \
534             "[in-reply-to]=\<$parent\>"
535 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
536 pass_if_equal "$output" "thread:XXX   2001-01-09 [3/5] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
537
538 printf " Ignore added reply prefix (Aw:)...\t\t"
539 add_message '[subject]="Aw: thread-naming: Initial thread subject"' \
540             '[date]="Wed, 10 Jan 2001 15:43:45 -0800"' \
541             "[in-reply-to]=\<$parent\>"
542 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
543 pass_if_equal "$output" "thread:XXX   2001-01-10 [4/6] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
544
545 printf " Ignore added reply prefix (Vs:)...\t\t"
546 add_message '[subject]="Vs: thread-naming: Initial thread subject"' \
547             '[date]="Thu, 11 Jan 2001 15:43:45 -0800"' \
548             "[in-reply-to]=\<$parent\>"
549 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
550 pass_if_equal "$output" "thread:XXX   2001-01-11 [5/7] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
551
552 printf " Ignore added reply prefix (Sv:)...\t\t"
553 add_message '[subject]="Sv: thread-naming: Initial thread subject"' \
554             '[date]="Fri, 12 Jan 2001 15:43:45 -0800"' \
555             "[in-reply-to]=\<$parent\>"
556 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
557 pass_if_equal "$output" "thread:XXX   2001-01-12 [6/8] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
558
559 printf " Test order of messages in \"notmuch show\"\t"
560 output=$($NOTMUCH show thread-naming | notmuch_show_sanitize)
561 pass_if_equal "$output" "\fmessage{ id:msg-$(printf "%03d" $first)@notmuch-test-suite depth:0 match:1 filename:/XXX/mail/msg-$(printf "%03d" $first)
562 \fheader{
563 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (unread)
564 Subject: thread-naming: Initial thread subject
565 From: Notmuch Test Suite <test_suite@notmuchmail.org>
566 To: Notmuch Test Suite <test_suite@notmuchmail.org>
567 Date: Fri, 05 Jan 2001 15:43:56 -0800
568 \fheader}
569 \fbody{
570 \fpart{ ID: 1, Content-type: text/plain
571 This is just a test message (#$first)
572 \fpart}
573 \fbody}
574 \fmessage}
575 \fmessage{ id:msg-$(printf "%03d" $((first + 1)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 1)))
576 \fheader{
577 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-06) (inbox unread)
578 Subject: thread-naming: Older changed subject
579 From: Notmuch Test Suite <test_suite@notmuchmail.org>
580 To: Notmuch Test Suite <test_suite@notmuchmail.org>
581 Date: Sat, 06 Jan 2001 15:43:56 -0800
582 \fheader}
583 \fbody{
584 \fpart{ ID: 1, Content-type: text/plain
585 This is just a test message (#$((first + 1)))
586 \fpart}
587 \fbody}
588 \fmessage}
589 \fmessage{ id:msg-$(printf "%03d" $((first + 2)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 2)))
590 \fheader{
591 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-07) (inbox unread)
592 Subject: thread-naming: Newer changed subject
593 From: Notmuch Test Suite <test_suite@notmuchmail.org>
594 To: Notmuch Test Suite <test_suite@notmuchmail.org>
595 Date: Sun, 07 Jan 2001 15:43:56 -0800
596 \fheader}
597 \fbody{
598 \fpart{ ID: 1, Content-type: text/plain
599 This is just a test message (#$((first + 2)))
600 \fpart}
601 \fbody}
602 \fmessage}
603 \fmessage{ id:msg-$(printf "%03d" $((first + 3)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 3)))
604 \fheader{
605 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-08) (unread)
606 Subject: thread-naming: Final thread subject
607 From: Notmuch Test Suite <test_suite@notmuchmail.org>
608 To: Notmuch Test Suite <test_suite@notmuchmail.org>
609 Date: Mon, 08 Jan 2001 15:43:56 -0800
610 \fheader}
611 \fbody{
612 \fpart{ ID: 1, Content-type: text/plain
613 This is just a test message (#$((first + 3)))
614 \fpart}
615 \fbody}
616 \fmessage}
617 \fmessage{ id:msg-$(printf "%03d" $((first + 4)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 4)))
618 \fheader{
619 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-09) (inbox unread)
620 Subject: Re: thread-naming: Initial thread subject
621 From: Notmuch Test Suite <test_suite@notmuchmail.org>
622 To: Notmuch Test Suite <test_suite@notmuchmail.org>
623 Date: Tue, 09 Jan 2001 15:43:45 -0800
624 \fheader}
625 \fbody{
626 \fpart{ ID: 1, Content-type: text/plain
627 This is just a test message (#$((first + 4)))
628 \fpart}
629 \fbody}
630 \fmessage}
631 \fmessage{ id:msg-$(printf "%03d" $((first + 5)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 5)))
632 \fheader{
633 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-10) (inbox unread)
634 Subject: Aw: thread-naming: Initial thread subject
635 From: Notmuch Test Suite <test_suite@notmuchmail.org>
636 To: Notmuch Test Suite <test_suite@notmuchmail.org>
637 Date: Wed, 10 Jan 2001 15:43:45 -0800
638 \fheader}
639 \fbody{
640 \fpart{ ID: 1, Content-type: text/plain
641 This is just a test message (#$((first + 5)))
642 \fpart}
643 \fbody}
644 \fmessage}
645 \fmessage{ id:msg-$(printf "%03d" $((first + 6)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 6)))
646 \fheader{
647 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-11) (inbox unread)
648 Subject: Vs: thread-naming: Initial thread subject
649 From: Notmuch Test Suite <test_suite@notmuchmail.org>
650 To: Notmuch Test Suite <test_suite@notmuchmail.org>
651 Date: Thu, 11 Jan 2001 15:43:45 -0800
652 \fheader}
653 \fbody{
654 \fpart{ ID: 1, Content-type: text/plain
655 This is just a test message (#$((first + 6)))
656 \fpart}
657 \fbody}
658 \fmessage}
659 \fmessage{ id:msg-$(printf "%03d" $((first + 7)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 7)))
660 \fheader{
661 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-12) (inbox unread)
662 Subject: Sv: thread-naming: Initial thread subject
663 From: Notmuch Test Suite <test_suite@notmuchmail.org>
664 To: Notmuch Test Suite <test_suite@notmuchmail.org>
665 Date: Fri, 12 Jan 2001 15:43:45 -0800
666 \fheader}
667 \fbody{
668 \fpart{ ID: 1, Content-type: text/plain
669 This is just a test message (#$((first + 7)))
670 \fpart}
671 \fbody}
672 \fmessage}"
673
674 printf "\nTesting \"notmuch reply\" in several variations:\n"
675
676 printf " Basic reply...\t\t\t\t\t"
677 add_message '[from]="Sender <sender@example.com>"' \
678              [to]=test_suite@notmuchmail.org \
679              [subject]=notmuch-reply-test \
680             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
681             '[body]="basic reply test"'
682
683 output=$($NOTMUCH reply id:${gen_msg_id})
684 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
685 Subject: Re: notmuch-reply-test
686 To: Sender <sender@example.com>
687 Bcc: test_suite@notmuchmail.org
688 In-Reply-To: <${gen_msg_id}>
689 References: <${gen_msg_id}>
690
691 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
692 > basic reply test"
693
694 printf " Multiple recipients...\t\t\t\t"
695 add_message '[from]="Sender <sender@example.com>"' \
696             '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
697              [subject]=notmuch-reply-test \
698             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
699             '[body]="Multiple recipients"'
700
701 output=$($NOTMUCH reply id:${gen_msg_id})
702 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
703 Subject: Re: notmuch-reply-test
704 To: Sender <sender@example.com>, Someone Else <someone@example.com>
705 Bcc: test_suite@notmuchmail.org
706 In-Reply-To: <${gen_msg_id}>
707 References: <${gen_msg_id}>
708
709 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
710 > Multiple recipients"
711
712 printf " Reply with CC...\t\t\t\t"
713 add_message '[from]="Sender <sender@example.com>"' \
714              [to]=test_suite@notmuchmail.org \
715             '[cc]="Other Parties <cc@example.com>"' \
716              [subject]=notmuch-reply-test \
717             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
718             '[body]="reply with CC"'
719
720 output=$($NOTMUCH reply id:${gen_msg_id})
721 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
722 Subject: Re: notmuch-reply-test
723 To: Sender <sender@example.com>
724 Cc: Other Parties <cc@example.com>
725 Bcc: test_suite@notmuchmail.org
726 In-Reply-To: <${gen_msg_id}>
727 References: <${gen_msg_id}>
728
729 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
730 > reply with CC"
731
732 printf " Reply from alternate address...\t\t"
733 add_message '[from]="Sender <sender@example.com>"' \
734              [to]=test_suite_other@notmuchmail.org \
735              [subject]=notmuch-reply-test \
736             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
737             '[body]="reply from alternate address"'
738
739 output=$($NOTMUCH reply id:${gen_msg_id})
740 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
741 Subject: Re: notmuch-reply-test
742 To: Sender <sender@example.com>
743 Bcc: test_suite@notmuchmail.org
744 In-Reply-To: <${gen_msg_id}>
745 References: <${gen_msg_id}>
746
747 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
748 > reply from alternate address"
749
750 printf " Support for Reply-To...\t\t\t"
751 add_message '[from]="Sender <sender@example.com>"' \
752              [to]=test_suite@notmuchmail.org \
753              [subject]=notmuch-reply-test \
754             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
755             '[body]="support for reply-to"' \
756             '[reply-to]="Sender <elsewhere@example.com>"'
757
758 output=$($NOTMUCH reply id:${gen_msg_id})
759 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
760 Subject: Re: notmuch-reply-test
761 To: Sender <elsewhere@example.com>
762 Bcc: test_suite@notmuchmail.org
763 In-Reply-To: <${gen_msg_id}>
764 References: <${gen_msg_id}>
765
766 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
767 > support for reply-to"
768
769 printf " Un-munging Reply-To...\t\t\t\t"
770 add_message '[from]="Sender <sender@example.com>"' \
771             '[to]="Some List <list@example.com>"' \
772              [subject]=notmuch-reply-test \
773             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
774             '[body]="Un-munging Reply-To"' \
775             '[reply-to]="Evil Munging List <list@example.com>"'
776
777 output=$($NOTMUCH reply id:${gen_msg_id})
778 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
779 Subject: Re: notmuch-reply-test
780 To: Sender <sender@example.com>, Some List <list@example.com>
781 Bcc: test_suite@notmuchmail.org
782 In-Reply-To: <${gen_msg_id}>
783 References: <${gen_msg_id}>
784
785 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
786 > Un-munging Reply-To"
787
788 printf "\nTesting handling of uuencoded data:\n"
789
790 add_message [subject]=uuencodetest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
791 '[body]="This message is used to ensure that notmuch correctly handles a
792 message containing a block of uuencoded data. First, we have a marker
793 this content beforeuudata . Then we beging the uunencoded data itself:
794
795 begin 644 bogus-uuencoded-data
796 M0123456789012345678901234567890123456789012345678901234567890
797 MOBVIOUSLY, THIS IS NOT ANY SORT OF USEFUL UUNECODED DATA.    
798 MINSTEAD THIS IS JUST A WAY TO ENSURE THAT THIS BLOCK OF DATA 
799 MIS CORRECTLY IGNORED WHEN NOTMUCH CREATES ITS INDEX. SO WE   
800 MINCLUDE A DURINGUUDATA MARKER THAT SHOULD NOT RESULT IN ANY  
801 MSEARCH RESULT.                                               
802 \`
803 end
804
805 Finally, we have our afteruudata marker as well."'
806
807 printf " Ensure content before uu data is indexed...\t"
808 output=$($NOTMUCH search beforeuudata | notmuch_search_sanitize)
809 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
810 printf " Ensure uu data is not indexed...\t\t"
811 output=$($NOTMUCH search DURINGUUDATA | notmuch_search_sanitize)
812 pass_if_equal "$output" ""
813 printf " Ensure content after uu data is indexed...\t"
814 output=$($NOTMUCH search afteruudata | notmuch_search_sanitize)
815 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
816
817 printf "\nTesting \"notmuch dump\" and \"notmuch restore\":\n"
818
819 printf " Dumping all tags...\t\t\t\t"
820 $NOTMUCH dump dump.expected
821 pass_if_equal "$?" "0"
822
823 printf " Clearing all tags...\t\t\t\t"
824 sed -e 's/(\([^(]*\))$/()/' < dump.expected > clear.expected
825 $NOTMUCH restore clear.expected
826 $NOTMUCH dump clear.actual
827 pass_if_equal "$(< clear.actual)" "$(< clear.expected)"
828
829 printf " Restoring original tags...\t\t\t"
830 $NOTMUCH restore dump.expected
831 $NOTMUCH dump dump.actual
832 pass_if_equal "$(< dump.actual)" "$(< dump.expected)"
833
834 printf " Restore with nothing to do...\t\t\t"
835 $NOTMUCH restore dump.expected
836 pass_if_equal "$?" "0"
837
838 printf "\nTesting threading when messages received out of order:\n"
839 printf " Adding initial child message...\t\t"
840 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
841 output=$(NOTMUCH_NEW)
842 pass_if_equal "$output" "Added 1 new message to the database."
843 printf " Searching returns the message...\t\t"
844 output=$($NOTMUCH search foo | notmuch_search_sanitize)
845 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; brokenthreadtest (inbox unread)"
846 printf " Adding second child message...\t\t\t"
847 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
848 output=$(NOTMUCH_NEW)
849 pass_if_equal "$output" "Added 1 new message to the database."
850 printf " Searching returns both messages in one thread..."
851 output=$($NOTMUCH search foo | notmuch_search_sanitize)
852 pass_if_equal "$output" "thread:XXX   2000-01-01 [2/2] Notmuch Test Suite; brokenthreadtest (inbox unread)"
853 printf " Adding parent message...\t\t\t"
854 generate_message [body]=foo [id]=parent-id [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
855 output=$(NOTMUCH_NEW)
856 pass_if_equal "$output" "Added 1 new message to the database."
857 printf " Searching returns all three messages in one thread..."
858 output=$($NOTMUCH search foo | notmuch_search_sanitize)
859 pass_if_equal "$output" "thread:XXX   2000-01-01 [3/3] Notmuch Test Suite; brokenthreadtest (inbox unread)"
860
861 echo ""
862 echo "Notmuch test suite complete."
863
864 if [ "$test_failures" = "0" ]; then
865     echo "All $tests tests passed."
866     rm -rf ${TEST_DIR}
867 else
868     echo "$test_failures/$tests tests failed. The failures can be investigated in:"
869     echo "${TEST_DIR}"
870 fi
871
872 echo ""
873
874 exit $test_failures