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