8 while [ -n "$dir" ]; do
15 if [ "$dir" = "/" ]; then
23 increment_mtime_amount=0
28 increment_mtime_amount=$((increment_mtime_amount + 1))
29 touch -d "+${increment_mtime_amount} seconds" $dir
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.
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
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:
43 # [dir]=directory/of/choice
45 # Generate the message in directory 'directory/of/choice' within
46 # the mail store. The directory will be created if necessary.
50 # Text to use as the body of the email message
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"'
57 # Values for email headers. If not provided, default values will
58 # be generated instead.
60 # '[cc]="Some User <user@example.com>"'
61 # [reply-to]=some-address
62 # [in-reply-to]=<message-id>
64 # Additional values for email headers. If these are not provided
65 # then the relevant headers will simply not appear in the
70 # Controls the message-id of the created message.
76 # This is our (bash-specific) magic for doing named parameters
77 local -A template="($@)"
78 local additional_headers
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"
85 gen_msg_name="msg-${template[id]}"
86 gen_msg_id="${template[id]}"
89 if [ -z "${template[dir]}" ]; then
90 gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
92 gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
93 mkdir -p $(dirname $gen_msg_filename)
96 if [ -z "${template[body]}" ]; then
97 template[body]="This is just a test message (#${gen_msg_cnt})"
100 if [ -z "${template[from]}" ]; then
101 template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
104 if [ -z "${template[to]}" ]; then
105 template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
108 if [ -z "${template[subject]}" ]; then
109 template[subject]="Test message #${gen_msg_cnt}"
112 if [ -z "${template[date]}" ]; then
113 template[date]="Tue, 05 Jan 2001 15:43:57 -0800"
116 additional_headers=""
117 if [ ! -z "${template[reply-to]}" ]; then
118 additional_headers="Reply-To: ${template[reply-to]}
119 ${additional_headers}"
122 if [ ! -z "${template[in-reply-to]}" ]; then
123 additional_headers="In-Reply-To: ${template[in-reply-to]}
124 ${additional_headers}"
127 if [ ! -z "${template[cc]}" ]; then
128 additional_headers="Cc: ${template[cc]}
129 ${additional_headers}"
132 cat <<EOF >$gen_msg_filename
133 From: ${template[from]}
135 Message-Id: <${gen_msg_id}>
136 Subject: ${template[subject]}
137 Date: ${template[date]}
138 ${additional_headers}
142 # Ensure that the mtime of the containing directory is updated
143 increment_mtime $(dirname ${gen_msg_filename})
146 # Generate a new message and add it to the index.
148 # All of the arguments and return values supported by generate_message
149 # are also supported here, so see that function for details.
152 generate_message "$@"
154 $NOTMUCH new > /dev/null
167 if [ "$output" = "$expected" ]; then
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))
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))
186 $NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
189 notmuch_search_sanitize ()
191 sed -r -e 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
194 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
195 notmuch_show_sanitize ()
197 sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
206 cat <<EOF > ${NOTMUCH_CONFIG}
211 name=Notmuch Test Suite
212 primary_email=test_suite@notmuchmail.org
213 other_email=test_suite_other@notmuchmail.org
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."
221 printf " Single new message...\t\t\t\t"
223 output=$(NOTMUCH_NEW)
224 pass_if_equal "$output" "Added 1 new message to the database."
226 printf " Multiple new messages...\t\t\t"
229 output=$(NOTMUCH_NEW)
230 pass_if_equal "$output" "Added 2 new messages to the database."
232 printf " No new messages (non-empty DB)...\t\t"
233 output=$(NOTMUCH_NEW)
234 pass_if_equal "$output" "No new mail."
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
242 output=$(NOTMUCH_NEW)
243 pass_if_equal "$output" "Added 1 new message to the database."
245 printf " Alternate inode order...\t\t\t"
247 rm -rf ${MAIL_DIR}/.notmuch
248 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
250 generate_message [dir]=abc
252 output=$(NOTMUCH_NEW)
253 pass_if_equal "$output" "Added 1 new message to the database."
255 printf " Message moved in...\t\t\t\t"
256 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
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."
268 printf " Renamed message...\t\t\t\t"
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."
277 printf " Deleted message...\t\t\t\t"
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."
284 printf " Renamed directory...\t\t\t\t"
286 generate_message [dir]=dir
287 generate_message [dir]=dir
288 generate_message [dir]=dir
290 $NOTMUCH new > /dev/null
292 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
293 increment_mtime ${MAIL_DIR}
295 output=$(NOTMUCH_NEW)
296 pass_if_equal "$output" "No new mail. Detected 3 file renames."
298 printf " Deleted directory...\t\t\t\t"
300 rm -rf ${MAIL_DIR}/dir-renamed
301 increment_mtime ${MAIL_DIR}
303 output=$(NOTMUCH_NEW)
304 pass_if_equal "$output" "No new mail. Removed 3 messages."
306 printf " New directory (at end of list)...\t\t"
308 generate_message [dir]=zzz
309 generate_message [dir]=zzz
310 generate_message [dir]=zzz
312 output=$(NOTMUCH_NEW)
313 pass_if_equal "$output" "Added 3 new messages to the database."
315 printf " Deleted directory (end of list)...\t\t"
317 rm -rf ${MAIL_DIR}/zzz
318 increment_mtime ${MAIL_DIR}
320 output=$(NOTMUCH_NEW)
321 pass_if_equal "$output" "No new mail. Removed 3 messages."
323 printf " New symlink to directory...\t\t\t"
325 rm -rf ${MAIL_DIR}/.notmuch
326 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
329 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
331 output=$(NOTMUCH_NEW)
332 pass_if_equal "$output" "Added 1 new message to the database."
334 printf " New symlink to a file...\t\t\t"
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."
344 printf " New two-level directory...\t\t\t"
346 generate_message [dir]=two/levels
347 generate_message [dir]=two/levels
348 generate_message [dir]=two/levels
350 output=$(NOTMUCH_NEW)
351 pass_if_equal "$output" "Added 3 new messages to the database."
353 printf " Deleted two-level directory...\t\t\t"
355 rm -rf ${MAIL_DIR}/two
356 increment_mtime ${MAIL_DIR}
358 output=$(NOTMUCH_NEW)
359 pass_if_equal "$output" "No new mail. Removed 3 messages."
361 printf "\nTesting \"notmuch search\" in several variations:\n"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
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)"
452 printf " Search body (utf-8):...\t\t\t"
453 add_message '[subject]="utf8-message-body-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="message body utf8: bödý"'
454 output=$($NOTMUCH search 'bödý' | notmuch_search_sanitize)
455 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)"
457 printf "\nTesting --format=json output:\n"
459 printf " Show message: json...\t\t\t\t"
460 add_message '[subject]="json-show-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="json-show-message"'
461 output=$($NOTMUCH show --format=json 'json-show-message')
462 pass_if_equal "$output" '[[[{"id": "'${gen_msg_id}'", "match": true, "filename": "'${gen_msg_filename}'", "timestamp": 946728000, "date_relative": "2000-01-01", "tags": ["inbox","unread"], "headers": {"Subject": "json-show-subject", "From": "Notmuch Test Suite <test_suite@notmuchmail.org>", "To": "Notmuch Test Suite <test_suite@notmuchmail.org>", "Cc": "", "Bcc": "", "Date": "Sat, 01 Jan 2000 12:00:00 -0000"}, "body": [{"id": 1, "content-type": "text/plain", "content": "json-show-message\n"}]}, []]]]'
464 printf " Search message: json...\t\t\t"
465 add_message '[subject]="json-search-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="json-search-message"'
466 output=$($NOTMUCH search --format=json 'json-search-message' | notmuch_search_sanitize)
467 pass_if_equal "$output" '[{"thread": "XXX",
468 "timestamp": 946728000,
471 "authors": "Notmuch Test Suite",
472 "subject": "json-search-subject",
473 "tags": ["inbox", "unread"]}]'
475 printf " Search by subject (utf-8):...\t\t\t"
476 add_message [subject]=utf8-sübjéct '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
477 output=$($NOTMUCH search subject:utf8-sübjéct | notmuch_search_sanitize)
478 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
480 printf " Show message: json, utf-8...\t\t\t"
481 add_message '[subject]="json-show-utf8-body-sübjéct"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="jsön-show-méssage"'
482 output=$($NOTMUCH show --format=json 'jsön-show-méssage')
483 pass_if_equal "$output" '[[[{"id": "'${gen_msg_id}'", "match": true, "filename": "'${gen_msg_filename}'", "timestamp": 946728000, "date_relative": "2000-01-01", "tags": ["inbox","unread"], "headers": {"Subject": "json-show-utf8-body-sübjéct", "From": "Notmuch Test Suite <test_suite@notmuchmail.org>", "To": "Notmuch Test Suite <test_suite@notmuchmail.org>", "Cc": "", "Bcc": "", "Date": "Sat, 01 Jan 2000 12:00:00 -0000"}, "body": [{"id": 1, "content-type": "text/plain", "content": "jsön-show-méssage\n"}]}, []]]]'
485 printf " Search message: json, utf-8...\t\t\t"
486 add_message '[subject]="json-search-utf8-body-sübjéct"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="jsön-search-méssage"'
487 output=$($NOTMUCH search --format=json 'jsön-search-méssage' | notmuch_search_sanitize)
488 pass_if_equal "$output" '[{"thread": "XXX",
489 "timestamp": 946728000,
492 "authors": "Notmuch Test Suite",
493 "subject": "json-search-utf8-body-sübjéct",
494 "tags": ["inbox", "unread"]}]'
496 printf "\nTesting naming of threads with changing subject:\n"
497 add_message '[subject]="thread-naming: Initial thread subject"' \
498 '[date]="Fri, 05 Jan 2001 15:43:56 -0800"'
501 add_message '[subject]="thread-naming: Older changed subject"' \
502 '[date]="Sat, 06 Jan 2001 15:43:56 -0800"' \
503 "[in-reply-to]=\<$parent\>"
504 add_message '[subject]="thread-naming: Newer changed subject"' \
505 '[date]="Sun, 07 Jan 2001 15:43:56 -0800"' \
506 "[in-reply-to]=\<$parent\>"
507 add_message '[subject]="thread-naming: Final thread subject"' \
508 '[date]="Mon, 08 Jan 2001 15:43:56 -0800"' \
509 "[in-reply-to]=\<$parent\>"
512 printf " Initial thread name (oldest-first search)...\t"
513 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
514 pass_if_equal "$output" "thread:XXX 2001-01-05 [4/4] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
516 printf " Initial thread name (newest-first search)...\t"
517 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
518 pass_if_equal "$output" "thread:XXX 2001-01-08 [4/4] Notmuch Test Suite; thread-naming: Final thread subject (inbox unread)"
520 # Remove oldest and newest messages from search results
521 $NOTMUCH tag -inbox id:$parent or id:$final
523 printf " Changed thread name (oldest-first search)...\t"
524 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
525 pass_if_equal "$output" "thread:XXX 2001-01-06 [2/4] Notmuch Test Suite; thread-naming: Older changed subject (inbox unread)"
527 printf " Changed thread name (newest-first search)...\t"
528 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
529 pass_if_equal "$output" "thread:XXX 2001-01-07 [2/4] Notmuch Test Suite; thread-naming: Newer changed subject (inbox unread)"
531 printf " Ignore added reply prefix (Re:)...\t\t"
532 add_message '[subject]="Re: thread-naming: Initial thread subject"' \
533 '[date]="Tue, 09 Jan 2001 15:43:45 -0800"' \
534 "[in-reply-to]=\<$parent\>"
535 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
536 pass_if_equal "$output" "thread:XXX 2001-01-09 [3/5] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
538 printf " Ignore added reply prefix (Aw:)...\t\t"
539 add_message '[subject]="Aw: thread-naming: Initial thread subject"' \
540 '[date]="Wed, 10 Jan 2001 15:43:45 -0800"' \
541 "[in-reply-to]=\<$parent\>"
542 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
543 pass_if_equal "$output" "thread:XXX 2001-01-10 [4/6] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
545 printf " Ignore added reply prefix (Vs:)...\t\t"
546 add_message '[subject]="Vs: thread-naming: Initial thread subject"' \
547 '[date]="Thu, 11 Jan 2001 15:43:45 -0800"' \
548 "[in-reply-to]=\<$parent\>"
549 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
550 pass_if_equal "$output" "thread:XXX 2001-01-11 [5/7] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
552 printf " Ignore added reply prefix (Sv:)...\t\t"
553 add_message '[subject]="Sv: thread-naming: Initial thread subject"' \
554 '[date]="Fri, 12 Jan 2001 15:43:45 -0800"' \
555 "[in-reply-to]=\<$parent\>"
556 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
557 pass_if_equal "$output" "thread:XXX 2001-01-12 [6/8] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
559 printf " Test order of messages in \"notmuch show\"\t"
560 output=$($NOTMUCH show thread-naming | notmuch_show_sanitize)
561 pass_if_equal "$output" "
\fmessage{ id:msg-$(printf "%03d" $first)@notmuch-test-suite depth:0 match:1 filename:/XXX/mail/msg-$(printf "%03d" $first)
563 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (unread)
564 Subject: thread-naming: Initial thread subject
565 From: Notmuch Test Suite <test_suite@notmuchmail.org>
566 To: Notmuch Test Suite <test_suite@notmuchmail.org>
567 Date: Fri, 05 Jan 2001 15:43:56 -0800
570 \fpart{ ID: 1, Content-type: text/plain
571 This is just a test message (#$first)
575 \fmessage{ id:msg-$(printf "%03d" $((first + 1)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 1)))
577 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-06) (inbox unread)
578 Subject: thread-naming: Older changed subject
579 From: Notmuch Test Suite <test_suite@notmuchmail.org>
580 To: Notmuch Test Suite <test_suite@notmuchmail.org>
581 Date: Sat, 06 Jan 2001 15:43:56 -0800
584 \fpart{ ID: 1, Content-type: text/plain
585 This is just a test message (#$((first + 1)))
589 \fmessage{ id:msg-$(printf "%03d" $((first + 2)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 2)))
591 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-07) (inbox unread)
592 Subject: thread-naming: Newer changed subject
593 From: Notmuch Test Suite <test_suite@notmuchmail.org>
594 To: Notmuch Test Suite <test_suite@notmuchmail.org>
595 Date: Sun, 07 Jan 2001 15:43:56 -0800
598 \fpart{ ID: 1, Content-type: text/plain
599 This is just a test message (#$((first + 2)))
603 \fmessage{ id:msg-$(printf "%03d" $((first + 3)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 3)))
605 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-08) (unread)
606 Subject: thread-naming: Final thread subject
607 From: Notmuch Test Suite <test_suite@notmuchmail.org>
608 To: Notmuch Test Suite <test_suite@notmuchmail.org>
609 Date: Mon, 08 Jan 2001 15:43:56 -0800
612 \fpart{ ID: 1, Content-type: text/plain
613 This is just a test message (#$((first + 3)))
617 \fmessage{ id:msg-$(printf "%03d" $((first + 4)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 4)))
619 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-09) (inbox unread)
620 Subject: Re: thread-naming: Initial thread subject
621 From: Notmuch Test Suite <test_suite@notmuchmail.org>
622 To: Notmuch Test Suite <test_suite@notmuchmail.org>
623 Date: Tue, 09 Jan 2001 15:43:45 -0800
626 \fpart{ ID: 1, Content-type: text/plain
627 This is just a test message (#$((first + 4)))
631 \fmessage{ id:msg-$(printf "%03d" $((first + 5)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 5)))
633 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-10) (inbox unread)
634 Subject: Aw: thread-naming: Initial thread subject
635 From: Notmuch Test Suite <test_suite@notmuchmail.org>
636 To: Notmuch Test Suite <test_suite@notmuchmail.org>
637 Date: Wed, 10 Jan 2001 15:43:45 -0800
640 \fpart{ ID: 1, Content-type: text/plain
641 This is just a test message (#$((first + 5)))
645 \fmessage{ id:msg-$(printf "%03d" $((first + 6)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 6)))
647 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-11) (inbox unread)
648 Subject: Vs: thread-naming: Initial thread subject
649 From: Notmuch Test Suite <test_suite@notmuchmail.org>
650 To: Notmuch Test Suite <test_suite@notmuchmail.org>
651 Date: Thu, 11 Jan 2001 15:43:45 -0800
654 \fpart{ ID: 1, Content-type: text/plain
655 This is just a test message (#$((first + 6)))
659 \fmessage{ id:msg-$(printf "%03d" $((first + 7)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 7)))
661 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-12) (inbox unread)
662 Subject: Sv: thread-naming: Initial thread subject
663 From: Notmuch Test Suite <test_suite@notmuchmail.org>
664 To: Notmuch Test Suite <test_suite@notmuchmail.org>
665 Date: Fri, 12 Jan 2001 15:43:45 -0800
668 \fpart{ ID: 1, Content-type: text/plain
669 This is just a test message (#$((first + 7)))
674 printf "\nTesting \"notmuch reply\" in several variations:\n"
676 printf " Basic reply...\t\t\t\t\t"
677 add_message '[from]="Sender <sender@example.com>"' \
678 [to]=test_suite@notmuchmail.org \
679 [subject]=notmuch-reply-test \
680 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
681 '[body]="basic reply test"'
683 output=$($NOTMUCH reply id:${gen_msg_id})
684 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
685 Subject: Re: notmuch-reply-test
686 To: Sender <sender@example.com>
687 Bcc: test_suite@notmuchmail.org
688 In-Reply-To: <${gen_msg_id}>
689 References: <${gen_msg_id}>
691 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
694 printf " Multiple recipients...\t\t\t\t"
695 add_message '[from]="Sender <sender@example.com>"' \
696 '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
697 [subject]=notmuch-reply-test \
698 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
699 '[body]="Multiple recipients"'
701 output=$($NOTMUCH reply id:${gen_msg_id})
702 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
703 Subject: Re: notmuch-reply-test
704 To: Sender <sender@example.com>, Someone Else <someone@example.com>
705 Bcc: test_suite@notmuchmail.org
706 In-Reply-To: <${gen_msg_id}>
707 References: <${gen_msg_id}>
709 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
710 > Multiple recipients"
712 printf " Reply with CC...\t\t\t\t"
713 add_message '[from]="Sender <sender@example.com>"' \
714 [to]=test_suite@notmuchmail.org \
715 '[cc]="Other Parties <cc@example.com>"' \
716 [subject]=notmuch-reply-test \
717 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
718 '[body]="reply with CC"'
720 output=$($NOTMUCH reply id:${gen_msg_id})
721 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
722 Subject: Re: notmuch-reply-test
723 To: Sender <sender@example.com>
724 Cc: Other Parties <cc@example.com>
725 Bcc: test_suite@notmuchmail.org
726 In-Reply-To: <${gen_msg_id}>
727 References: <${gen_msg_id}>
729 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
732 printf " Reply from alternate address...\t\t"
733 add_message '[from]="Sender <sender@example.com>"' \
734 [to]=test_suite_other@notmuchmail.org \
735 [subject]=notmuch-reply-test \
736 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
737 '[body]="reply from alternate address"'
739 output=$($NOTMUCH reply id:${gen_msg_id})
740 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
741 Subject: Re: notmuch-reply-test
742 To: Sender <sender@example.com>
743 Bcc: test_suite@notmuchmail.org
744 In-Reply-To: <${gen_msg_id}>
745 References: <${gen_msg_id}>
747 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
748 > reply from alternate address"
750 printf " Support for Reply-To...\t\t\t"
751 add_message '[from]="Sender <sender@example.com>"' \
752 [to]=test_suite@notmuchmail.org \
753 [subject]=notmuch-reply-test \
754 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
755 '[body]="support for reply-to"' \
756 '[reply-to]="Sender <elsewhere@example.com>"'
758 output=$($NOTMUCH reply id:${gen_msg_id})
759 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
760 Subject: Re: notmuch-reply-test
761 To: Sender <elsewhere@example.com>
762 Bcc: test_suite@notmuchmail.org
763 In-Reply-To: <${gen_msg_id}>
764 References: <${gen_msg_id}>
766 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
767 > support for reply-to"
769 printf " Un-munging Reply-To...\t\t\t\t"
770 add_message '[from]="Sender <sender@example.com>"' \
771 '[to]="Some List <list@example.com>"' \
772 [subject]=notmuch-reply-test \
773 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
774 '[body]="Un-munging Reply-To"' \
775 '[reply-to]="Evil Munging List <list@example.com>"'
777 output=$($NOTMUCH reply id:${gen_msg_id})
778 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
779 Subject: Re: notmuch-reply-test
780 To: Sender <sender@example.com>, Some List <list@example.com>
781 Bcc: test_suite@notmuchmail.org
782 In-Reply-To: <${gen_msg_id}>
783 References: <${gen_msg_id}>
785 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
786 > Un-munging Reply-To"
788 printf "\nTesting handling of uuencoded data:\n"
790 add_message [subject]=uuencodetest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
791 '[body]="This message is used to ensure that notmuch correctly handles a
792 message containing a block of uuencoded data. First, we have a marker
793 this content beforeuudata . Then we beging the uunencoded data itself:
795 begin 644 bogus-uuencoded-data
796 M0123456789012345678901234567890123456789012345678901234567890
797 MOBVIOUSLY, THIS IS NOT ANY SORT OF USEFUL UUNECODED DATA.
798 MINSTEAD THIS IS JUST A WAY TO ENSURE THAT THIS BLOCK OF DATA
799 MIS CORRECTLY IGNORED WHEN NOTMUCH CREATES ITS INDEX. SO WE
800 MINCLUDE A DURINGUUDATA MARKER THAT SHOULD NOT RESULT IN ANY
805 Finally, we have our afteruudata marker as well."'
807 printf " Ensure content before uu data is indexed...\t"
808 output=$($NOTMUCH search beforeuudata | notmuch_search_sanitize)
809 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
810 printf " Ensure uu data is not indexed...\t\t"
811 output=$($NOTMUCH search DURINGUUDATA | notmuch_search_sanitize)
812 pass_if_equal "$output" ""
813 printf " Ensure content after uu data is indexed...\t"
814 output=$($NOTMUCH search afteruudata | notmuch_search_sanitize)
815 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
817 printf "\nTesting \"notmuch dump\" and \"notmuch restore\":\n"
819 printf " Dumping all tags...\t\t\t\t"
820 $NOTMUCH dump dump.expected
821 pass_if_equal "$?" "0"
823 printf " Clearing all tags...\t\t\t\t"
824 sed -e 's/(\([^(]*\))$/()/' < dump.expected > clear.expected
825 $NOTMUCH restore clear.expected
826 $NOTMUCH dump clear.actual
827 pass_if_equal "$(< clear.actual)" "$(< clear.expected)"
829 printf " Restoring original tags...\t\t\t"
830 $NOTMUCH restore dump.expected
831 $NOTMUCH dump dump.actual
832 pass_if_equal "$(< dump.actual)" "$(< dump.expected)"
834 printf " Restore with nothing to do...\t\t\t"
835 $NOTMUCH restore dump.expected
836 pass_if_equal "$?" "0"
838 printf "\nTesting threading when messages received out of order:\n"
839 printf " Adding initial child message...\t\t"
840 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
841 output=$(NOTMUCH_NEW)
842 pass_if_equal "$output" "Added 1 new message to the database."
843 printf " Searching returns the message...\t\t"
844 output=$($NOTMUCH search foo | notmuch_search_sanitize)
845 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; brokenthreadtest (inbox unread)"
846 printf " Adding second child message...\t\t\t"
847 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
848 output=$(NOTMUCH_NEW)
849 pass_if_equal "$output" "Added 1 new message to the database."
850 printf " Searching returns both messages in one thread..."
851 output=$($NOTMUCH search foo | notmuch_search_sanitize)
852 pass_if_equal "$output" "thread:XXX 2000-01-01 [2/2] Notmuch Test Suite; brokenthreadtest (inbox unread)"
853 printf " Adding parent message...\t\t\t"
854 generate_message [body]=foo [id]=parent-id [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
855 output=$(NOTMUCH_NEW)
856 pass_if_equal "$output" "Added 1 new message to the database."
857 printf " Searching returns all three messages in one thread..."
858 output=$($NOTMUCH search foo | notmuch_search_sanitize)
859 pass_if_equal "$output" "thread:XXX 2000-01-01 [3/3] Notmuch Test Suite; brokenthreadtest (inbox unread)"
862 echo "Notmuch test suite complete."
864 if [ "$test_failures" = "0" ]; then
865 echo "All $tests tests passed."
868 echo "$test_failures/$tests tests failed. The failures can be investigated in:"