]> git.notmuchmail.org Git - notmuch/blob - test/notmuch-test
test: Unify all tests to use the pass_if_equal function.
[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 alos supported here, so see that function for details.
150 add_message ()
151 {
152     generate_message "$@"
153
154     $NOTMUCH new > /dev/null
155 }
156
157 pass_if_equal ()
158 {
159     output=$1
160     expected=$2
161
162     if [ "$output" = "$expected" ]; then
163         echo "  PASS"
164     else
165         echo "  FAIL"
166         echo "  Expected output: $expected"
167         echo "  Actual output:   $output"
168     fi
169 }
170
171 TEST_DIR=$(pwd)/test.$$
172 MAIL_DIR=${TEST_DIR}/mail
173 export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
174 NOTMUCH=$(find_notmuch_binary $(pwd))
175
176 NOTMUCH_NEW ()
177 {
178     $NOTMUCH new | grep -v -E -e '^Processed [0-9]*( total)? file|Found [0-9]* total file'
179 }
180
181 NOTMUCH_SEARCH_THREAD_ID_SQUELCH='s/thread:................/thread:XXX/'
182 notmuch_search_sanitize ()
183 {
184     sed -e "$NOTMUCH_SEARCH_THREAD_ID_SQUELCH"
185 }
186
187 rm -rf ${TEST_DIR}
188 mkdir ${TEST_DIR}
189 cd ${TEST_DIR}
190
191 mkdir ${MAIL_DIR}
192
193 cat <<EOF > ${NOTMUCH_CONFIG}
194 [database]
195 path=${MAIL_DIR}
196
197 [user]
198 name=Notmuch Test Suite
199 primary_email=test_suite@notmuchmail.org
200 other_email=test_suite_other@notmuchmail.org
201 EOF
202
203 printf "Testing \"notmuch new\" in several variations:\n"
204 printf " No new messages...\t\t\t\t"
205 output=$(NOTMUCH_NEW)
206 pass_if_equal "$output" "No new mail."
207
208 printf " Single new message...\t\t\t\t"
209 generate_message
210 output=$(NOTMUCH_NEW)
211 pass_if_equal "$output" "Added 1 new message to the database."
212
213 printf " Multiple new messages...\t\t\t"
214 generate_message
215 generate_message
216 output=$(NOTMUCH_NEW)
217 pass_if_equal "$output" "Added 2 new messages to the database."
218
219 printf " No new messages (non-empty DB)...\t\t"
220 output=$(NOTMUCH_NEW)
221 pass_if_equal "$output" "No new mail."
222
223 printf " New directories...\t\t\t\t"
224 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
225 mkdir ${MAIL_DIR}/def
226 mkdir ${MAIL_DIR}/ghi
227 generate_message [dir]=def
228
229 output=$(NOTMUCH_NEW)
230 pass_if_equal "$output" "Added 1 new message to the database."
231
232 printf " Alternate inode order...\t\t\t"
233
234 rm -rf ${MAIL_DIR}/.notmuch
235 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
236 rm ${MAIL_DIR}/def/*
237 generate_message [dir]=abc
238
239 output=$(NOTMUCH_NEW)
240 pass_if_equal "$output" "Added 1 new message to the database."
241
242 printf " Message moved in...\t\t\t\t"
243 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
244 generate_message
245 tmp_msg_filename=tmp/$gen_msg_filename
246 mkdir -p $(dirname $tmp_msg_filename)
247 mv $gen_msg_filename $tmp_msg_filename
248 increment_mtime ${MAIL_DIR}
249 $NOTMUCH new > /dev/null
250 mv $tmp_msg_filename $gen_msg_filename
251 increment_mtime ${MAIL_DIR}
252 output=$(NOTMUCH_NEW)
253 pass_if_equal "$output" "Added 1 new message to the database."
254
255 printf " Renamed message...\t\t\t\t"
256
257 generate_message
258 $NOTMUCH new > /dev/null
259 mv $gen_msg_filename ${gen_msg_filename}-renamed
260 increment_mtime ${MAIL_DIR}
261 output=$(NOTMUCH_NEW)
262 pass_if_equal "$output" "No new mail. Detected 1 file rename."
263
264 printf " Deleted message...\t\t\t\t"
265
266 rm ${gen_msg_filename}-renamed
267 increment_mtime ${MAIL_DIR}
268 output=$(NOTMUCH_NEW)
269 pass_if_equal "$output" "No new mail. Removed 1 message."
270
271 printf " Renamed directory...\t\t\t\t"
272
273 generate_message [dir]=dir
274 generate_message [dir]=dir
275 generate_message [dir]=dir
276
277 $NOTMUCH new > /dev/null
278
279 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
280 increment_mtime ${MAIL_DIR}
281
282 output=$(NOTMUCH_NEW)
283 pass_if_equal "$output" "No new mail. Detected 3 file renames."
284
285 printf " Deleted directory...\t\t\t\t"
286
287 rm -rf ${MAIL_DIR}/dir-renamed
288 increment_mtime ${MAIL_DIR}
289
290 output=$(NOTMUCH_NEW)
291 pass_if_equal "$output" "No new mail. Removed 3 messages."
292
293 printf " New directory (at end of list)...\t\t"
294
295 generate_message [dir]=zzz
296 generate_message [dir]=zzz
297 generate_message [dir]=zzz
298
299 output=$(NOTMUCH_NEW)
300 pass_if_equal "$output" "Added 3 new messages to the database."
301
302 printf " Deleted directory (end of list)...\t\t"
303
304 rm -rf ${MAIL_DIR}/zzz
305 increment_mtime ${MAIL_DIR}
306
307 output=$(NOTMUCH_NEW)
308 pass_if_equal "$output" "No new mail. Removed 3 messages."
309
310 printf " New symlink to directory...\t\t\t"
311
312 rm -rf ${MAIL_DIR}/.notmuch
313 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
314
315 mkdir ${MAIL_DIR}
316 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
317
318 output=$(NOTMUCH_NEW)
319 pass_if_equal "$output" "Added 1 new message to the database."
320
321 printf " New symlink to a file...\t\t\t"
322 generate_message
323 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
324 mkdir -p $(dirname $external_msg_filename)
325 mv $gen_msg_filename $external_msg_filename
326 ln -s $external_msg_filename $gen_msg_filename
327 increment_mtime ${MAIL_DIR}
328 output=$(NOTMUCH_NEW)
329 pass_if_equal "$output" "Added 1 new message to the database."
330
331 printf " New two-level directory...\t\t\t"
332
333 generate_message [dir]=two/levels
334 generate_message [dir]=two/levels
335 generate_message [dir]=two/levels
336
337 output=$(NOTMUCH_NEW)
338 pass_if_equal "$output" "Added 3 new messages to the database."
339
340 printf " Deleted two-level directory...\t\t\t"
341
342 rm -rf ${MAIL_DIR}/two
343 increment_mtime ${MAIL_DIR}
344
345 output=$(NOTMUCH_NEW)
346 pass_if_equal "$output" "No new mail. Removed 3 messages."
347
348 printf "\nTesting \"notmuch search\" in several variations:\n"
349
350 printf " Search body...\t\t\t\t\t"
351 add_message '[subject]="body search"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [body]=bodysearchtest
352 output=$($NOTMUCH search bodysearchtest | notmuch_search_sanitize)
353 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)"
354
355 printf " Search by from:...\t\t\t\t"
356 add_message '[subject]="search by from"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom
357 output=$($NOTMUCH search from:searchbyfrom | notmuch_search_sanitize)
358 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)"
359
360 printf " Search by to:...\t\t\t\t"
361 add_message '[subject]="search by to"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto
362 output=$($NOTMUCH search to:searchbyto | notmuch_search_sanitize)
363 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)"
364
365 printf " Search by subject:...\t\t\t\t"
366 add_message [subject]=subjectsearchtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
367 output=$($NOTMUCH search subject:subjectsearchtest | notmuch_search_sanitize)
368 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)"
369
370 printf " Search by id:...\t\t\t\t"
371 add_message '[subject]="search by id"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
372 output=$($NOTMUCH search id:${gen_msg_id} | notmuch_search_sanitize)
373 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
374
375 printf " Search by tag:...\t\t\t\t"
376 add_message '[subject]="search by tag"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
377 $NOTMUCH tag +searchbytag id:${gen_msg_id}
378 output=$($NOTMUCH search tag:searchbytag | notmuch_search_sanitize)
379 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)"
380
381 printf " Search by thread:...\t\t\t\t"
382 add_message '[subject]="search by thread"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
383 thread_id=$($NOTMUCH search id:${gen_msg_id} | sed -e 's/thread:\([a-f0-9]*\).*/\1/')
384 output=$($NOTMUCH search thread:${thread_id} | notmuch_search_sanitize)
385 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)"
386
387 printf " Search body (phrase)...\t\t\t"
388 add_message '[subject]="body search (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="body search (phrase)"'
389 add_message '[subject]="negative result"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="This phrase should not match the body search"'
390 output=$($NOTMUCH search '\"body search (phrase)\"' | notmuch_search_sanitize)
391 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)"
392
393 printf " Search by from: (address)...\t\t\t"
394 add_message '[subject]="search by from (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom@example.com
395 output=$($NOTMUCH search from:searchbyfrom@example.com | notmuch_search_sanitize)
396 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)"
397
398 printf " Search by from: (name)...\t\t\t"
399 add_message '[subject]="search by from (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[from]="Search By From Name <test@example.com>"'
400 output=$($NOTMUCH search from:'Search By From Name' | notmuch_search_sanitize)
401 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
402
403 printf " Search by to: (address)...\t\t\t"
404 add_message '[subject]="search by to (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto@example.com
405 output=$($NOTMUCH search to:searchbyto@example.com | notmuch_search_sanitize)
406 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)"
407
408 printf " Search by to: (name)...\t\t\t"
409 add_message '[subject]="search by to (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[to]="Search By To Name <test@example.com>"'
410 output=$($NOTMUCH search to:'Search By To Name' | notmuch_search_sanitize)
411 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
412
413 printf " Search by subject: (phrase)...\t\t\t"
414 add_message '[subject]="subject search test (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
415 add_message '[subject]="this phrase should not match the subject search test"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
416 output=$($NOTMUCH search 'subject:\"subject search test (phrase)\"' | notmuch_search_sanitize)
417 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)"
418
419 printf " Search for all messages (\"*\"):...\t\t"
420 output=$($NOTMUCH search '*' | notmuch_search_sanitize)
421 pass_if_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #6 (inbox unread)
422 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Test message #14 (inbox unread)
423 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)
424 thread:XXX   2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)
425 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)
426 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)
427 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)
428 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)
429 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)
430 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)
431 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; negative result (inbox unread)
432 thread:XXX   2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)
433 thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)
434 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)
435 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)
436 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)
437 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; this phrase should not match the subject search test (inbox unread)"
438
439 printf "\nTesting \"notmuch reply\" in several variations:\n"
440
441 printf " Basic reply...\t\t\t\t\t"
442 add_message '[from]="Sender <sender@example.com>"' \
443              [to]=test_suite@notmuchmail.org \
444              [subject]=notmuch-reply-test \
445             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
446             '[body]="basic reply test"'
447
448 output=$($NOTMUCH reply id:${gen_msg_id})
449 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
450 Subject: Re: notmuch-reply-test
451 To: Sender <sender@example.com>
452 Bcc: test_suite@notmuchmail.org
453 In-Reply-To: <${gen_msg_id}>
454 References: <${gen_msg_id}>
455
456 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
457 > basic reply test"
458
459 printf " Multiple recipients...\t\t\t\t"
460 add_message '[from]="Sender <sender@example.com>"' \
461             '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
462              [subject]=notmuch-reply-test \
463             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
464             '[body]="Multiple recipients"'
465
466 output=$($NOTMUCH reply id:${gen_msg_id})
467 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
468 Subject: Re: notmuch-reply-test
469 To: Sender <sender@example.com>, Someone Else <someone@example.com>
470 Bcc: test_suite@notmuchmail.org
471 In-Reply-To: <${gen_msg_id}>
472 References: <${gen_msg_id}>
473
474 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
475 > Multiple recipients"
476
477 printf " Reply with CC...\t\t\t\t"
478 add_message '[from]="Sender <sender@example.com>"' \
479              [to]=test_suite@notmuchmail.org \
480             '[cc]="Other Parties <cc@example.com>"' \
481              [subject]=notmuch-reply-test \
482             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
483             '[body]="reply with CC"'
484
485 output=$($NOTMUCH reply id:${gen_msg_id})
486 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
487 Subject: Re: notmuch-reply-test
488 To: Sender <sender@example.com>
489 Cc: Other Parties <cc@example.com>
490 Bcc: test_suite@notmuchmail.org
491 In-Reply-To: <${gen_msg_id}>
492 References: <${gen_msg_id}>
493
494 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
495 > reply with CC"
496
497 printf " Reply from alternate address...\t\t"
498 add_message '[from]="Sender <sender@example.com>"' \
499              [to]=test_suite_other@notmuchmail.org \
500              [subject]=notmuch-reply-test \
501             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
502             '[body]="reply from alternate address"'
503
504 output=$($NOTMUCH reply id:${gen_msg_id})
505 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
506 Subject: Re: notmuch-reply-test
507 To: Sender <sender@example.com>
508 Bcc: test_suite@notmuchmail.org
509 In-Reply-To: <${gen_msg_id}>
510 References: <${gen_msg_id}>
511
512 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
513 > reply from alternate address"
514
515 printf " Support for Reply-To...\t\t\t"
516 add_message '[from]="Sender <sender@example.com>"' \
517              [to]=test_suite@notmuchmail.org \
518              [subject]=notmuch-reply-test \
519             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
520             '[body]="support for reply-to"' \
521             '[reply-to]="Sender <elsewhere@example.com>"'
522
523 output=$($NOTMUCH reply id:${gen_msg_id})
524 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
525 Subject: Re: notmuch-reply-test
526 To: Sender <elsewhere@example.com>
527 Bcc: test_suite@notmuchmail.org
528 In-Reply-To: <${gen_msg_id}>
529 References: <${gen_msg_id}>
530
531 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
532 > support for reply-to"
533
534 printf " Un-munging Reply-To...\t\t\t\t"
535 add_message '[from]="Sender <sender@example.com>"' \
536             '[to]="Some List <list@example.com>"' \
537              [subject]=notmuch-reply-test \
538             '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
539             '[body]="Un-munging Reply-To"' \
540             '[reply-to]="Evil Munging List <list@example.com>"'
541
542 output=$($NOTMUCH reply id:${gen_msg_id})
543 pass_if_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
544 Subject: Re: notmuch-reply-test
545 To: Sender <sender@example.com>, Some List <list@example.com>
546 Bcc: test_suite@notmuchmail.org
547 In-Reply-To: <${gen_msg_id}>
548 References: <${gen_msg_id}>
549
550 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
551 > Un-munging Reply-To"
552
553 printf "\nTesting handling of uuencoded data:\n"
554
555 add_message [subject]=uuencodetest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
556 '[body]="This message is used to ensure that notmuch correctly handles a
557 message containing a block of uuencoded data. First, we have a marker
558 this content beforeuudata . Then we beging the uunencoded data itself:
559
560 begin 644 bogus-uuencoded-data
561 M0123456789012345678901234567890123456789012345678901234567890
562 MOBVIOUSLY, THIS IS NOT ANY SORT OF USEFUL UUNECODED DATA.    
563 MINSTEAD THIS IS JUST A WAY TO ENSURE THAT THIS BLOCK OF DATA 
564 MIS CORRECTLY IGNORED WHEN NOTMUCH CREATES ITS INDEX. SO WE   
565 MINCLUDE A DURINGUUDATA MARKER THAT SHOULD NOT RESULT IN ANY  
566 MSEARCH RESULT.                                               
567 \`
568 end
569
570 Finally, we have our afteruudata marker as well."'
571
572 printf " Ensure content before uu data is indexed...\t"
573 output=$($NOTMUCH search beforeuudata | notmuch_search_sanitize)
574 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
575 printf " Ensure uu data is not indexed...\t\t"
576 output=$($NOTMUCH search DURINGUUDATA | notmuch_search_sanitize)
577 pass_if_equal "$output" ""
578 printf " Ensure content after uu data is indexed...\t"
579 output=$($NOTMUCH search afteruudata | notmuch_search_sanitize)
580 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
581
582 printf "\nTesting \"notmuch dump\" and \"notmuch restore\":\n"
583
584 printf " Dumping all tags...\t\t\t\t"
585 $NOTMUCH dump dump.expected
586 pass_if_equal "$?" "0"
587
588 printf " Clearing all tags...\t\t\t\t"
589 sed -e 's/(\([^(]*\))$/()/' < dump.expected > clear.expected
590 $NOTMUCH restore clear.expected
591 $NOTMUCH dump clear.actual
592 pass_if_equal "$(< clear.actual)" "$(< clear.expected)"
593
594 printf " Restoring original tags...\t\t\t"
595 $NOTMUCH restore dump.expected
596 $NOTMUCH dump dump.actual
597 pass_if_equal "$(< dump.actual)" "$(< dump.expected)"
598
599 printf " Restore with nothing to do...\t\t\t"
600 $NOTMUCH restore dump.expected
601 pass_if_equal "$?" "0"
602
603 printf "\nTesting threading when messages received out of order:\n"
604 printf " Adding initial child message...\t\t"
605 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
606 output=$(NOTMUCH_NEW)
607 pass_if_equal "$output" "Added 1 new message to the database."
608 printf " Searching returns the message...\t\t"
609 output=$($NOTMUCH search foo | notmuch_search_sanitize)
610 pass_if_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; brokenthreadtest (inbox unread)"
611 printf " Adding second child message...\t\t\t"
612 generate_message [body]=foo '[in-reply-to]=\<parent-id\>' [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
613 output=$(NOTMUCH_NEW)
614 pass_if_equal "$output" "Added 1 new message to the database."
615 printf " Searching returns both messages in one thread..."
616 output=$($NOTMUCH search foo | notmuch_search_sanitize)
617 pass_if_equal "$output" "thread:XXX   2000-01-01 [2/2] Notmuch Test Suite; brokenthreadtest (inbox unread)"
618 printf " Adding parent message...\t\t\t"
619 generate_message [body]=foo [id]=parent-id [subject]=brokenthreadtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
620 output=$(NOTMUCH_NEW)
621 pass_if_equal "$output" "Added 1 new message to the database."
622 printf " Searching returns all three messages in one thread..."
623 output=$($NOTMUCH search foo | notmuch_search_sanitize)
624 pass_if_equal "$output" "thread:XXX   2000-01-01 [3/3] Notmuch Test Suite; brokenthreadtest (inbox unread)"
625
626 cat <<EOF
627 Notmuch test suite complete.
628
629 Intermediate state can be examined in:
630         ${TEST_DIR}
631 EOF