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