]> git.notmuchmail.org Git - notmuch/blob - test/notmuch-test
First tests for JSON output and UTF-8 in mail body and subject
[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 " Show message: json...\t\t\t\t"
453 add_message '[subject]="json-show-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="json-show-message"'
454 output=$($NOTMUCH show --format=json 'json-show-message')
455 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"}]}, []]]]'
456
457 printf " Search message: json...\t\t\t"
458 add_message '[subject]="json-search-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="json-search-message"'
459 output=$($NOTMUCH search --format=json 'json-search-message' | notmuch_search_sanitize)
460 pass_if_equal "$output" '[{"thread": "XXX",
461 "timestamp": 946728000,
462 "matched": 1,
463 "total": 1,
464 "authors": "Notmuch Test Suite",
465 "subject": "json-search-subject",
466 "tags": ["inbox", "unread"]}]'
467
468 printf " Search by subject (utf-8):...\t\t\t"
469 add_message [subject]=utf8-sübjéct '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
470 output=$($NOTMUCH search subject:utf8-sübjéct | notmuch_search_sanitize)
471 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
472
473 printf " Search body (utf-8):...\t\t\t"
474 add_message '[subject]="utf8-message-body-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="message body utf8: bödý"'
475 output=$($NOTMUCH search 'bödý' | notmuch_search_sanitize)
476 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)"
477
478 printf " Show message: json, utf-8...\t\t\t"
479 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"'
480 output=$($NOTMUCH show --format=json 'jsön-show-méssage')
481 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"}]}, []]]]'
482
483 printf " Search message: json, utf-8...\t\t\t"
484 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"'
485 output=$($NOTMUCH search --format=json 'jsön-search-méssage' | notmuch_search_sanitize)
486 pass_if_equal "$output" '[{"thread": "XXX",
487 "timestamp": 946728000,
488 "matched": 1,
489 "total": 1,
490 "authors": "Notmuch Test Suite",
491 "subject": "json-search-utf8-body-sübjéct",
492 "tags": ["inbox", "unread"]}]'
493
494 printf "\nTesting naming of threads with changing subject:\n"
495 add_message '[subject]="thread-naming: Initial thread subject"' \
496             '[date]="Fri, 05 Jan 2001 15:43:56 -0800"'
497 first=${gen_msg_cnt}
498 parent=${gen_msg_id}
499 add_message '[subject]="thread-naming: Older changed subject"' \
500             '[date]="Sat, 06 Jan 2001 15:43:56 -0800"' \
501             "[in-reply-to]=\<$parent\>"
502 add_message '[subject]="thread-naming: Newer changed subject"' \
503             '[date]="Sun, 07 Jan 2001 15:43:56 -0800"' \
504             "[in-reply-to]=\<$parent\>"
505 add_message '[subject]="thread-naming: Final thread subject"' \
506             '[date]="Mon, 08 Jan 2001 15:43:56 -0800"' \
507             "[in-reply-to]=\<$parent\>"
508 final=${gen_msg_id}
509
510 printf " Initial thread name (oldest-first search)...\t"
511 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
512 pass_if_equal "$output" "thread:XXX   2001-01-05 [4/4] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
513
514 printf " Initial thread name (newest-first search)...\t"
515 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
516 pass_if_equal "$output" "thread:XXX   2001-01-08 [4/4] Notmuch Test Suite; thread-naming: Final thread subject (inbox unread)"
517
518 # Remove oldest and newest messages from search results
519 $NOTMUCH tag -inbox id:$parent or id:$final
520
521 printf " Changed thread name (oldest-first search)...\t"
522 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
523 pass_if_equal "$output" "thread:XXX   2001-01-06 [2/4] Notmuch Test Suite; thread-naming: Older changed subject (inbox unread)"
524
525 printf " Changed thread name (newest-first search)...\t"
526 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
527 pass_if_equal "$output" "thread:XXX   2001-01-07 [2/4] Notmuch Test Suite; thread-naming: Newer changed subject (inbox unread)"
528
529 printf " Ignore added reply prefix (Re:)...\t\t"
530 add_message '[subject]="Re: thread-naming: Initial thread subject"' \
531             '[date]="Tue, 09 Jan 2001 15:43:45 -0800"' \
532             "[in-reply-to]=\<$parent\>"
533 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
534 pass_if_equal "$output" "thread:XXX   2001-01-09 [3/5] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
535
536 printf " Ignore added reply prefix (Aw:)...\t\t"
537 add_message '[subject]="Aw: thread-naming: Initial thread subject"' \
538             '[date]="Wed, 10 Jan 2001 15:43:45 -0800"' \
539             "[in-reply-to]=\<$parent\>"
540 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
541 pass_if_equal "$output" "thread:XXX   2001-01-10 [4/6] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
542
543 printf " Ignore added reply prefix (Vs:)...\t\t"
544 add_message '[subject]="Vs: thread-naming: Initial thread subject"' \
545             '[date]="Thu, 11 Jan 2001 15:43:45 -0800"' \
546             "[in-reply-to]=\<$parent\>"
547 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
548 pass_if_equal "$output" "thread:XXX   2001-01-11 [5/7] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
549
550 printf " Ignore added reply prefix (Sv:)...\t\t"
551 add_message '[subject]="Sv: thread-naming: Initial thread subject"' \
552             '[date]="Fri, 12 Jan 2001 15:43:45 -0800"' \
553             "[in-reply-to]=\<$parent\>"
554 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
555 pass_if_equal "$output" "thread:XXX   2001-01-12 [6/8] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
556
557 printf " Test order of messages in \"notmuch show\"\t"
558 output=$($NOTMUCH show thread-naming | notmuch_show_sanitize)
559 pass_if_equal "$output" "\fmessage{ id:msg-$(printf "%03d" $first)@notmuch-test-suite depth:0 match:1 filename:/XXX/mail/msg-$(printf "%03d" $first)
560 \fheader{
561 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (unread)
562 Subject: thread-naming: Initial thread subject
563 From: Notmuch Test Suite <test_suite@notmuchmail.org>
564 To: Notmuch Test Suite <test_suite@notmuchmail.org>
565 Date: Fri, 05 Jan 2001 15:43:56 -0800
566 \fheader}
567 \fbody{
568 \fpart{ ID: 1, Content-type: text/plain
569 This is just a test message (#$first)
570 \fpart}
571 \fbody}
572 \fmessage}
573 \fmessage{ id:msg-$(printf "%03d" $((first + 1)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 1)))
574 \fheader{
575 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-06) (inbox unread)
576 Subject: thread-naming: Older changed subject
577 From: Notmuch Test Suite <test_suite@notmuchmail.org>
578 To: Notmuch Test Suite <test_suite@notmuchmail.org>
579 Date: Sat, 06 Jan 2001 15:43:56 -0800
580 \fheader}
581 \fbody{
582 \fpart{ ID: 1, Content-type: text/plain
583 This is just a test message (#$((first + 1)))
584 \fpart}
585 \fbody}
586 \fmessage}
587 \fmessage{ id:msg-$(printf "%03d" $((first + 2)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 2)))
588 \fheader{
589 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-07) (inbox unread)
590 Subject: thread-naming: Newer changed subject
591 From: Notmuch Test Suite <test_suite@notmuchmail.org>
592 To: Notmuch Test Suite <test_suite@notmuchmail.org>
593 Date: Sun, 07 Jan 2001 15:43:56 -0800
594 \fheader}
595 \fbody{
596 \fpart{ ID: 1, Content-type: text/plain
597 This is just a test message (#$((first + 2)))
598 \fpart}
599 \fbody}
600 \fmessage}
601 \fmessage{ id:msg-$(printf "%03d" $((first + 3)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 3)))
602 \fheader{
603 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-08) (unread)
604 Subject: thread-naming: Final thread subject
605 From: Notmuch Test Suite <test_suite@notmuchmail.org>
606 To: Notmuch Test Suite <test_suite@notmuchmail.org>
607 Date: Mon, 08 Jan 2001 15:43:56 -0800
608 \fheader}
609 \fbody{
610 \fpart{ ID: 1, Content-type: text/plain
611 This is just a test message (#$((first + 3)))
612 \fpart}
613 \fbody}
614 \fmessage}
615 \fmessage{ id:msg-$(printf "%03d" $((first + 4)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 4)))
616 \fheader{
617 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-09) (inbox unread)
618 Subject: Re: thread-naming: Initial thread subject
619 From: Notmuch Test Suite <test_suite@notmuchmail.org>
620 To: Notmuch Test Suite <test_suite@notmuchmail.org>
621 Date: Tue, 09 Jan 2001 15:43:45 -0800
622 \fheader}
623 \fbody{
624 \fpart{ ID: 1, Content-type: text/plain
625 This is just a test message (#$((first + 4)))
626 \fpart}
627 \fbody}
628 \fmessage}
629 \fmessage{ id:msg-$(printf "%03d" $((first + 5)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 5)))
630 \fheader{
631 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-10) (inbox unread)
632 Subject: Aw: thread-naming: Initial thread subject
633 From: Notmuch Test Suite <test_suite@notmuchmail.org>
634 To: Notmuch Test Suite <test_suite@notmuchmail.org>
635 Date: Wed, 10 Jan 2001 15:43:45 -0800
636 \fheader}
637 \fbody{
638 \fpart{ ID: 1, Content-type: text/plain
639 This is just a test message (#$((first + 5)))
640 \fpart}
641 \fbody}
642 \fmessage}
643 \fmessage{ id:msg-$(printf "%03d" $((first + 6)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 6)))
644 \fheader{
645 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-11) (inbox unread)
646 Subject: Vs: thread-naming: Initial thread subject
647 From: Notmuch Test Suite <test_suite@notmuchmail.org>
648 To: Notmuch Test Suite <test_suite@notmuchmail.org>
649 Date: Thu, 11 Jan 2001 15:43:45 -0800
650 \fheader}
651 \fbody{
652 \fpart{ ID: 1, Content-type: text/plain
653 This is just a test message (#$((first + 6)))
654 \fpart}
655 \fbody}
656 \fmessage}
657 \fmessage{ id:msg-$(printf "%03d" $((first + 7)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 7)))
658 \fheader{
659 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-12) (inbox unread)
660 Subject: Sv: thread-naming: Initial thread subject
661 From: Notmuch Test Suite <test_suite@notmuchmail.org>
662 To: Notmuch Test Suite <test_suite@notmuchmail.org>
663 Date: Fri, 12 Jan 2001 15:43:45 -0800
664 \fheader}
665 \fbody{
666 \fpart{ ID: 1, Content-type: text/plain
667 This is just a test message (#$((first + 7)))
668 \fpart}
669 \fbody}
670 \fmessage}"
671
672 printf "\nTesting \"notmuch reply\" in several variations:\n"
673
674 printf " Basic reply...\t\t\t\t\t"
675 add_message '[from]="Sender <sender@example.com>"' \
676              [to]=test_suite@notmuchmail.org \
677              [subject]=notmuch-reply-test \
678             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
679             '[body]="basic reply test"'
680
681 output=$($NOTMUCH reply id:${gen_msg_id})
682 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
683 Subject: Re: notmuch-reply-test
684 To: Sender <sender@example.com>
685 Bcc: test_suite@notmuchmail.org
686 In-Reply-To: <${gen_msg_id}>
687 References: <${gen_msg_id}>
688
689 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
690 > basic reply test"
691
692 printf " Multiple recipients...\t\t\t\t"
693 add_message '[from]="Sender <sender@example.com>"' \
694             '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
695              [subject]=notmuch-reply-test \
696             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
697             '[body]="Multiple recipients"'
698
699 output=$($NOTMUCH reply id:${gen_msg_id})
700 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
701 Subject: Re: notmuch-reply-test
702 To: Sender <sender@example.com>, Someone Else <someone@example.com>
703 Bcc: test_suite@notmuchmail.org
704 In-Reply-To: <${gen_msg_id}>
705 References: <${gen_msg_id}>
706
707 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
708 > Multiple recipients"
709
710 printf " Reply with CC...\t\t\t\t"
711 add_message '[from]="Sender <sender@example.com>"' \
712              [to]=test_suite@notmuchmail.org \
713             '[cc]="Other Parties <cc@example.com>"' \
714              [subject]=notmuch-reply-test \
715             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
716             '[body]="reply with CC"'
717
718 output=$($NOTMUCH reply id:${gen_msg_id})
719 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
720 Subject: Re: notmuch-reply-test
721 To: Sender <sender@example.com>
722 Cc: Other Parties <cc@example.com>
723 Bcc: test_suite@notmuchmail.org
724 In-Reply-To: <${gen_msg_id}>
725 References: <${gen_msg_id}>
726
727 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
728 > reply with CC"
729
730 printf " Reply from alternate address...\t\t"
731 add_message '[from]="Sender <sender@example.com>"' \
732              [to]=test_suite_other@notmuchmail.org \
733              [subject]=notmuch-reply-test \
734             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
735             '[body]="reply from alternate address"'
736
737 output=$($NOTMUCH reply id:${gen_msg_id})
738 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
739 Subject: Re: notmuch-reply-test
740 To: Sender <sender@example.com>
741 Bcc: test_suite@notmuchmail.org
742 In-Reply-To: <${gen_msg_id}>
743 References: <${gen_msg_id}>
744
745 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
746 > reply from alternate address"
747
748 printf " Support for Reply-To...\t\t\t"
749 add_message '[from]="Sender <sender@example.com>"' \
750              [to]=test_suite@notmuchmail.org \
751              [subject]=notmuch-reply-test \
752             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
753             '[body]="support for reply-to"' \
754             '[reply-to]="Sender <elsewhere@example.com>"'
755
756 output=$($NOTMUCH reply id:${gen_msg_id})
757 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
758 Subject: Re: notmuch-reply-test
759 To: Sender <elsewhere@example.com>
760 Bcc: test_suite@notmuchmail.org
761 In-Reply-To: <${gen_msg_id}>
762 References: <${gen_msg_id}>
763
764 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
765 > support for reply-to"
766
767 printf " Un-munging Reply-To...\t\t\t\t"
768 add_message '[from]="Sender <sender@example.com>"' \
769             '[to]="Some List <list@example.com>"' \
770              [subject]=notmuch-reply-test \
771             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
772             '[body]="Un-munging Reply-To"' \
773             '[reply-to]="Evil Munging List <list@example.com>"'
774
775 output=$($NOTMUCH reply id:${gen_msg_id})
776 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
777 Subject: Re: notmuch-reply-test
778 To: Sender <sender@example.com>, Some List <list@example.com>
779 Bcc: test_suite@notmuchmail.org
780 In-Reply-To: <${gen_msg_id}>
781 References: <${gen_msg_id}>
782
783 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
784 > Un-munging Reply-To"
785
786 printf "\nTesting handling of uuencoded data:\n"
787
788 add_message [subject]=uuencodetest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
789 '[body]="This message is used to ensure that notmuch correctly handles a
790 message containing a block of uuencoded data. First, we have a marker
791 this content beforeuudata . Then we beging the uunencoded data itself:
792
793 begin 644 bogus-uuencoded-data
794 M0123456789012345678901234567890123456789012345678901234567890
795 MOBVIOUSLY, THIS IS NOT ANY SORT OF USEFUL UUNECODED DATA.    
796 MINSTEAD THIS IS JUST A WAY TO ENSURE THAT THIS BLOCK OF DATA 
797 MIS CORRECTLY IGNORED WHEN NOTMUCH CREATES ITS INDEX. SO WE   
798 MINCLUDE A DURINGUUDATA MARKER THAT SHOULD NOT RESULT IN ANY  
799 MSEARCH RESULT.                                               
800 \`
801 end
802
803 Finally, we have our afteruudata marker as well."'
804
805 printf " Ensure content before uu data is indexed...\t"
806 output=$($NOTMUCH search beforeuudata | notmuch_search_sanitize)
807 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
808 printf " Ensure uu data is not indexed...\t\t"
809 output=$($NOTMUCH search DURINGUUDATA | notmuch_search_sanitize)
810 pass_if_equal "$output" ""
811 printf " Ensure content after uu data is indexed...\t"
812 output=$($NOTMUCH search afteruudata | notmuch_search_sanitize)
813 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
814
815 printf "\nTesting \"notmuch dump\" and \"notmuch restore\":\n"
816
817 printf " Dumping all tags...\t\t\t\t"
818 $NOTMUCH dump dump.expected
819 pass_if_equal "$?" "0"
820
821 printf " Clearing all tags...\t\t\t\t"
822 sed -e 's/(\([^(]*\))$/()/' < dump.expected > clear.expected
823 $NOTMUCH restore clear.expected
824 $NOTMUCH dump clear.actual
825 pass_if_equal "$(< clear.actual)" "$(< clear.expected)"
826
827 printf " Restoring original tags...\t\t\t"
828 $NOTMUCH restore dump.expected
829 $NOTMUCH dump dump.actual
830 pass_if_equal "$(< dump.actual)" "$(< dump.expected)"
831
832 printf " Restore with nothing to do...\t\t\t"
833 $NOTMUCH restore dump.expected
834 pass_if_equal "$?" "0"
835
836 printf "\nTesting threading when messages received out of order:\n"
837 printf " Adding initial child message...\t\t"
838 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
839 output=$(NOTMUCH_NEW)
840 pass_if_equal "$output" "Added 1 new message to the database."
841 printf " Searching returns the message...\t\t"
842 output=$($NOTMUCH search foo | notmuch_search_sanitize)
843 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; brokenthreadtest (inbox unread)"
844 printf " Adding second child message...\t\t\t"
845 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
846 output=$(NOTMUCH_NEW)
847 pass_if_equal "$output" "Added 1 new message to the database."
848 printf " Searching returns both messages in one thread..."
849 output=$($NOTMUCH search foo | notmuch_search_sanitize)
850 pass_if_equal "$output" "thread:XXX   2000-01-01 [2/2] Notmuch Test Suite; brokenthreadtest (inbox unread)"
851 printf " Adding parent message...\t\t\t"
852 generate_message [body]=foo [id]=parent-id [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
853 output=$(NOTMUCH_NEW)
854 pass_if_equal "$output" "Added 1 new message to the database."
855 printf " Searching returns all three messages in one thread..."
856 output=$($NOTMUCH search foo | notmuch_search_sanitize)
857 pass_if_equal "$output" "thread:XXX   2000-01-01 [3/3] Notmuch Test Suite; brokenthreadtest (inbox unread)"
858
859 echo ""
860 echo "Notmuch test suite complete."
861
862 if [ "$test_failures" = "0" ]; then
863     echo "All $tests tests passed."
864     rm -rf ${TEST_DIR}
865 else
866     echo "$test_failures/$tests tests failed. The failures can be investigated in:"
867     echo "${TEST_DIR}"
868 fi
869
870 echo ""
871
872 exit $test_failures