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>
65 # '[header]=full header line, including keyword'
67 # Additional values for email headers. If these are not provided
68 # then the relevant headers will simply not appear in the
73 # Controls the message-id of the created message.
79 # This is our (bash-specific) magic for doing named parameters
80 local -A template="($@)"
81 local additional_headers
83 if [ -z "${template[id]}" ]; then
84 gen_msg_cnt=$((gen_msg_cnt + 1))
85 gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
86 gen_msg_id="${gen_msg_name}@notmuch-test-suite"
88 gen_msg_name="msg-${template[id]}"
89 gen_msg_id="${template[id]}"
92 if [ -z "${template[dir]}" ]; then
93 gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
95 gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
96 mkdir -p $(dirname $gen_msg_filename)
99 if [ -z "${template[body]}" ]; then
100 template[body]="This is just a test message (#${gen_msg_cnt})"
103 if [ -z "${template[from]}" ]; then
104 template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
107 if [ -z "${template[to]}" ]; then
108 template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
111 if [ -z "${template[subject]}" ]; then
112 template[subject]="Test message #${gen_msg_cnt}"
115 if [ -z "${template[date]}" ]; then
116 template[date]="Tue, 05 Jan 2001 15:43:57 -0800"
119 additional_headers=""
120 if [ ! -z "${template[header]}" ]; then
121 additional_headers="${template[header]}
122 ${additional_headers}"
125 if [ ! -z "${template[reply-to]}" ]; then
126 additional_headers="Reply-To: ${template[reply-to]}
127 ${additional_headers}"
130 if [ ! -z "${template[in-reply-to]}" ]; then
131 additional_headers="In-Reply-To: ${template[in-reply-to]}
132 ${additional_headers}"
135 if [ ! -z "${template[cc]}" ]; then
136 additional_headers="Cc: ${template[cc]}
137 ${additional_headers}"
141 cat <<EOF >$gen_msg_filename
142 From: ${template[from]}
144 Message-Id: <${gen_msg_id}>
145 Subject: ${template[subject]}
146 Date: ${template[date]}
147 ${additional_headers}
151 # Ensure that the mtime of the containing directory is updated
152 increment_mtime $(dirname ${gen_msg_filename})
155 # Generate a new message and add it to the index.
157 # All of the arguments and return values supported by generate_message
158 # are also supported here, so see that function for details.
161 generate_message "$@"
163 $NOTMUCH new > /dev/null
176 if [ "$output" = "$expected" ]; then
180 testname=test-$(printf "%03d" $tests)
181 echo "$expected" > $testname.expected
182 echo "$output" > $testname.output
183 diff -u $testname.expected $testname.output || true
184 test_failures=$((test_failures + 1))
188 TEST_DIR=$(pwd)/test.$$
189 MAIL_DIR=${TEST_DIR}/mail
190 export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
191 NOTMUCH=$(find_notmuch_binary $(pwd))
195 $NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
198 notmuch_search_sanitize ()
200 sed -r -e 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
203 NOTMUCH_SHOW_FILENAME_SQUELCH='s,filename:.*/mail,filename:/XXX/mail,'
204 notmuch_show_sanitize ()
206 sed -e "$NOTMUCH_SHOW_FILENAME_SQUELCH"
215 cat <<EOF > ${NOTMUCH_CONFIG}
220 name=Notmuch Test Suite
221 primary_email=test_suite@notmuchmail.org
222 other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
225 printf "Testing \"notmuch new\" in several variations:\n"
226 printf " No new messages...\t\t\t\t"
227 output=$(NOTMUCH_NEW)
228 pass_if_equal "$output" "No new mail."
230 printf " Single new message...\t\t\t\t"
232 output=$(NOTMUCH_NEW)
233 pass_if_equal "$output" "Added 1 new message to the database."
235 printf " Multiple new messages...\t\t\t"
238 output=$(NOTMUCH_NEW)
239 pass_if_equal "$output" "Added 2 new messages to the database."
241 printf " No new messages (non-empty DB)...\t\t"
242 output=$(NOTMUCH_NEW)
243 pass_if_equal "$output" "No new mail."
245 printf " New directories...\t\t\t\t"
246 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
247 mkdir ${MAIL_DIR}/def
248 mkdir ${MAIL_DIR}/ghi
249 generate_message [dir]=def
251 output=$(NOTMUCH_NEW)
252 pass_if_equal "$output" "Added 1 new message to the database."
254 printf " Alternate inode order...\t\t\t"
256 rm -rf ${MAIL_DIR}/.notmuch
257 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
259 generate_message [dir]=abc
261 output=$(NOTMUCH_NEW)
262 pass_if_equal "$output" "Added 1 new message to the database."
264 printf " Message moved in...\t\t\t\t"
265 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
267 tmp_msg_filename=tmp/$gen_msg_filename
268 mkdir -p $(dirname $tmp_msg_filename)
269 mv $gen_msg_filename $tmp_msg_filename
270 increment_mtime ${MAIL_DIR}
271 $NOTMUCH new > /dev/null
272 mv $tmp_msg_filename $gen_msg_filename
273 increment_mtime ${MAIL_DIR}
274 output=$(NOTMUCH_NEW)
275 pass_if_equal "$output" "Added 1 new message to the database."
277 printf " Renamed message...\t\t\t\t"
280 $NOTMUCH new > /dev/null
281 mv $gen_msg_filename ${gen_msg_filename}-renamed
282 increment_mtime ${MAIL_DIR}
283 output=$(NOTMUCH_NEW)
284 pass_if_equal "$output" "No new mail. Detected 1 file rename."
286 printf " Deleted message...\t\t\t\t"
288 rm ${gen_msg_filename}-renamed
289 increment_mtime ${MAIL_DIR}
290 output=$(NOTMUCH_NEW)
291 pass_if_equal "$output" "No new mail. Removed 1 message."
293 printf " Renamed directory...\t\t\t\t"
295 generate_message [dir]=dir
296 generate_message [dir]=dir
297 generate_message [dir]=dir
299 $NOTMUCH new > /dev/null
301 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
302 increment_mtime ${MAIL_DIR}
304 output=$(NOTMUCH_NEW)
305 pass_if_equal "$output" "No new mail. Detected 3 file renames."
307 printf " Deleted directory...\t\t\t\t"
309 rm -rf ${MAIL_DIR}/dir-renamed
310 increment_mtime ${MAIL_DIR}
312 output=$(NOTMUCH_NEW)
313 pass_if_equal "$output" "No new mail. Removed 3 messages."
315 printf " New directory (at end of list)...\t\t"
317 generate_message [dir]=zzz
318 generate_message [dir]=zzz
319 generate_message [dir]=zzz
321 output=$(NOTMUCH_NEW)
322 pass_if_equal "$output" "Added 3 new messages to the database."
324 printf " Deleted directory (end of list)...\t\t"
326 rm -rf ${MAIL_DIR}/zzz
327 increment_mtime ${MAIL_DIR}
329 output=$(NOTMUCH_NEW)
330 pass_if_equal "$output" "No new mail. Removed 3 messages."
332 printf " New symlink to directory...\t\t\t"
334 rm -rf ${MAIL_DIR}/.notmuch
335 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
338 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
340 output=$(NOTMUCH_NEW)
341 pass_if_equal "$output" "Added 1 new message to the database."
343 printf " New symlink to a file...\t\t\t"
345 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
346 mkdir -p $(dirname $external_msg_filename)
347 mv $gen_msg_filename $external_msg_filename
348 ln -s $external_msg_filename $gen_msg_filename
349 increment_mtime ${MAIL_DIR}
350 output=$(NOTMUCH_NEW)
351 pass_if_equal "$output" "Added 1 new message to the database."
353 printf " New two-level directory...\t\t\t"
355 generate_message [dir]=two/levels
356 generate_message [dir]=two/levels
357 generate_message [dir]=two/levels
359 output=$(NOTMUCH_NEW)
360 pass_if_equal "$output" "Added 3 new messages to the database."
362 printf " Deleted two-level directory...\t\t\t"
364 rm -rf ${MAIL_DIR}/two
365 increment_mtime ${MAIL_DIR}
367 output=$(NOTMUCH_NEW)
368 pass_if_equal "$output" "No new mail. Removed 3 messages."
370 printf "\nTesting \"notmuch search\" in several variations:\n"
372 printf " Search body...\t\t\t\t\t"
373 add_message '[subject]="body search"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [body]=bodysearchtest
374 output=$($NOTMUCH search bodysearchtest | notmuch_search_sanitize)
375 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)"
377 printf " Search by from:...\t\t\t\t"
378 add_message '[subject]="search by from"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom
379 output=$($NOTMUCH search from:searchbyfrom | notmuch_search_sanitize)
380 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)"
382 printf " Search by to:...\t\t\t\t"
383 add_message '[subject]="search by to"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto
384 output=$($NOTMUCH search to:searchbyto | notmuch_search_sanitize)
385 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)"
387 printf " Search by subject:...\t\t\t\t"
388 add_message [subject]=subjectsearchtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
389 output=$($NOTMUCH search subject:subjectsearchtest | notmuch_search_sanitize)
390 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)"
392 printf " Search by id:...\t\t\t\t"
393 add_message '[subject]="search by id"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
394 output=$($NOTMUCH search id:${gen_msg_id} | notmuch_search_sanitize)
395 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
397 printf " Search by tag:...\t\t\t\t"
398 add_message '[subject]="search by tag"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
399 $NOTMUCH tag +searchbytag id:${gen_msg_id}
400 output=$($NOTMUCH search tag:searchbytag | notmuch_search_sanitize)
401 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)"
403 printf " Search by thread:...\t\t\t\t"
404 add_message '[subject]="search by thread"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
405 thread_id=$($NOTMUCH search id:${gen_msg_id} | sed -e 's/thread:\([a-f0-9]*\).*/\1/')
406 output=$($NOTMUCH search thread:${thread_id} | notmuch_search_sanitize)
407 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)"
409 printf " Search body (phrase)...\t\t\t"
410 add_message '[subject]="body search (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="body search (phrase)"'
411 add_message '[subject]="negative result"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="This phrase should not match the body search"'
412 output=$($NOTMUCH search '\"body search (phrase)\"' | notmuch_search_sanitize)
413 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)"
415 printf " Search by from: (address)...\t\t\t"
416 add_message '[subject]="search by from (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom@example.com
417 output=$($NOTMUCH search from:searchbyfrom@example.com | notmuch_search_sanitize)
418 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)"
420 printf " Search by from: (name)...\t\t\t"
421 add_message '[subject]="search by from (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[from]="Search By From Name <test@example.com>"'
422 output=$($NOTMUCH search from:'Search By From Name' | notmuch_search_sanitize)
423 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
425 printf " Search by to: (address)...\t\t\t"
426 add_message '[subject]="search by to (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto@example.com
427 output=$($NOTMUCH search to:searchbyto@example.com | notmuch_search_sanitize)
428 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)"
430 printf " Search by to: (name)...\t\t\t"
431 add_message '[subject]="search by to (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[to]="Search By To Name <test@example.com>"'
432 output=$($NOTMUCH search to:'Search By To Name' | notmuch_search_sanitize)
433 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
435 printf " Search by subject: (phrase)...\t\t\t"
436 add_message '[subject]="subject search test (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
437 add_message '[subject]="this phrase should not match the subject search test"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
438 output=$($NOTMUCH search 'subject:\"subject search test (phrase)\"' | notmuch_search_sanitize)
439 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)"
441 printf " Search for all messages (\"*\"):...\t\t"
442 output=$($NOTMUCH search '*' | notmuch_search_sanitize)
443 pass_if_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Test message #6 (inbox unread)
444 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Test message #14 (inbox unread)
445 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)
446 thread:XXX 2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)
447 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)
448 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)
449 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)
450 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)
451 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)
452 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)
453 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; negative result (inbox unread)
454 thread:XXX 2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)
455 thread:XXX 2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)
456 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)
457 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)
458 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)
459 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; this phrase should not match the subject search test (inbox unread)"
461 printf " Search body (utf-8):...\t\t\t"
462 add_message '[subject]="utf8-message-body-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="message body utf8: bödý"'
463 output=$($NOTMUCH search 'bödý' | notmuch_search_sanitize)
464 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)"
466 printf "\nTesting --format=json output:\n"
468 printf " Show message: json...\t\t\t\t"
469 add_message '[subject]="json-show-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="json-show-message"'
470 output=$($NOTMUCH show --format=json 'json-show-message')
471 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"}]}, []]]]'
473 printf " Search message: json...\t\t\t"
474 add_message '[subject]="json-search-subject"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="json-search-message"'
475 output=$($NOTMUCH search --format=json 'json-search-message' | notmuch_search_sanitize)
476 pass_if_equal "$output" '[{"thread": "XXX",
477 "timestamp": 946728000,
480 "authors": "Notmuch Test Suite",
481 "subject": "json-search-subject",
482 "tags": ["inbox", "unread"]}]'
484 printf " Search by subject (utf-8):...\t\t\t"
485 add_message [subject]=utf8-sübjéct '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
486 output=$($NOTMUCH search subject:utf8-sübjéct | notmuch_search_sanitize)
487 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; utf8-sübjéct (inbox unread)"
489 printf " Show message: json, utf-8...\t\t\t"
490 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"'
491 output=$($NOTMUCH show --format=json 'jsön-show-méssage')
492 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"}]}, []]]]'
494 printf " Search message: json, utf-8...\t\t\t"
495 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"'
496 output=$($NOTMUCH search --format=json 'jsön-search-méssage' | notmuch_search_sanitize)
497 pass_if_equal "$output" '[{"thread": "XXX",
498 "timestamp": 946728000,
501 "authors": "Notmuch Test Suite",
502 "subject": "json-search-utf8-body-sübjéct",
503 "tags": ["inbox", "unread"]}]'
505 printf "\nTesting naming of threads with changing subject:\n"
506 add_message '[subject]="thread-naming: Initial thread subject"' \
507 '[date]="Fri, 05 Jan 2001 15:43:56 -0800"'
510 add_message '[subject]="thread-naming: Older changed subject"' \
511 '[date]="Sat, 06 Jan 2001 15:43:56 -0800"' \
512 "[in-reply-to]=\<$parent\>"
513 add_message '[subject]="thread-naming: Newer changed subject"' \
514 '[date]="Sun, 07 Jan 2001 15:43:56 -0800"' \
515 "[in-reply-to]=\<$parent\>"
516 add_message '[subject]="thread-naming: Final thread subject"' \
517 '[date]="Mon, 08 Jan 2001 15:43:56 -0800"' \
518 "[in-reply-to]=\<$parent\>"
521 printf " Initial 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-05 [4/4] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
525 printf " Initial 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-08 [4/4] Notmuch Test Suite; thread-naming: Final thread subject (inbox unread)"
529 # Remove oldest and newest messages from search results
530 $NOTMUCH tag -inbox id:$parent or id:$final
532 printf " Changed thread name (oldest-first search)...\t"
533 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
534 pass_if_equal "$output" "thread:XXX 2001-01-06 [2/4] Notmuch Test Suite; thread-naming: Older changed subject (inbox unread)"
536 printf " Changed thread name (newest-first search)...\t"
537 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
538 pass_if_equal "$output" "thread:XXX 2001-01-07 [2/4] Notmuch Test Suite; thread-naming: Newer changed subject (inbox unread)"
540 printf " Ignore added reply prefix (Re:)...\t\t"
541 add_message '[subject]="Re: thread-naming: Initial thread subject"' \
542 '[date]="Tue, 09 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-09 [3/5] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
547 printf " Ignore added reply prefix (Aw:)...\t\t"
548 add_message '[subject]="Aw: thread-naming: Initial thread subject"' \
549 '[date]="Wed, 10 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-10 [4/6] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
554 printf " Ignore added reply prefix (Vs:)...\t\t"
555 add_message '[subject]="Vs: thread-naming: Initial thread subject"' \
556 '[date]="Thu, 11 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-11 [5/7] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
561 printf " Ignore added reply prefix (Sv:)...\t\t"
562 add_message '[subject]="Sv: thread-naming: Initial thread subject"' \
563 '[date]="Fri, 12 Jan 2001 15:43:45 -0800"' \
564 "[in-reply-to]=\<$parent\>"
565 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
566 pass_if_equal "$output" "thread:XXX 2001-01-12 [6/8] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
568 printf " Test order of messages in \"notmuch show\"\t"
569 output=$($NOTMUCH show thread-naming | notmuch_show_sanitize)
570 pass_if_equal "$output" "
\fmessage{ id:msg-$(printf "%03d" $first)@notmuch-test-suite depth:0 match:1 filename:/XXX/mail/msg-$(printf "%03d" $first)
572 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (unread)
573 Subject: thread-naming: Initial thread subject
574 From: Notmuch Test Suite <test_suite@notmuchmail.org>
575 To: Notmuch Test Suite <test_suite@notmuchmail.org>
576 Date: Fri, 05 Jan 2001 15:43:56 -0800
579 \fpart{ ID: 1, Content-type: text/plain
580 This is just a test message (#$first)
584 \fmessage{ id:msg-$(printf "%03d" $((first + 1)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 1)))
586 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-06) (inbox unread)
587 Subject: thread-naming: Older changed subject
588 From: Notmuch Test Suite <test_suite@notmuchmail.org>
589 To: Notmuch Test Suite <test_suite@notmuchmail.org>
590 Date: Sat, 06 Jan 2001 15:43:56 -0800
593 \fpart{ ID: 1, Content-type: text/plain
594 This is just a test message (#$((first + 1)))
598 \fmessage{ id:msg-$(printf "%03d" $((first + 2)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 2)))
600 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-07) (inbox unread)
601 Subject: thread-naming: Newer changed subject
602 From: Notmuch Test Suite <test_suite@notmuchmail.org>
603 To: Notmuch Test Suite <test_suite@notmuchmail.org>
604 Date: Sun, 07 Jan 2001 15:43:56 -0800
607 \fpart{ ID: 1, Content-type: text/plain
608 This is just a test message (#$((first + 2)))
612 \fmessage{ id:msg-$(printf "%03d" $((first + 3)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 3)))
614 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-08) (unread)
615 Subject: thread-naming: Final thread subject
616 From: Notmuch Test Suite <test_suite@notmuchmail.org>
617 To: Notmuch Test Suite <test_suite@notmuchmail.org>
618 Date: Mon, 08 Jan 2001 15:43:56 -0800
621 \fpart{ ID: 1, Content-type: text/plain
622 This is just a test message (#$((first + 3)))
626 \fmessage{ id:msg-$(printf "%03d" $((first + 4)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 4)))
628 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-09) (inbox unread)
629 Subject: Re: thread-naming: Initial thread subject
630 From: Notmuch Test Suite <test_suite@notmuchmail.org>
631 To: Notmuch Test Suite <test_suite@notmuchmail.org>
632 Date: Tue, 09 Jan 2001 15:43:45 -0800
635 \fpart{ ID: 1, Content-type: text/plain
636 This is just a test message (#$((first + 4)))
640 \fmessage{ id:msg-$(printf "%03d" $((first + 5)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 5)))
642 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-10) (inbox unread)
643 Subject: Aw: thread-naming: Initial thread subject
644 From: Notmuch Test Suite <test_suite@notmuchmail.org>
645 To: Notmuch Test Suite <test_suite@notmuchmail.org>
646 Date: Wed, 10 Jan 2001 15:43:45 -0800
649 \fpart{ ID: 1, Content-type: text/plain
650 This is just a test message (#$((first + 5)))
654 \fmessage{ id:msg-$(printf "%03d" $((first + 6)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 6)))
656 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-11) (inbox unread)
657 Subject: Vs: thread-naming: Initial thread subject
658 From: Notmuch Test Suite <test_suite@notmuchmail.org>
659 To: Notmuch Test Suite <test_suite@notmuchmail.org>
660 Date: Thu, 11 Jan 2001 15:43:45 -0800
663 \fpart{ ID: 1, Content-type: text/plain
664 This is just a test message (#$((first + 6)))
668 \fmessage{ id:msg-$(printf "%03d" $((first + 7)))@notmuch-test-suite depth:1 match:1 filename:/XXX/mail/msg-$(printf "%03d" $((first + 7)))
670 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-12) (inbox unread)
671 Subject: Sv: thread-naming: Initial thread subject
672 From: Notmuch Test Suite <test_suite@notmuchmail.org>
673 To: Notmuch Test Suite <test_suite@notmuchmail.org>
674 Date: Fri, 12 Jan 2001 15:43:45 -0800
677 \fpart{ ID: 1, Content-type: text/plain
678 This is just a test message (#$((first + 7)))
683 printf "\nTesting \"notmuch reply\" in several variations:\n"
685 printf " Basic reply...\t\t\t\t\t"
686 add_message '[from]="Sender <sender@example.com>"' \
687 [to]=test_suite@notmuchmail.org \
688 [subject]=notmuch-reply-test \
689 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
690 '[body]="basic reply test"'
692 output=$($NOTMUCH reply id:${gen_msg_id})
693 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
694 Subject: Re: notmuch-reply-test
695 To: Sender <sender@example.com>
696 Bcc: test_suite@notmuchmail.org
697 In-Reply-To: <${gen_msg_id}>
698 References: <${gen_msg_id}>
700 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
703 printf " Multiple recipients...\t\t\t\t"
704 add_message '[from]="Sender <sender@example.com>"' \
705 '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
706 [subject]=notmuch-reply-test \
707 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
708 '[body]="Multiple recipients"'
710 output=$($NOTMUCH reply id:${gen_msg_id})
711 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
712 Subject: Re: notmuch-reply-test
713 To: Sender <sender@example.com>, Someone Else <someone@example.com>
714 Bcc: test_suite@notmuchmail.org
715 In-Reply-To: <${gen_msg_id}>
716 References: <${gen_msg_id}>
718 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
719 > Multiple recipients"
721 printf " Reply with CC...\t\t\t\t"
722 add_message '[from]="Sender <sender@example.com>"' \
723 [to]=test_suite@notmuchmail.org \
724 '[cc]="Other Parties <cc@example.com>"' \
725 [subject]=notmuch-reply-test \
726 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
727 '[body]="reply with CC"'
729 output=$($NOTMUCH reply id:${gen_msg_id})
730 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
731 Subject: Re: notmuch-reply-test
732 To: Sender <sender@example.com>
733 Cc: Other Parties <cc@example.com>
734 Bcc: test_suite@notmuchmail.org
735 In-Reply-To: <${gen_msg_id}>
736 References: <${gen_msg_id}>
738 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
741 printf " Reply from alternate address...\t\t"
742 add_message '[from]="Sender <sender@example.com>"' \
743 [to]=test_suite_other@notmuchmail.org \
744 [subject]=notmuch-reply-test \
745 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
746 '[body]="reply from alternate address"'
748 output=$($NOTMUCH reply id:${gen_msg_id})
749 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
750 Subject: Re: notmuch-reply-test
751 To: Sender <sender@example.com>
752 Bcc: test_suite@notmuchmail.org
753 In-Reply-To: <${gen_msg_id}>
754 References: <${gen_msg_id}>
756 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
757 > reply from alternate address"
759 printf " Support for Reply-To...\t\t\t"
760 add_message '[from]="Sender <sender@example.com>"' \
761 [to]=test_suite@notmuchmail.org \
762 [subject]=notmuch-reply-test \
763 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
764 '[body]="support for reply-to"' \
765 '[reply-to]="Sender <elsewhere@example.com>"'
767 output=$($NOTMUCH reply id:${gen_msg_id})
768 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
769 Subject: Re: notmuch-reply-test
770 To: Sender <elsewhere@example.com>
771 Bcc: test_suite@notmuchmail.org
772 In-Reply-To: <${gen_msg_id}>
773 References: <${gen_msg_id}>
775 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
776 > support for reply-to"
778 printf " Un-munging Reply-To...\t\t\t\t"
779 add_message '[from]="Sender <sender@example.com>"' \
780 '[to]="Some List <list@example.com>"' \
781 [subject]=notmuch-reply-test \
782 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
783 '[body]="Un-munging Reply-To"' \
784 '[reply-to]="Evil Munging List <list@example.com>"'
786 output=$($NOTMUCH reply id:${gen_msg_id})
787 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
788 Subject: Re: notmuch-reply-test
789 To: Sender <sender@example.com>, Some List <list@example.com>
790 Bcc: test_suite@notmuchmail.org
791 In-Reply-To: <${gen_msg_id}>
792 References: <${gen_msg_id}>
794 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
795 > Un-munging Reply-To"
797 printf "\nTesting handling of uuencoded data:\n"
799 add_message [subject]=uuencodetest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
800 '[body]="This message is used to ensure that notmuch correctly handles a
801 message containing a block of uuencoded data. First, we have a marker
802 this content beforeuudata . Then we beging the uunencoded data itself:
804 begin 644 bogus-uuencoded-data
805 M0123456789012345678901234567890123456789012345678901234567890
806 MOBVIOUSLY, THIS IS NOT ANY SORT OF USEFUL UUNECODED DATA.
807 MINSTEAD THIS IS JUST A WAY TO ENSURE THAT THIS BLOCK OF DATA
808 MIS CORRECTLY IGNORED WHEN NOTMUCH CREATES ITS INDEX. SO WE
809 MINCLUDE A DURINGUUDATA MARKER THAT SHOULD NOT RESULT IN ANY
814 Finally, we have our afteruudata marker as well."'
816 printf " Ensure content before uu data is indexed...\t"
817 output=$($NOTMUCH search beforeuudata | notmuch_search_sanitize)
818 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
819 printf " Ensure uu data is not indexed...\t\t"
820 output=$($NOTMUCH search DURINGUUDATA | notmuch_search_sanitize)
821 pass_if_equal "$output" ""
822 printf " Ensure content after uu data is indexed...\t"
823 output=$($NOTMUCH search afteruudata | notmuch_search_sanitize)
824 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
826 printf "\nTesting \"notmuch dump\" and \"notmuch restore\":\n"
828 printf " Dumping all tags...\t\t\t\t"
829 $NOTMUCH dump dump.expected
830 pass_if_equal "$?" "0"
832 printf " Clearing all tags...\t\t\t\t"
833 sed -e 's/(\([^(]*\))$/()/' < dump.expected > clear.expected
834 $NOTMUCH restore clear.expected
835 $NOTMUCH dump clear.actual
836 pass_if_equal "$(< clear.actual)" "$(< clear.expected)"
838 printf " Restoring original tags...\t\t\t"
839 $NOTMUCH restore dump.expected
840 $NOTMUCH dump dump.actual
841 pass_if_equal "$(< dump.actual)" "$(< dump.expected)"
843 printf " Restore with nothing to do...\t\t\t"
844 $NOTMUCH restore dump.expected
845 pass_if_equal "$?" "0"
847 printf "\nTesting threading when messages received out of order:\n"
848 printf " Adding initial child message...\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 the message...\t\t"
853 output=$($NOTMUCH search foo | notmuch_search_sanitize)
854 pass_if_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; brokenthreadtest (inbox unread)"
855 printf " Adding second child message...\t\t\t"
856 generate_message [body]=foo '[in-reply-to]=\<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 both messages in one thread..."
860 output=$($NOTMUCH search foo | notmuch_search_sanitize)
861 pass_if_equal "$output" "thread:XXX 2000-01-01 [2/2] Notmuch Test Suite; brokenthreadtest (inbox unread)"
862 printf " Adding parent message...\t\t\t"
863 generate_message [body]=foo [id]=parent-id [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
864 output=$(NOTMUCH_NEW)
865 pass_if_equal "$output" "Added 1 new message to the database."
866 printf " Searching returns all three messages in one thread..."
867 output=$($NOTMUCH search foo | notmuch_search_sanitize)
868 pass_if_equal "$output" "thread:XXX 2000-01-01 [3/3] Notmuch Test Suite; brokenthreadtest (inbox unread)"
870 printf " Magic from guessing (nothing to go on)...\t"
871 add_message '[from]="Sender <sender@example.com>"' \
872 [to]=mailinglist@notmuchmail.org \
873 [subject]=notmuch-reply-test \
874 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
875 '[body]="from guessing test"'
877 output=$($NOTMUCH reply id:${gen_msg_id})
878 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
879 Subject: Re: notmuch-reply-test
880 To: Sender <sender@example.com>, mailinglist@notmuchmail.org
881 Bcc: test_suite@notmuchmail.org
882 In-Reply-To: <${gen_msg_id}>
883 References: <${gen_msg_id}>
885 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
886 > from guessing test"
888 printf " Magic from guessing (Envelope-to:)...\t\t"
889 add_message '[from]="Sender <sender@example.com>"' \
890 [to]=mailinglist@notmuchmail.org \
891 [subject]=notmuch-reply-test \
892 '[header]="Envelope-To: test_suite_other@notmuchmail.org"' \
893 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
894 '[body]="from guessing test"'
896 output=$($NOTMUCH reply id:${gen_msg_id})
897 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
898 Subject: Re: notmuch-reply-test
899 To: Sender <sender@example.com>, mailinglist@notmuchmail.org
900 Bcc: test_suite@notmuchmail.org
901 In-Reply-To: <${gen_msg_id}>
902 References: <${gen_msg_id}>
904 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
905 > from guessing test"
907 printf " Magic from guessing (X-Original-To:)...\t"
908 add_message '[from]="Sender <sender@example.com>"' \
909 [to]=mailinglist@notmuchmail.org \
910 [subject]=notmuch-reply-test \
911 '[header]="X-Original-To: test_suite_other@notmuchmail.org"' \
912 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
913 '[body]="from guessing test"'
915 output=$($NOTMUCH reply id:${gen_msg_id})
916 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
917 Subject: Re: notmuch-reply-test
918 To: Sender <sender@example.com>, mailinglist@notmuchmail.org
919 Bcc: test_suite@notmuchmail.org
920 In-Reply-To: <${gen_msg_id}>
921 References: <${gen_msg_id}>
923 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
924 > from guessing test"
926 printf " Magic from guessing (Received: .. for ..)...\t"
927 add_message '[from]="Sender <sender@example.com>"' \
928 [to]=mailinglist@notmuchmail.org \
929 [subject]=notmuch-reply-test \
930 '[header]="Received: from mail.example.com (mail.example.com [1.1.1.1])\
931 by mail.notmuchmail.org (some MTA) with ESMTP id 12345678\
932 for <test_suite_other@notmuchmail.org>; Sat, 10 Apr 2010 07:54:51 -0400 (EDT)"' \
933 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
934 '[body]="from guessing test"'
936 output=$($NOTMUCH reply id:${gen_msg_id})
937 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
938 Subject: Re: notmuch-reply-test
939 To: Sender <sender@example.com>, mailinglist@notmuchmail.org
940 Bcc: test_suite@notmuchmail.org
941 In-Reply-To: <${gen_msg_id}>
942 References: <${gen_msg_id}>
944 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
945 > from guessing test"
947 printf " Magic from guessing (Received: domain)...\t"
948 add_message '[from]="Sender <sender@example.com>"' \
949 [to]=mailinglist@notmuchmail.org \
950 [subject]=notmuch-reply-test \
951 '[header]="Received: from mail.example.com (mail.example.com [1.1.1.1])\
952 by mail.otherdomain.org (some MTA) with ESMTP id 12345678\
953 Sat, 10 Apr 2010 07:54:51 -0400 (EDT)"' \
954 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
955 '[body]="from guessing test"'
957 output=$($NOTMUCH reply id:${gen_msg_id})
958 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@otherdomain.org>
959 Subject: Re: notmuch-reply-test
960 To: Sender <sender@example.com>, mailinglist@notmuchmail.org
961 Bcc: test_suite@notmuchmail.org
962 In-Reply-To: <${gen_msg_id}>
963 References: <${gen_msg_id}>
965 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
966 > from guessing test"
970 echo "Notmuch test suite complete."
972 if [ "$test_failures" = "0" ]; then
973 echo "All $tests tests passed."
976 echo "$test_failures/$tests tests failed. The failures can be investigated in:"