]> git.notmuchmail.org Git - notmuch/blob - test/notmuch-test
Merge Sebastian Spaeth's python bindings into bindings/python
[notmuch] / test / notmuch-test
1 #!/bin/bash
2 set -e
3
4 find_notmuch_binary ()
5 {
6     dir=$1
7
8     while [ -n "$dir" ]; do
9         bin=$dir/notmuch
10         if [ -x $bin ]; then
11             echo $bin
12             return
13         fi
14         dir=$(dirname $dir)
15         if [ "$dir" = "/" ]; then
16             break
17         fi
18     done
19
20     echo notmuch
21 }
22
23 increment_mtime_amount=0
24 increment_mtime ()
25 {
26     dir=$1
27
28     increment_mtime_amount=$((increment_mtime_amount + 1))
29     touch -d "+${increment_mtime_amount} seconds" $dir
30 }
31
32 # Generate a new message in the mail directory, with a unique message
33 # ID and subject. The message is not added to the index.
34 #
35 # After this function returns, the filename of the generated message
36 # is available as $gen_msg_filename and the message ID is available as
37 # $gen_msg_id .
38 #
39 # This function supports named parameters with the bash syntax for
40 # assigning a value to an associative array ([name]=value). The
41 # supported parameters are:
42 #
43 #  [dir]=directory/of/choice
44 #
45 #       Generate the message in directory 'directory/of/choice' within
46 #       the mail store. The directory will be created if necessary.
47 #
48 #  [body]=text
49 #
50 #       Text to use as the body of the email message
51 #
52 #  '[from]="Some User <user@example.com>"'
53 #  '[to]="Some User <user@example.com>"'
54 #  '[subject]="Subject of email message"'
55 #  '[date]="RFC 822 Date"'
56 #
57 #       Values for email headers. If not provided, default values will
58 #       be generated instead.
59 #
60 #  '[cc]="Some User <user@example.com>"'
61 #  [reply-to]=some-address
62 #  [in-reply-to]=<message-id>
63 #
64 #       Additional values for email headers. If these are not provided
65 #       then the relevant headers will simply not appear in the
66 #       message.
67 #
68 #  '[id]=<message-id>'
69 #
70 #       Controls the message-id of the created message.
71 gen_msg_cnt=0
72 gen_msg_filename=""
73 gen_msg_id=""
74 generate_message ()
75 {
76     # This is our (bash-specific) magic for doing named parameters
77     local -A template="($@)"
78     local additional_headers
79
80     if [ -z "${template[id]}" ]; then
81         gen_msg_cnt=$((gen_msg_cnt + 1))
82         gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
83         gen_msg_id="${gen_msg_name}@notmuch-test-suite"
84     else
85         gen_msg_name="msg-${template[id]}"
86         gen_msg_id="${template[id]}"
87     fi
88
89     if [ -z "${template[dir]}" ]; then
90         gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
91     else
92         gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
93         mkdir -p $(dirname $gen_msg_filename)
94     fi
95
96     if [ -z "${template[body]}" ]; then
97         template[body]="This is just test message (#${gen_msg_cnt})"
98     fi
99
100     if [ -z "${template[from]}" ]; then
101         template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
102     fi
103
104     if [ -z "${template[to]}" ]; then
105         template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
106     fi
107
108     if [ -z "${template[subject]}" ]; then
109         template[subject]="Test message #${gen_msg_cnt}"
110     fi
111
112     if [ -z "${template[date]}" ]; then
113         template[date]="Tue, 05 Jan 2001 15:43:57 -0800"
114     fi
115
116     additional_headers=""
117     if [ ! -z "${template[reply-to]}" ]; then
118         additional_headers="Reply-To: ${template[reply-to]}
119 ${additional_headers}"
120     fi
121
122     if [ ! -z "${template[in-reply-to]}" ]; then
123         additional_headers="In-Reply-To: ${template[in-reply-to]}
124 ${additional_headers}"
125     fi
126
127     if [ ! -z "${template[cc]}" ]; then
128         additional_headers="Cc: ${template[cc]}
129 ${additional_headers}"
130     fi
131
132 cat <<EOF >$gen_msg_filename
133 From: ${template[from]}
134 To: ${template[to]}
135 Message-Id: <${gen_msg_id}>
136 Subject: ${template[subject]}
137 Date: ${template[date]}
138 ${additional_headers}
139 ${template[body]}
140 EOF
141
142     # Ensure that the mtime of the containing directory is updated
143     increment_mtime $(dirname ${gen_msg_filename})
144 }
145
146 # Generate a new message and add it to the index.
147 #
148 # All of the arguments and return values supported by generate_message
149 # are also supported here, so see that function for details.
150 add_message ()
151 {
152     generate_message "$@"
153
154     $NOTMUCH new > /dev/null
155 }
156
157 tests=0
158 test_failures=0
159
160 pass_if_equal ()
161 {
162     output=$1
163     expected=$2
164
165     tests=$((tests + 1))
166
167     if [ "$output" = "$expected" ]; then
168         echo "  PASS"
169     else
170         echo "  FAIL"
171         echo "  Expected output: $expected"
172         echo "  Actual output:   $output"
173         test_failures=$((test_failures + 1))
174     fi
175 }
176
177 TEST_DIR=$(pwd)/test.$$
178 MAIL_DIR=${TEST_DIR}/mail
179 export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
180 NOTMUCH=$(find_notmuch_binary $(pwd))
181
182 NOTMUCH_NEW ()
183 {
184     $NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
185 }
186
187 NOTMUCH_SEARCH_THREAD_ID_SQUELCH='s/thread:................/thread:XXX/'
188 notmuch_search_sanitize ()
189 {
190     sed -e "$NOTMUCH_SEARCH_THREAD_ID_SQUELCH"
191 }
192
193 rm -rf ${TEST_DIR}
194 mkdir ${TEST_DIR}
195 cd ${TEST_DIR}
196
197 mkdir ${MAIL_DIR}
198
199 cat <<EOF > ${NOTMUCH_CONFIG}
200 [database]
201 path=${MAIL_DIR}
202
203 [user]
204 name=Notmuch Test Suite
205 primary_email=test_suite@notmuchmail.org
206 other_email=test_suite_other@notmuchmail.org
207 EOF
208
209 printf "Testing \"notmuch new\" in several variations:\n"
210 printf " No new messages...\t\t\t\t"
211 output=$(NOTMUCH_NEW)
212 pass_if_equal "$output" "No new mail."
213
214 printf " Single new message...\t\t\t\t"
215 generate_message
216 output=$(NOTMUCH_NEW)
217 pass_if_equal "$output" "Added 1 new message to the database."
218
219 printf " Multiple new messages...\t\t\t"
220 generate_message
221 generate_message
222 output=$(NOTMUCH_NEW)
223 pass_if_equal "$output" "Added 2 new messages to the database."
224
225 printf " No new messages (non-empty DB)...\t\t"
226 output=$(NOTMUCH_NEW)
227 pass_if_equal "$output" "No new mail."
228
229 printf " New directories...\t\t\t\t"
230 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
231 mkdir ${MAIL_DIR}/def
232 mkdir ${MAIL_DIR}/ghi
233 generate_message [dir]=def
234
235 output=$(NOTMUCH_NEW)
236 pass_if_equal "$output" "Added 1 new message to the database."
237
238 printf " Alternate inode order...\t\t\t"
239
240 rm -rf ${MAIL_DIR}/.notmuch
241 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
242 rm ${MAIL_DIR}/def/*
243 generate_message [dir]=abc
244
245 output=$(NOTMUCH_NEW)
246 pass_if_equal "$output" "Added 1 new message to the database."
247
248 printf " Message moved in...\t\t\t\t"
249 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
250 generate_message
251 tmp_msg_filename=tmp/$gen_msg_filename
252 mkdir -p $(dirname $tmp_msg_filename)
253 mv $gen_msg_filename $tmp_msg_filename
254 increment_mtime ${MAIL_DIR}
255 $NOTMUCH new > /dev/null
256 mv $tmp_msg_filename $gen_msg_filename
257 increment_mtime ${MAIL_DIR}
258 output=$(NOTMUCH_NEW)
259 pass_if_equal "$output" "Added 1 new message to the database."
260
261 printf " Renamed message...\t\t\t\t"
262
263 generate_message
264 $NOTMUCH new > /dev/null
265 mv $gen_msg_filename ${gen_msg_filename}-renamed
266 increment_mtime ${MAIL_DIR}
267 output=$(NOTMUCH_NEW)
268 pass_if_equal "$output" "No new mail. Detected 1 file rename."
269
270 printf " Deleted message...\t\t\t\t"
271
272 rm ${gen_msg_filename}-renamed
273 increment_mtime ${MAIL_DIR}
274 output=$(NOTMUCH_NEW)
275 pass_if_equal "$output" "No new mail. Removed 1 message."
276
277 printf " Renamed directory...\t\t\t\t"
278
279 generate_message [dir]=dir
280 generate_message [dir]=dir
281 generate_message [dir]=dir
282
283 $NOTMUCH new > /dev/null
284
285 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
286 increment_mtime ${MAIL_DIR}
287
288 output=$(NOTMUCH_NEW)
289 pass_if_equal "$output" "No new mail. Detected 3 file renames."
290
291 printf " Deleted directory...\t\t\t\t"
292
293 rm -rf ${MAIL_DIR}/dir-renamed
294 increment_mtime ${MAIL_DIR}
295
296 output=$(NOTMUCH_NEW)
297 pass_if_equal "$output" "No new mail. Removed 3 messages."
298
299 printf " New directory (at end of list)...\t\t"
300
301 generate_message [dir]=zzz
302 generate_message [dir]=zzz
303 generate_message [dir]=zzz
304
305 output=$(NOTMUCH_NEW)
306 pass_if_equal "$output" "Added 3 new messages to the database."
307
308 printf " Deleted directory (end of list)...\t\t"
309
310 rm -rf ${MAIL_DIR}/zzz
311 increment_mtime ${MAIL_DIR}
312
313 output=$(NOTMUCH_NEW)
314 pass_if_equal "$output" "No new mail. Removed 3 messages."
315
316 printf " New symlink to directory...\t\t\t"
317
318 rm -rf ${MAIL_DIR}/.notmuch
319 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
320
321 mkdir ${MAIL_DIR}
322 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
323
324 output=$(NOTMUCH_NEW)
325 pass_if_equal "$output" "Added 1 new message to the database."
326
327 printf " New symlink to a file...\t\t\t"
328 generate_message
329 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
330 mkdir -p $(dirname $external_msg_filename)
331 mv $gen_msg_filename $external_msg_filename
332 ln -s $external_msg_filename $gen_msg_filename
333 increment_mtime ${MAIL_DIR}
334 output=$(NOTMUCH_NEW)
335 pass_if_equal "$output" "Added 1 new message to the database."
336
337 printf " New two-level directory...\t\t\t"
338
339 generate_message [dir]=two/levels
340 generate_message [dir]=two/levels
341 generate_message [dir]=two/levels
342
343 output=$(NOTMUCH_NEW)
344 pass_if_equal "$output" "Added 3 new messages to the database."
345
346 printf " Deleted two-level directory...\t\t\t"
347
348 rm -rf ${MAIL_DIR}/two
349 increment_mtime ${MAIL_DIR}
350
351 output=$(NOTMUCH_NEW)
352 pass_if_equal "$output" "No new mail. Removed 3 messages."
353
354 printf "\nTesting \"notmuch search\" in several variations:\n"
355
356 printf " Search body...\t\t\t\t\t"
357 add_message '[subject]="body search"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [body]=bodysearchtest
358 output=$($NOTMUCH search bodysearchtest | notmuch_search_sanitize)
359 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)"
360
361 printf " Search by from:...\t\t\t\t"
362 add_message '[subject]="search by from"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom
363 output=$($NOTMUCH search from:searchbyfrom | notmuch_search_sanitize)
364 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)"
365
366 printf " Search by to:...\t\t\t\t"
367 add_message '[subject]="search by to"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto
368 output=$($NOTMUCH search to:searchbyto | notmuch_search_sanitize)
369 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)"
370
371 printf " Search by subject:...\t\t\t\t"
372 add_message [subject]=subjectsearchtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
373 output=$($NOTMUCH search subject:subjectsearchtest | notmuch_search_sanitize)
374 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)"
375
376 printf " Search by id:...\t\t\t\t"
377 add_message '[subject]="search by id"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
378 output=$($NOTMUCH search id:${gen_msg_id} | notmuch_search_sanitize)
379 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
380
381 printf " Search by tag:...\t\t\t\t"
382 add_message '[subject]="search by tag"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
383 $NOTMUCH tag +searchbytag id:${gen_msg_id}
384 output=$($NOTMUCH search tag:searchbytag | notmuch_search_sanitize)
385 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)"
386
387 printf " Search by thread:...\t\t\t\t"
388 add_message '[subject]="search by thread"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
389 thread_id=$($NOTMUCH search id:${gen_msg_id} | sed -e 's/thread:\([a-f0-9]*\).*/\1/')
390 output=$($NOTMUCH search thread:${thread_id} | notmuch_search_sanitize)
391 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)"
392
393 printf " Search body (phrase)...\t\t\t"
394 add_message '[subject]="body search (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="body search (phrase)"'
395 add_message '[subject]="negative result"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="This phrase should not match the body search"'
396 output=$($NOTMUCH search '\"body search (phrase)\"' | notmuch_search_sanitize)
397 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)"
398
399 printf " Search by from: (address)...\t\t\t"
400 add_message '[subject]="search by from (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom@example.com
401 output=$($NOTMUCH search from:searchbyfrom@example.com | notmuch_search_sanitize)
402 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)"
403
404 printf " Search by from: (name)...\t\t\t"
405 add_message '[subject]="search by from (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[from]="Search By From Name <test@example.com>"'
406 output=$($NOTMUCH search from:'Search By From Name' | notmuch_search_sanitize)
407 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
408
409 printf " Search by to: (address)...\t\t\t"
410 add_message '[subject]="search by to (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto@example.com
411 output=$($NOTMUCH search to:searchbyto@example.com | notmuch_search_sanitize)
412 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)"
413
414 printf " Search by to: (name)...\t\t\t"
415 add_message '[subject]="search by to (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[to]="Search By To Name <test@example.com>"'
416 output=$($NOTMUCH search to:'Search By To Name' | notmuch_search_sanitize)
417 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
418
419 printf " Search by subject: (phrase)...\t\t\t"
420 add_message '[subject]="subject search test (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
421 add_message '[subject]="this phrase should not match the subject search test"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
422 output=$($NOTMUCH search 'subject:\"subject search test (phrase)\"' | notmuch_search_sanitize)
423 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)"
424
425 printf " Search for all messages (\"*\"):...\t\t"
426 output=$($NOTMUCH search '*' | notmuch_search_sanitize)
427 pass_if_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #6 (inbox unread)
428 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #14 (inbox unread)
429 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)
430 thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)
431 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)
432 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)
433 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)
434 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)
435 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)
436 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)
437 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; negative result (inbox unread)
438 thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)
439 thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)
440 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)
441 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)
442 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)
443 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; this phrase should not match the subject search test (inbox unread)"
444
445 printf "\nTesting naming of threads with changing subject:\n"
446 add_message '[subject]="thread-naming: Initial thread subject"' \
447             '[date]="Fri, 05 Jan 2001 15:43:56 -0800"'
448 parent=${gen_msg_id}
449 add_message '[subject]="thread-naming: Older changed subject"' \
450             '[date]="Sat, 06 Jan 2001 15:43:56 -0800"' \
451             "[in-reply-to]=\<$parent\>"
452 add_message '[subject]="thread-naming: Newer changed subject"' \
453             '[date]="Sun, 07 Jan 2001 15:43:56 -0800"' \
454             "[in-reply-to]=\<$parent\>"
455 add_message '[subject]="thread-naming: Final thread subject"' \
456             '[date]="Mon, 08 Jan 2001 15:43:56 -0800"' \
457             "[in-reply-to]=\<$parent\>"
458 final=${gen_msg_id}
459
460 printf " Initial thread name (oldest-first search)...\t"
461 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
462 pass_if_equal "$output" "thread:XXX   2001-01-05 [4/4] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
463
464 printf " Initial thread name (newest-first search)...\t"
465 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
466 pass_if_equal "$output" "thread:XXX   2001-01-08 [4/4] Notmuch Test Suite; thread-naming: Final thread subject (inbox unread)"
467
468 # Remove oldest and newest messages from search results
469 $NOTMUCH tag -inbox id:$parent or id:$final
470
471 printf " Changed thread name (oldest-first search)...\t"
472 output=$($NOTMUCH search --sort=oldest-first thread-naming and tag:inbox | notmuch_search_sanitize)
473 pass_if_equal "$output" "thread:XXX   2001-01-06 [2/4] Notmuch Test Suite; thread-naming: Older changed subject (inbox unread)"
474
475 printf " Changed thread name (newest-first search)...\t"
476 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
477 pass_if_equal "$output" "thread:XXX   2001-01-07 [2/4] Notmuch Test Suite; thread-naming: Newer changed subject (inbox unread)"
478
479 printf " Ignore added reply prefix (Re:)...\t\t"
480 add_message '[subject]="Re: thread-naming: Initial thread subject"' \
481             '[date]="Tue, 09 Jan 2001 15:43:45 -0800"' \
482             "[in-reply-to]=\<$parent\>"
483 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
484 pass_if_equal "$output" "thread:XXX   2001-01-09 [3/5] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
485
486 printf " Ignore added reply prefix (Aw:)...\t\t"
487 add_message '[subject]="Aw: thread-naming: Initial thread subject"' \
488             '[date]="Wed, 10 Jan 2001 15:43:45 -0800"' \
489             "[in-reply-to]=\<$parent\>"
490 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
491 pass_if_equal "$output" "thread:XXX   2001-01-10 [4/6] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
492
493 printf " Ignore added reply prefix (Vs:)...\t\t"
494 add_message '[subject]="Vs: thread-naming: Initial thread subject"' \
495             '[date]="Thu, 11 Jan 2001 15:43:45 -0800"' \
496             "[in-reply-to]=\<$parent\>"
497 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
498 pass_if_equal "$output" "thread:XXX   2001-01-11 [5/7] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
499
500 printf " Ignore added reply prefix (Sv:)...\t\t"
501 add_message '[subject]="Sv: thread-naming: Initial thread subject"' \
502             '[date]="Fri, 12 Jan 2001 15:43:45 -0800"' \
503             "[in-reply-to]=\<$parent\>"
504 output=$($NOTMUCH search --sort=newest-first thread-naming and tag:inbox | notmuch_search_sanitize)
505 pass_if_equal "$output" "thread:XXX   2001-01-12 [6/8] Notmuch Test Suite; thread-naming: Initial thread subject (inbox unread)"
506
507 printf "\nTesting \"notmuch reply\" in several variations:\n"
508
509 printf " Basic reply...\t\t\t\t\t"
510 add_message '[from]="Sender <sender@example.com>"' \
511              [to]=test_suite@notmuchmail.org \
512              [subject]=notmuch-reply-test \
513             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
514             '[body]="basic reply test"'
515
516 output=$($NOTMUCH reply id:${gen_msg_id})
517 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
518 Subject: Re: notmuch-reply-test
519 To: Sender <sender@example.com>
520 Bcc: test_suite@notmuchmail.org
521 In-Reply-To: <${gen_msg_id}>
522 References: <${gen_msg_id}>
523
524 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
525 > basic reply test"
526
527 printf " Multiple recipients...\t\t\t\t"
528 add_message '[from]="Sender <sender@example.com>"' \
529             '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
530              [subject]=notmuch-reply-test \
531             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
532             '[body]="Multiple recipients"'
533
534 output=$($NOTMUCH reply id:${gen_msg_id})
535 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
536 Subject: Re: notmuch-reply-test
537 To: Sender <sender@example.com>, Someone Else <someone@example.com>
538 Bcc: test_suite@notmuchmail.org
539 In-Reply-To: <${gen_msg_id}>
540 References: <${gen_msg_id}>
541
542 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
543 > Multiple recipients"
544
545 printf " Reply with CC...\t\t\t\t"
546 add_message '[from]="Sender <sender@example.com>"' \
547              [to]=test_suite@notmuchmail.org \
548             '[cc]="Other Parties <cc@example.com>"' \
549              [subject]=notmuch-reply-test \
550             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
551             '[body]="reply with CC"'
552
553 output=$($NOTMUCH reply id:${gen_msg_id})
554 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
555 Subject: Re: notmuch-reply-test
556 To: Sender <sender@example.com>
557 Cc: Other Parties <cc@example.com>
558 Bcc: test_suite@notmuchmail.org
559 In-Reply-To: <${gen_msg_id}>
560 References: <${gen_msg_id}>
561
562 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
563 > reply with CC"
564
565 printf " Reply from alternate address...\t\t"
566 add_message '[from]="Sender <sender@example.com>"' \
567              [to]=test_suite_other@notmuchmail.org \
568              [subject]=notmuch-reply-test \
569             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
570             '[body]="reply from alternate address"'
571
572 output=$($NOTMUCH reply id:${gen_msg_id})
573 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
574 Subject: Re: notmuch-reply-test
575 To: Sender <sender@example.com>
576 Bcc: test_suite@notmuchmail.org
577 In-Reply-To: <${gen_msg_id}>
578 References: <${gen_msg_id}>
579
580 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
581 > reply from alternate address"
582
583 printf " Support for Reply-To...\t\t\t"
584 add_message '[from]="Sender <sender@example.com>"' \
585              [to]=test_suite@notmuchmail.org \
586              [subject]=notmuch-reply-test \
587             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
588             '[body]="support for reply-to"' \
589             '[reply-to]="Sender <elsewhere@example.com>"'
590
591 output=$($NOTMUCH reply id:${gen_msg_id})
592 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
593 Subject: Re: notmuch-reply-test
594 To: Sender <elsewhere@example.com>
595 Bcc: test_suite@notmuchmail.org
596 In-Reply-To: <${gen_msg_id}>
597 References: <${gen_msg_id}>
598
599 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
600 > support for reply-to"
601
602 printf " Un-munging Reply-To...\t\t\t\t"
603 add_message '[from]="Sender <sender@example.com>"' \
604             '[to]="Some List <list@example.com>"' \
605              [subject]=notmuch-reply-test \
606             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
607             '[body]="Un-munging Reply-To"' \
608             '[reply-to]="Evil Munging List <list@example.com>"'
609
610 output=$($NOTMUCH reply id:${gen_msg_id})
611 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
612 Subject: Re: notmuch-reply-test
613 To: Sender <sender@example.com>, Some List <list@example.com>
614 Bcc: test_suite@notmuchmail.org
615 In-Reply-To: <${gen_msg_id}>
616 References: <${gen_msg_id}>
617
618 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
619 > Un-munging Reply-To"
620
621 printf "\nTesting handling of uuencoded data:\n"
622
623 add_message [subject]=uuencodetest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
624 '[body]="This message is used to ensure that notmuch correctly handles a
625 message containing a block of uuencoded data. First, we have a marker
626 this content beforeuudata . Then we beging the uunencoded data itself:
627
628 begin 644 bogus-uuencoded-data
629 M0123456789012345678901234567890123456789012345678901234567890
630 MOBVIOUSLY, THIS IS NOT ANY SORT OF USEFUL UUNECODED DATA.    
631 MINSTEAD THIS IS JUST A WAY TO ENSURE THAT THIS BLOCK OF DATA 
632 MIS CORRECTLY IGNORED WHEN NOTMUCH CREATES ITS INDEX. SO WE   
633 MINCLUDE A DURINGUUDATA MARKER THAT SHOULD NOT RESULT IN ANY  
634 MSEARCH RESULT.                                               
635 \`
636 end
637
638 Finally, we have our afteruudata marker as well."'
639
640 printf " Ensure content before uu data is indexed...\t"
641 output=$($NOTMUCH search beforeuudata | notmuch_search_sanitize)
642 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
643 printf " Ensure uu data is not indexed...\t\t"
644 output=$($NOTMUCH search DURINGUUDATA | notmuch_search_sanitize)
645 pass_if_equal "$output" ""
646 printf " Ensure content after uu data is indexed...\t"
647 output=$($NOTMUCH search afteruudata | notmuch_search_sanitize)
648 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
649
650 printf "\nTesting \"notmuch dump\" and \"notmuch restore\":\n"
651
652 printf " Dumping all tags...\t\t\t\t"
653 $NOTMUCH dump dump.expected
654 pass_if_equal "$?" "0"
655
656 printf " Clearing all tags...\t\t\t\t"
657 sed -e 's/(\([^(]*\))$/()/' < dump.expected > clear.expected
658 $NOTMUCH restore clear.expected
659 $NOTMUCH dump clear.actual
660 pass_if_equal "$(< clear.actual)" "$(< clear.expected)"
661
662 printf " Restoring original tags...\t\t\t"
663 $NOTMUCH restore dump.expected
664 $NOTMUCH dump dump.actual
665 pass_if_equal "$(< dump.actual)" "$(< dump.expected)"
666
667 printf " Restore with nothing to do...\t\t\t"
668 $NOTMUCH restore dump.expected
669 pass_if_equal "$?" "0"
670
671 printf "\nTesting threading when messages received out of order:\n"
672 printf " Adding initial child message...\t\t"
673 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
674 output=$(NOTMUCH_NEW)
675 pass_if_equal "$output" "Added 1 new message to the database."
676 printf " Searching returns the message...\t\t"
677 output=$($NOTMUCH search foo | notmuch_search_sanitize)
678 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; brokenthreadtest (inbox unread)"
679 printf " Adding second child message...\t\t\t"
680 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
681 output=$(NOTMUCH_NEW)
682 pass_if_equal "$output" "Added 1 new message to the database."
683 printf " Searching returns both messages in one thread..."
684 output=$($NOTMUCH search foo | notmuch_search_sanitize)
685 pass_if_equal "$output" "thread:XXX   2000-01-01 [2/2] Notmuch Test Suite; brokenthreadtest (inbox unread)"
686 printf " Adding parent message...\t\t\t"
687 generate_message [body]=foo [id]=parent-id [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
688 output=$(NOTMUCH_NEW)
689 pass_if_equal "$output" "Added 1 new message to the database."
690 printf " Searching returns all three messages in one thread..."
691 output=$($NOTMUCH search foo | notmuch_search_sanitize)
692 pass_if_equal "$output" "thread:XXX   2000-01-01 [3/3] Notmuch Test Suite; brokenthreadtest (inbox unread)"
693
694 echo ""
695 echo "Notmuch test suite complete."
696
697 if [ "$test_failures" = "0" ]; then
698     echo "All $tests tests passed."
699     rm -rf ${TEST_DIR}
700 else
701     echo "$test_failures/$tests tests failed. The failures can be investigated in:"
702     echo "${TEST_DIR}"
703 fi
704
705 echo ""
706
707 exit $test_failures