8 while [ -n "$dir" ]; do
15 if [ "$dir" = "/" ]; then
23 increment_mtime_amount=0
28 increment_mtime_amount=$((increment_mtime_amount + 1))
29 touch -d "+${increment_mtime_amount} seconds" $dir
32 # Generate a new message in the mail directory, with a unique message
33 # ID and subject. The message is not added to the index.
35 # After this function returns, the filename of the generated message
36 # is available as $gen_msg_filename and the message ID is available as
39 # This function supports named parameters with the bash syntax for
40 # assigning a value to an associative array ([name]=value). The
41 # supported parameters are:
43 # [dir]=directory/of/choice
45 # Generate the message in directory 'directory/of/choice' within
46 # the mail store. The directory will be created if necessary.
50 # Text to use as the body of the email message
52 # '[from]="Some User <user@example.com>"'
53 # '[to]="Some User <user@example.com>"'
54 # '[subject]="Subject of email message"'
55 # '[date]="RFC 822 Date"'
57 # Values for email headers. If not provided, default values will
58 # be generated instead.
60 # '[cc]="Some User <user@example.com>"'
61 # [reply-to]=some-address
62 # [in-reply-to]=<message-id>
64 # Additional values for email headers. If these are not provided
65 # then the relevant headers will simply not appear in the
72 # This is our (bash-specific) magic for doing named parameters
73 local -A template="($@)"
74 local additional_headers
76 gen_msg_cnt=$((gen_msg_cnt + 1))
77 gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
78 gen_msg_id="${gen_msg_name}@notmuch-test-suite"
80 if [ -z "${template[dir]}" ]; then
81 gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
83 gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
84 mkdir -p $(dirname $gen_msg_filename)
87 if [ -z "${template[body]}" ]; then
88 template[body]="This is just a test message at ${gen_msg_filename}"
91 if [ -z "${template[from]}" ]; then
92 template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
95 if [ -z "${template[to]}" ]; then
96 template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
99 if [ -z "${template[subject]}" ]; then
100 template[subject]="Test message ${gen_msg_filename}"
103 if [ -z "${template[date]}" ]; then
104 template[date]="Tue, 05 Jan 2010 15:43:57 -0800"
107 additional_headers=""
108 if [ ! -z "${template[reply-to]}" ]; then
109 additional_headers="Reply-To: ${template[reply-to]}
110 ${additional_headers}"
113 if [ ! -z "${template[in-reply-to]}" ]; then
114 additional_headers="In-Reply-To: ${template[in-reply-to]}
115 ${additional_headers}"
118 if [ ! -z "${template[cc]}" ]; then
119 additional_headers="Cc: ${template[cc]}
120 ${additional_headers}"
123 cat <<EOF >$gen_msg_filename
124 From: ${template[from]}
126 Message-Id: <${gen_msg_id}>
127 Subject: ${template[subject]}
128 Date: ${template[date]}
129 ${additional_headers}
133 # Ensure that the mtime of the containing directory is updated
134 increment_mtime $(dirname ${gen_msg_filename})
137 # Generate a new message and add it to the index.
139 # All of the arguments and return values supported by generate_message
140 # are alos supported here, so see that function for details.
143 generate_message "$@"
145 $NOTMUCH new > /dev/null
148 NOTMUCH_IGNORED_OUTPUT_REGEXP='^Processed [0-9]*( total)? file|Found [0-9]* total file'
149 NOTMUCH_THREAD_ID_SQUELCH='s/thread:................................/thread:XXX/'
155 output=$($NOTMUCH $args | grep -v -E -e "$NOTMUCH_IGNORED_OUTPUT_REGEXP" | sed -e "$NOTMUCH_THREAD_ID_SQUELCH" || true)
156 if [ "$output" = "$expected" ]; then
160 echo " Expected output: $expected"
161 echo " Actual output: $output"
165 TEST_DIR=$(pwd)/test.$$
166 MAIL_DIR=${TEST_DIR}/mail
167 export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
168 NOTMUCH=$(find_notmuch_binary $(pwd))
176 cat <<EOF > ${NOTMUCH_CONFIG}
181 name=Notmuch Test Suite
182 primary_email=test_suite@notmuchmail.org
183 other_email=test_suite_other@notmuchmail.org
186 printf "Testing \"notmuch new\" in several variations:\n"
187 printf " No new messages...\t\t"
188 execute_expecting new "No new mail."
190 printf " Single new message...\t\t"
192 execute_expecting new "Added 1 new message to the database."
194 printf " Multiple new messages...\t"
197 execute_expecting new "Added 2 new messages to the database."
199 printf " No new messages (non-empty DB)... "
200 execute_expecting new "No new mail."
202 printf " New directories...\t\t"
203 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
204 mkdir ${MAIL_DIR}/def
205 mkdir ${MAIL_DIR}/ghi
206 generate_message [dir]=def
208 execute_expecting new "Added 1 new message to the database."
210 printf " Alternate inode order...\t"
212 rm -rf ${MAIL_DIR}/.notmuch
213 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
215 generate_message [dir]=abc
217 execute_expecting new "Added 1 new message to the database."
219 printf " Message moved in...\t\t"
220 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
222 tmp_msg_filename=tmp/$gen_msg_filename
223 mkdir -p $(dirname $tmp_msg_filename)
224 mv $gen_msg_filename $tmp_msg_filename
225 increment_mtime ${MAIL_DIR}
226 $NOTMUCH new > /dev/null
227 mv $tmp_msg_filename $gen_msg_filename
228 increment_mtime ${MAIL_DIR}
229 execute_expecting new "Added 1 new message to the database."
231 printf " Renamed message...\t\t"
234 $NOTMUCH new > /dev/null
235 mv $gen_msg_filename ${gen_msg_filename}-renamed
236 increment_mtime ${MAIL_DIR}
237 execute_expecting new "No new mail. Detected 1 file rename."
239 printf " Deleted message...\t\t"
241 rm ${gen_msg_filename}-renamed
242 increment_mtime ${MAIL_DIR}
243 execute_expecting new "No new mail. Removed 1 message."
245 printf " Renamed directory...\t\t"
247 generate_message [dir]=dir
248 generate_message [dir]=dir
249 generate_message [dir]=dir
251 $NOTMUCH new > /dev/null
253 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
254 increment_mtime ${MAIL_DIR}
256 execute_expecting new "No new mail. Detected 3 file renames."
258 printf " Deleted directory...\t\t"
260 rm -rf ${MAIL_DIR}/dir-renamed
261 increment_mtime ${MAIL_DIR}
263 execute_expecting new "No new mail. Removed 3 messages."
265 printf " New directory (at end of list)... "
267 generate_message [dir]=zzz
268 generate_message [dir]=zzz
269 generate_message [dir]=zzz
271 execute_expecting new "Added 3 new messages to the database."
273 printf " Deleted directory (end of list)... "
275 rm -rf ${MAIL_DIR}/zzz
276 increment_mtime ${MAIL_DIR}
278 execute_expecting new "No new mail. Removed 3 messages."
280 printf " New symlink to directory...\t"
282 rm -rf ${MAIL_DIR}/.notmuch
283 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
286 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
288 execute_expecting new "Added 1 new message to the database."
290 printf " New symlink to a file...\t"
292 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
293 mkdir -p $(dirname $external_msg_filename)
294 mv $gen_msg_filename $external_msg_filename
295 ln -s $external_msg_filename $gen_msg_filename
296 increment_mtime ${MAIL_DIR}
297 execute_expecting new "Added 1 new message to the database."
299 printf " New two-level directory...\t"
301 generate_message [dir]=two/levels
302 generate_message [dir]=two/levels
303 generate_message [dir]=two/levels
305 execute_expecting new "Added 3 new messages to the database."
307 printf " Deleted two-level directory... "
309 rm -rf ${MAIL_DIR}/two
310 increment_mtime ${MAIL_DIR}
312 execute_expecting new "No new mail. Removed 3 messages."
314 printf "\nTesting \"notmuch search\" in several variations:\n"
316 printf " Search body...\t\t"
317 add_message '[subject]="body search"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [body]=bodysearchtest
318 execute_expecting "search bodysearchtest" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; body search (inbox unread)"
320 printf " Search by from:...\t\t"
321 add_message '[subject]="search by from"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom
322 execute_expecting "search from:searchbyfrom" "thread:XXX 2000-01-01 [1/1] searchbyfrom; search by from (inbox unread)"
324 printf " Search by to:...\t\t"
325 add_message '[subject]="search by to"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto
326 execute_expecting "search to:searchbyto" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by to (inbox unread)"
328 printf " Search by subject:...\t\t"
329 add_message [subject]=subjectsearchtest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
330 execute_expecting "search subject:subjectsearchtest" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; subjectsearchtest (inbox unread)"
332 printf " Search by id:...\t\t"
333 add_message '[subject]="search by id"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
334 execute_expecting "search id:${gen_msg_id}" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by id (inbox unread)"
336 printf " Search by tag:...\t\t"
337 add_message '[subject]="search by tag"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
338 $NOTMUCH tag +searchbytag id:${gen_msg_id}
339 execute_expecting "search tag:searchbytag" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by tag (inbox searchbytag unread)"
341 printf " Search by thread:...\t\t"
342 add_message '[subject]="search by thread"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
343 thread_id=$($NOTMUCH search id:${gen_msg_id} | sed -e 's/thread:\([a-f0-9]*\).*/\1/')
344 execute_expecting "search thread:${thread_id}" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by thread (inbox unread)"
346 printf " Search body (phrase)...\t"
347 add_message '[subject]="body search (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[body]="body search (phrase)"'
348 execute_expecting "search 'body search (phrase)'" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; body search (phrase) (inbox unread)"
350 printf " Search by from: (address)...\t"
351 add_message '[subject]="search by from (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [from]=searchbyfrom@example.com
352 execute_expecting "search from:searchbyfrom@example.com" "thread:XXX 2000-01-01 [1/1] searchbyfrom@example.com; search by from (address) (inbox unread)"
354 printf " Search by from: (name)...\t"
355 add_message '[subject]="search by from (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[from]="Search By From Name <test@example.com>"'
356 execute_expecting "search from:'Search By From Name'" "thread:XXX 2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
358 printf " Search by to: (address)...\t"
359 add_message '[subject]="search by to (address)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' [to]=searchbyto@example.com
360 execute_expecting "search to:searchbyto@example.com" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by to (address) (inbox unread)"
362 printf " Search by to: (name)...\t"
363 add_message '[subject]="search by to (name)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' '[to]="Search By To Name <test@example.com>"'
364 execute_expecting "search to:'Search By To Name'" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
366 printf " Search by subject: (phrase)..."
367 add_message '[subject]="subject search test (phrase)"' '[date]="Sat, 01 Jan 2000 12:00:00 -0000"'
368 execute_expecting "search subject:'subject search test (phrase)'" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; subject search test (phrase) (inbox unread)"
370 printf "\nTesting \"notmuch reply\" in several variations:\n"
372 printf " Basic reply...\t\t\t"
373 add_message '[from]="Sender <sender@example.com>"' \
374 [to]=test_suite@notmuchmail.org \
375 [subject]=notmuch-reply-test \
376 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
377 '[body]="basic reply test"'
379 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
380 Subject: Re: notmuch-reply-test
381 To: Sender <sender@example.com>
382 Bcc: test_suite@notmuchmail.org
383 In-Reply-To: <${gen_msg_id}>
384 References: <${gen_msg_id}>
386 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
389 printf " Multiple recipients...\t\t"
390 add_message '[from]="Sender <sender@example.com>"' \
391 '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
392 [subject]=notmuch-reply-test \
393 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
394 '[body]="Multiple recipients"'
396 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
397 Subject: Re: notmuch-reply-test
398 To: Sender <sender@example.com>, Someone Else <someone@example.com>
399 Bcc: test_suite@notmuchmail.org
400 In-Reply-To: <${gen_msg_id}>
401 References: <${gen_msg_id}>
403 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
404 > Multiple recipients"
406 printf " Reply with CC...\t\t"
407 add_message '[from]="Sender <sender@example.com>"' \
408 [to]=test_suite@notmuchmail.org \
409 '[cc]="Other Parties <cc@example.com>"' \
410 [subject]=notmuch-reply-test \
411 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
412 '[body]="reply with CC"'
414 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
415 Subject: Re: notmuch-reply-test
416 To: Sender <sender@example.com>
417 Cc: Other Parties <cc@example.com>
418 Bcc: test_suite@notmuchmail.org
419 In-Reply-To: <${gen_msg_id}>
420 References: <${gen_msg_id}>
422 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
425 printf " Reply from alternate address..."
426 add_message '[from]="Sender <sender@example.com>"' \
427 [to]=test_suite_other@notmuchmail.org \
428 [subject]=notmuch-reply-test \
429 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
430 '[body]="reply from alternate address"'
432 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
433 Subject: Re: notmuch-reply-test
434 To: Sender <sender@example.com>
435 Bcc: test_suite@notmuchmail.org
436 In-Reply-To: <${gen_msg_id}>
437 References: <${gen_msg_id}>
439 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
440 > reply from alternate address"
442 printf " Support for Reply-To...\t"
443 add_message '[from]="Sender <sender@example.com>"' \
444 [to]=test_suite@notmuchmail.org \
445 [subject]=notmuch-reply-test \
446 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
447 '[body]="support for reply-to"' \
448 '[reply-to]="Sender <elsewhere@example.com>"'
450 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
451 Subject: Re: notmuch-reply-test
452 To: Sender <elsewhere@example.com>
453 Bcc: test_suite@notmuchmail.org
454 In-Reply-To: <${gen_msg_id}>
455 References: <${gen_msg_id}>
457 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
458 > support for reply-to"
460 printf " Un-munging Reply-To...\t\t"
461 add_message '[from]="Sender <sender@example.com>"' \
462 '[to]="Some List <list@example.com>"' \
463 [subject]=notmuch-reply-test \
464 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
465 '[body]="Un-munging Reply-To"' \
466 '[reply-to]="Evil Munging List <list@example.com>"'
468 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
469 Subject: Re: notmuch-reply-test
470 To: Sender <sender@example.com>, Some List <list@example.com>
471 Bcc: test_suite@notmuchmail.org
472 In-Reply-To: <${gen_msg_id}>
473 References: <${gen_msg_id}>
475 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
476 > Un-munging Reply-To"
478 printf "\nTesting handling of uuencoded data:\n"
480 add_message [subject]=uuencodetest '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
481 '[body]="This message is used to ensure that notmuch correctly handles a
482 message containing a block of uuencoded data. First, we have a marker
483 this content beforeuudata . Then we beging the uunencoded data itself:
485 begin 644 bogus-uuencoded-data
486 M0123456789012345678901234567890123456789012345678901234567890
487 MOBVIOUSLY, THIS IS NOT ANY SORT OF USEFUL UUNECODED DATA.
488 MINSTEAD THIS IS JUST A WAY TO ENSURE THAT THIS BLOCK OF DATA
489 MIS CORRECTLY IGNORED WHEN NOTMUCH CREATES ITS INDEX. SO WE
490 MINCLUDE A DURINGUUDATA MARKER THAT SHOULD NOT RESULT IN ANY
495 Finally, we have our afteruudata marker as well."'
497 printf " Ensure content before uu data is indexed..."
498 execute_expecting "search beforeuudata" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
499 printf " Ensure uu data is not indexed...\t"
500 execute_expecting "search DURINGUUDATA" ""
501 printf " Ensure content after uu data is indexed..."
502 execute_expecting "search afteruudata" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; uuencodetest (inbox unread)"
505 Notmuch test suite complete.
507 Intermediate state can be examined in: