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
33 # a unique message ID and subject.
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 NOTMUCH_IGNORED_OUTPUT_REGEXP='^Processed [0-9]*( total)? file|Found [0-9]* total file'
144 output=$($NOTMUCH $args | grep -v -E -e "$NOTMUCH_IGNORED_OUTPUT_REGEXP")
145 if [ "$output" = "$expected" ]; then
149 echo " Expected output: $expected"
150 echo " Actual output: $output"
154 TEST_DIR=$(pwd)/test.$$
155 MAIL_DIR=${TEST_DIR}/mail
156 export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
157 NOTMUCH=$(find_notmuch_binary $(pwd))
165 cat <<EOF > ${NOTMUCH_CONFIG}
170 name=Notmuch Test Suite
171 primary_email=test_suite@notmuchmail.org
172 other_email=test_suite_other@notmuchmail.org
175 printf "Testing \"notmuch new\" in several variations:\n"
176 printf " No new messages...\t\t"
177 execute_expecting new "No new mail."
179 printf " Single new message...\t\t"
181 execute_expecting new "Added 1 new message to the database."
183 printf " Multiple new messages...\t"
186 execute_expecting new "Added 2 new messages to the database."
188 printf " No new messages (non-empty DB)... "
189 execute_expecting new "No new mail."
191 printf " New directories...\t\t"
192 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
193 mkdir ${MAIL_DIR}/def
194 mkdir ${MAIL_DIR}/ghi
195 generate_message [dir]=def
197 execute_expecting new "Added 1 new message to the database."
199 printf " Alternate inode order...\t"
201 rm -rf ${MAIL_DIR}/.notmuch
202 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
204 generate_message [dir]=abc
206 execute_expecting new "Added 1 new message to the database."
208 printf " Message moved in...\t\t"
209 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
211 tmp_msg_filename=tmp/$gen_msg_filename
212 mkdir -p $(dirname $tmp_msg_filename)
213 mv $gen_msg_filename $tmp_msg_filename
214 increment_mtime ${MAIL_DIR}
215 $NOTMUCH new > /dev/null
216 mv $tmp_msg_filename $gen_msg_filename
217 increment_mtime ${MAIL_DIR}
218 execute_expecting new "Added 1 new message to the database."
220 printf " Renamed message...\t\t"
223 $NOTMUCH new > /dev/null
224 mv $gen_msg_filename ${gen_msg_filename}-renamed
225 increment_mtime ${MAIL_DIR}
226 execute_expecting new "No new mail. Detected 1 file rename."
228 printf " Deleted message...\t\t"
230 rm ${gen_msg_filename}-renamed
231 increment_mtime ${MAIL_DIR}
232 execute_expecting new "No new mail. Removed 1 message."
234 printf " Renamed directory...\t\t"
236 generate_message [dir]=dir
237 generate_message [dir]=dir
238 generate_message [dir]=dir
240 $NOTMUCH new > /dev/null
242 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
243 increment_mtime ${MAIL_DIR}
245 execute_expecting new "No new mail. Detected 3 file renames."
247 printf " Deleted directory...\t\t"
249 rm -rf ${MAIL_DIR}/dir-renamed
250 increment_mtime ${MAIL_DIR}
252 execute_expecting new "No new mail. Removed 3 messages."
254 printf " New directory (at end of list)... "
256 generate_message [dir]=zzz
257 generate_message [dir]=zzz
258 generate_message [dir]=zzz
260 execute_expecting new "Added 3 new messages to the database."
262 printf " Deleted directory (end of list)... "
264 rm -rf ${MAIL_DIR}/zzz
265 increment_mtime ${MAIL_DIR}
267 execute_expecting new "No new mail. Removed 3 messages."
269 printf " New symlink to directory...\t"
271 rm -rf ${MAIL_DIR}/.notmuch
272 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
275 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
277 execute_expecting new "Added 1 new message to the database."
279 printf " New symlink to a file...\t"
281 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
282 mkdir -p $(dirname $external_msg_filename)
283 mv $gen_msg_filename $external_msg_filename
284 ln -s $external_msg_filename $gen_msg_filename
285 increment_mtime ${MAIL_DIR}
286 execute_expecting new "Added 1 new message to the database."
288 printf " New two-level directory...\t"
290 generate_message [dir]=two/levels
291 generate_message [dir]=two/levels
292 generate_message [dir]=two/levels
294 execute_expecting new "Added 3 new messages to the database."
296 printf " Deleted two-level directory... "
298 rm -rf ${MAIL_DIR}/two
299 increment_mtime ${MAIL_DIR}
301 execute_expecting new "No new mail. Removed 3 messages."
303 printf "\nTesting \"notmuch reply\" in several variations:\n"
305 printf " Basic reply...\t\t\t"
306 generate_message '[from]="Sender <sender@example.com>"' \
307 [to]=test_suite@notmuchmail.org \
308 [subject]=notmuch-reply-test \
309 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
310 '[body]="basic reply test"'
312 $NOTMUCH new > /dev/null
313 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
314 Subject: Re: notmuch-reply-test
315 To: Sender <sender@example.com>
316 Bcc: test_suite@notmuchmail.org
317 In-Reply-To: <${gen_msg_id}>
318 References: <${gen_msg_id}>
320 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
323 printf " Multiple recipients...\t\t"
324 generate_message '[from]="Sender <sender@example.com>"' \
325 '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
326 [subject]=notmuch-reply-test \
327 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
328 '[body]="Multiple recipients"'
330 $NOTMUCH new > /dev/null
331 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
332 Subject: Re: notmuch-reply-test
333 To: Sender <sender@example.com>, Someone Else <someone@example.com>
334 Bcc: test_suite@notmuchmail.org
335 In-Reply-To: <${gen_msg_id}>
336 References: <${gen_msg_id}>
338 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
339 > Multiple recipients"
341 printf " Reply with CC...\t\t"
342 generate_message '[from]="Sender <sender@example.com>"' \
343 [to]=test_suite@notmuchmail.org \
344 '[cc]="Other Parties <cc@example.com>"' \
345 [subject]=notmuch-reply-test \
346 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
347 '[body]="reply with CC"'
349 $NOTMUCH new > /dev/null
350 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
351 Subject: Re: notmuch-reply-test
352 To: Sender <sender@example.com>
353 Cc: Other Parties <cc@example.com>
354 Bcc: test_suite@notmuchmail.org
355 In-Reply-To: <${gen_msg_id}>
356 References: <${gen_msg_id}>
358 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
361 printf " Reply from alternate address..."
362 generate_message '[from]="Sender <sender@example.com>"' \
363 [to]=test_suite_other@notmuchmail.org \
364 [subject]=notmuch-reply-test \
365 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
366 '[body]="reply from alternate address"'
368 $NOTMUCH new > /dev/null
369 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
370 Subject: Re: notmuch-reply-test
371 To: Sender <sender@example.com>
372 Bcc: test_suite@notmuchmail.org
373 In-Reply-To: <${gen_msg_id}>
374 References: <${gen_msg_id}>
376 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
377 > reply from alternate address"
379 printf " Support for Reply-To...\t"
380 generate_message '[from]="Sender <sender@example.com>"' \
381 [to]=test_suite@notmuchmail.org \
382 [subject]=notmuch-reply-test \
383 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
384 '[body]="support for reply-to"' \
385 '[reply-to]="Sender <elsewhere@example.com>"'
387 $NOTMUCH new > /dev/null
388 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
389 Subject: Re: notmuch-reply-test
390 To: Sender <elsewhere@example.com>
391 Bcc: test_suite@notmuchmail.org
392 In-Reply-To: <${gen_msg_id}>
393 References: <${gen_msg_id}>
395 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
396 > support for reply-to"
398 printf " Un-munging Reply-To...\t\t"
399 generate_message '[from]="Sender <sender@example.com>"' \
400 '[to]="Some List <list@example.com>"' \
401 [subject]=notmuch-reply-test \
402 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
403 '[body]="Un-munging Reply-To"' \
404 '[reply-to]="Evil Munging List <list@example.com>"'
406 $NOTMUCH new > /dev/null
407 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
408 Subject: Re: notmuch-reply-test
409 To: Sender <sender@example.com>, Some List <list@example.com>
410 Bcc: test_suite@notmuchmail.org
411 In-Reply-To: <${gen_msg_id}>
412 References: <${gen_msg_id}>
414 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
415 > Un-munging Reply-To"
418 Notmuch test suite complete.
420 Intermediate state can be examined in: