10 while [ -n "$dir" ]; do
17 if [ "$dir" = "/" ]; then
25 increment_mtime_amount=0
30 increment_mtime_amount=$((increment_mtime_amount + 1))
31 touch -d "+${increment_mtime_amount} seconds" $dir
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.
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
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:
45 # [dir]=directory/of/choice
47 # Generate the message in directory 'directory/of/choice' within
48 # the mail store. The directory will be created if necessary.
52 # Text to use as the body of the email message
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"'
59 # Values for email headers. If not provided, default values will
60 # be generated instead.
62 # '[cc]="Some User <user@example.com>"'
63 # [reply-to]=some-address
64 # [in-reply-to]=<message-id>
66 # Additional values for email headers. If these are not provided
67 # then the relevant headers will simply not appear in the
72 # Controls the message-id of the created message.
78 # This is our (bash-specific) magic for doing named parameters
79 local -A template="($@)"
80 local additional_headers
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"
87 gen_msg_name="msg-${template[id]}"
88 gen_msg_id="${template[id]}"
91 if [ -z "${template[dir]}" ]; then
92 gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
94 gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
95 mkdir -p $(dirname $gen_msg_filename)
98 if [ -z "${template[body]}" ]; then
99 template[body]="This is just a test message (#${gen_msg_cnt})"
102 if [ -z "${template[from]}" ]; then
103 template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
106 if [ -z "${template[to]}" ]; then
107 template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
110 if [ -z "${template[subject]}" ]; then
111 template[subject]="Test message #${gen_msg_cnt}"
114 if [ -z "${template[date]}" ]; then
115 template[date]="Tue, 05 Jan 2001 15:43:57 -0800"
118 additional_headers=""
119 if [ ! -z "${template[reply-to]}" ]; then
120 additional_headers="Reply-To: ${template[reply-to]}
121 ${additional_headers}"
124 if [ ! -z "${template[in-reply-to]}" ]; then
125 additional_headers="In-Reply-To: ${template[in-reply-to]}
126 ${additional_headers}"
129 if [ ! -z "${template[cc]}" ]; then
130 additional_headers="Cc: ${template[cc]}
131 ${additional_headers}"
134 cat <<EOF >$gen_msg_filename
135 From: ${template[from]}
137 Message-Id: <${gen_msg_id}>
138 Subject: ${template[subject]}
139 Date: ${template[date]}
140 ${additional_headers}
144 # Ensure that the mtime of the containing directory is updated
145 increment_mtime $(dirname ${gen_msg_filename})
148 # Generate a new message and add it to the index.
150 # All of the arguments and return values supported by generate_message
151 # are also supported here, so see that function for details.
154 generate_message "$@"
156 $NOTMUCH new > /dev/null
169 if [ "$output" = "$expected" ]; then
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))
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))
188 $NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
191 notmuch_search_sanitize ()
193 sed -r -e 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
196 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
197 notmuch_show_sanitize ()
199 sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
208 cat <<EOF > ${NOTMUCH_CONFIG}
213 name=Notmuch Test Suite
214 primary_email=test_suite@notmuchmail.org
215 other_email=test_suite_other@notmuchmail.org
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."
223 printf " Single new message...\t\t\t\t"
225 output=$(NOTMUCH_NEW)
226 pass_if_equal "$output" "Added 1 new message to the database."
228 printf " Multiple new messages...\t\t\t"
231 output=$(NOTMUCH_NEW)
232 pass_if_equal "$output" "Added 2 new messages to the database."
234 printf " No new messages (non-empty DB)...\t\t"
235 output=$(NOTMUCH_NEW)
236 pass_if_equal "$output" "No new mail."
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
244 output=$(NOTMUCH_NEW)
245 pass_if_equal "$output" "Added 1 new message to the database."
247 printf " Alternate inode order...\t\t\t"
249 rm -rf ${MAIL_DIR}/.notmuch
250 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
252 generate_message [dir]=abc
254 output=$(NOTMUCH_NEW)
255 pass_if_equal "$output" "Added 1 new message to the database."
257 printf " Message moved in...\t\t\t\t"
258 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
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."
270 printf " Renamed message...\t\t\t\t"
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."
279 printf " Deleted message...\t\t\t\t"
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."
286 printf " Renamed directory...\t\t\t\t"
288 generate_message [dir]=dir
289 generate_message [dir]=dir
290 generate_message [dir]=dir
292 $NOTMUCH new > /dev/null
294 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
295 increment_mtime ${MAIL_DIR}
297 output=$(NOTMUCH_NEW)
298 pass_if_equal "$output" "No new mail. Detected 3 file renames."
300 printf " Deleted directory...\t\t\t\t"
302 rm -rf ${MAIL_DIR}/dir-renamed
303 increment_mtime ${MAIL_DIR}
305 output=$(NOTMUCH_NEW)
306 pass_if_equal "$output" "No new mail. Removed 3 messages."
308 printf " New directory (at end of list)...\t\t"
310 generate_message [dir]=zzz
311 generate_message [dir]=zzz
312 generate_message [dir]=zzz
314 output=$(NOTMUCH_NEW)
315 pass_if_equal "$output" "Added 3 new messages to the database."
317 printf " Deleted directory (end of list)...\t\t"
319 rm -rf ${MAIL_DIR}/zzz
320 increment_mtime ${MAIL_DIR}
322 output=$(NOTMUCH_NEW)
323 pass_if_equal "$output" "No new mail. Removed 3 messages."
325 printf " New symlink to directory...\t\t\t"
327 rm -rf ${MAIL_DIR}/.notmuch
328 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
331 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
333 output=$(NOTMUCH_NEW)
334 pass_if_equal "$output" "Added 1 new message to the database."
336 printf " New symlink to a file...\t\t\t"
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."
346 printf " New two-level directory...\t\t\t"
348 generate_message [dir]=two/levels
349 generate_message [dir]=two/levels
350 generate_message [dir]=two/levels
352 output=$(NOTMUCH_NEW)
353 pass_if_equal "$output" "Added 3 new messages to the database."
355 printf " Deleted two-level directory...\t\t\t"
357 rm -rf ${MAIL_DIR}/two
358 increment_mtime ${MAIL_DIR}
360 output=$(NOTMUCH_NEW)
361 pass_if_equal "$output" "No new mail. Removed 3 messages."
363 printf "\nTesting \"notmuch search\" in several variations:\n"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
459 printf "\nTesting --format=json output:\n"
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"}]}, []]]]'
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,
473 "authors": "Notmuch Test Suite",
474 "subject": "json-search-subject",
475 "tags": ["inbox", "unread"]}]'
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)"
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"}]}, []]]]'
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,
494 "authors": "Notmuch Test Suite",
495 "subject": "json-search-utf8-body-sübjéct",
496 "tags": ["inbox", "unread"]}]'
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"'
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\>"
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)"
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)"
522 # Remove oldest and newest messages from search results
523 $NOTMUCH tag -inbox id:$parent or id:$final
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)"
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)"
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)"
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)"
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)"
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)"
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)
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
572 \fpart{ ID: 1, Content-type: text/plain
573 This is just a test message (#$first)
577 \fmessage{ id:msg-$(printf "%03d" $((first + 1)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 1)))
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
586 \fpart{ ID: 1, Content-type: text/plain
587 This is just a test message (#$((first + 1)))
591 \fmessage{ id:msg-$(printf "%03d" $((first + 2)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 2)))
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
600 \fpart{ ID: 1, Content-type: text/plain
601 This is just a test message (#$((first + 2)))
605 \fmessage{ id:msg-$(printf "%03d" $((first + 3)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 3)))
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
614 \fpart{ ID: 1, Content-type: text/plain
615 This is just a test message (#$((first + 3)))
619 \fmessage{ id:msg-$(printf "%03d" $((first + 4)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 4)))
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
628 \fpart{ ID: 1, Content-type: text/plain
629 This is just a test message (#$((first + 4)))
633 \fmessage{ id:msg-$(printf "%03d" $((first + 5)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 5)))
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
642 \fpart{ ID: 1, Content-type: text/plain
643 This is just a test message (#$((first + 5)))
647 \fmessage{ id:msg-$(printf "%03d" $((first + 6)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 6)))
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
656 \fpart{ ID: 1, Content-type: text/plain
657 This is just a test message (#$((first + 6)))
661 \fmessage{ id:msg-$(printf "%03d" $((first + 7)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 7)))
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
670 \fpart{ ID: 1, Content-type: text/plain
671 This is just a test message (#$((first + 7)))
676 printf "\nTesting \"notmuch reply\" in several variations:\n"
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"'
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}>
693 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
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"'
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}>
711 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
712 > Multiple recipients"
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"'
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}>
731 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
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"'
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}>
749 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
750 > reply from alternate address"
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>"'
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}>
768 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
769 > support for reply-to"
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>"'
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}>
787 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
788 > Un-munging Reply-To"
790 printf "\nTesting handling of uuencoded data:\n"
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:
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
807 Finally, we have our afteruudata marker as well."'
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)"
819 printf "\nTesting \"notmuch dump\" and \"notmuch restore\":\n"
821 printf " Dumping all tags...\t\t\t\t"
822 $NOTMUCH dump dump.expected
823 pass_if_equal "$?" "0"
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)"
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)"
836 printf " Restore with nothing to do...\t\t\t"
837 $NOTMUCH restore dump.expected
838 pass_if_equal "$?" "0"
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)"
864 echo "Notmuch test suite complete."
866 if [ "$test_failures" = "0" ]; then
867 echo "All $tests tests passed."
870 echo "$test_failures/$tests tests failed. The failures can be investigated in:"