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 # [in-reply-to]=<message-id>
63 # Additional values for email headers. If these are not provided
64 # then the relevant headers will simply not appear in the
71 # This is our (bash-specific) magic for doing named parameters
72 local -A template="($@)"
73 local additional_headers
75 gen_msg_cnt=$((gen_msg_cnt + 1))
76 gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
77 gen_msg_id="${gen_msg_name}@notmuch-test-suite"
79 if [ -z "${template[dir]}" ]; then
80 gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
82 gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
83 mkdir -p $(dirname $gen_msg_filename)
86 if [ -z "${template[body]}" ]; then
87 template[body]="This is just a test message at ${gen_msg_filename}"
90 if [ -z "${template[from]}" ]; then
91 template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
94 if [ -z "${template[to]}" ]; then
95 template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
98 if [ -z "${template[subject]}" ]; then
99 template[subject]="Test message ${gen_msg_filename}"
102 if [ -z "${template[date]}" ]; then
103 template[date]="Tue, 05 Jan 2010 15:43:57 -0800"
106 additional_headers=""
107 if [ ! -z "${template[cc]}" ]; then
108 additional_headers="Cc: ${template[cc]}
109 ${additional_headers}"
112 if [ ! -z "${template[in-reply-to]}" ]; then
113 additional_headers="In-Reply-To: ${template[in-reply-to]}
114 ${additional_headers}"
117 cat <<EOF >$gen_msg_filename
118 From: ${template[from]}
120 Message-Id: <${gen_msg_id}>
121 Subject: ${template[subject]}
122 Date: ${template[date]}
123 ${additional_headers}
127 # Ensure that the mtime of the containing directory is updated
128 increment_mtime $(dirname ${gen_msg_filename})
131 NOTMUCH_IGNORED_OUTPUT_REGEXP='^Processed [0-9]*( total)? file|Found [0-9]* total file'
138 output=$($NOTMUCH $args | grep -v -E -e "$NOTMUCH_IGNORED_OUTPUT_REGEXP")
139 if [ "$output" = "$expected" ]; then
143 echo " Expected output: $expected"
144 echo " Actual output: $output"
148 TEST_DIR=$(pwd)/test.$$
149 MAIL_DIR=${TEST_DIR}/mail
150 export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
151 NOTMUCH=$(find_notmuch_binary $(pwd))
159 cat <<EOF > ${NOTMUCH_CONFIG}
164 name=Notmuch Test Suite
165 primary_email=test_suite@notmuchmail.org
166 other_email=test_suite_other@notmuchmail.org
169 printf "Testing \"notmuch new\" in several variations:\n"
170 printf " No new messages...\t\t"
171 execute_expecting new "No new mail."
173 printf " Single new message...\t\t"
175 execute_expecting new "Added 1 new message to the database."
177 printf " Multiple new messages...\t"
180 execute_expecting new "Added 2 new messages to the database."
182 printf " No new messages (non-empty DB)... "
183 execute_expecting new "No new mail."
185 printf " New directories...\t\t"
186 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
187 mkdir ${MAIL_DIR}/def
188 mkdir ${MAIL_DIR}/ghi
189 generate_message [dir]=def
191 execute_expecting new "Added 1 new message to the database."
193 printf " Alternate inode order...\t"
195 rm -rf ${MAIL_DIR}/.notmuch
196 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
198 generate_message [dir]=abc
200 execute_expecting new "Added 1 new message to the database."
202 printf " Message moved in...\t\t"
203 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
205 tmp_msg_filename=tmp/$gen_msg_filename
206 mkdir -p $(dirname $tmp_msg_filename)
207 mv $gen_msg_filename $tmp_msg_filename
208 increment_mtime ${MAIL_DIR}
209 $NOTMUCH new > /dev/null
210 mv $tmp_msg_filename $gen_msg_filename
211 increment_mtime ${MAIL_DIR}
212 execute_expecting new "Added 1 new message to the database."
214 printf " Renamed message...\t\t"
217 $NOTMUCH new > /dev/null
218 mv $gen_msg_filename ${gen_msg_filename}-renamed
219 increment_mtime ${MAIL_DIR}
220 execute_expecting new "No new mail. Detected 1 file rename."
222 printf " Deleted message...\t\t"
224 rm ${gen_msg_filename}-renamed
225 increment_mtime ${MAIL_DIR}
226 execute_expecting new "No new mail. Removed 1 message."
228 printf " Renamed directory...\t\t"
230 generate_message [dir]=dir
231 generate_message [dir]=dir
232 generate_message [dir]=dir
234 $NOTMUCH new > /dev/null
236 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
237 increment_mtime ${MAIL_DIR}
239 execute_expecting new "No new mail. Detected 3 file renames."
241 printf " Deleted directory...\t\t"
243 rm -rf ${MAIL_DIR}/dir-renamed
244 increment_mtime ${MAIL_DIR}
246 execute_expecting new "No new mail. Removed 3 messages."
248 printf " New directory (at end of list)... "
250 generate_message [dir]=zzz
251 generate_message [dir]=zzz
252 generate_message [dir]=zzz
254 execute_expecting new "Added 3 new messages to the database."
256 printf " Deleted directory (end of list)... "
258 rm -rf ${MAIL_DIR}/zzz
259 increment_mtime ${MAIL_DIR}
261 execute_expecting new "No new mail. Removed 3 messages."
263 printf " New symlink to directory...\t"
265 rm -rf ${MAIL_DIR}/.notmuch
266 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
269 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
271 execute_expecting new "Added 1 new message to the database."
273 printf " New symlink to a file...\t"
275 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
276 mkdir -p $(dirname $external_msg_filename)
277 mv $gen_msg_filename $external_msg_filename
278 ln -s $external_msg_filename $gen_msg_filename
279 increment_mtime ${MAIL_DIR}
280 execute_expecting new "Added 1 new message to the database."
282 printf " New two-level directory...\t"
284 generate_message [dir]=two/levels
285 generate_message [dir]=two/levels
286 generate_message [dir]=two/levels
288 execute_expecting new "Added 3 new messages to the database."
290 printf " Deleted two-level directory... "
292 rm -rf ${MAIL_DIR}/two
293 increment_mtime ${MAIL_DIR}
295 execute_expecting new "No new mail. Removed 3 messages."
297 printf "\nTesting \"notmuch reply\" in several variations:\n"
299 printf " Basic reply...\t\t\t"
300 generate_message '[from]="Sender <sender@example.com>"' \
301 [to]=test_suite@notmuchmail.org \
302 [subject]=notmuch-reply-test \
303 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
304 [body]=notmuch-reply-test
306 $NOTMUCH new > /dev/null
307 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
308 Subject: Re: notmuch-reply-test
309 To: Sender <sender@example.com>
310 Bcc: test_suite@notmuchmail.org
311 In-Reply-To: <${gen_msg_id}>
312 References: <${gen_msg_id}>
314 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
315 > notmuch-reply-test"
317 printf " Reply from alternate address...\t"
318 generate_message '[from]="Sender <sender@example.com>"' \
319 [to]=test_suite_other@notmuchmail.org \
320 [subject]=notmuch-reply-test \
321 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
322 [body]=notmuch-reply-test
324 $NOTMUCH new > /dev/null
325 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
326 Subject: Re: notmuch-reply-test
327 To: Sender <sender@example.com>
328 Bcc: test_suite@notmuchmail.org
329 In-Reply-To: <${gen_msg_id}>
330 References: <${gen_msg_id}>
332 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
333 > notmuch-reply-test"
336 Notmuch test suite complete.
338 Intermediate state can be examined in: