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
168 printf "Testing \"notmuch new\" in several variations:\n"
169 printf " No new messages...\t\t"
170 execute_expecting new "No new mail."
172 printf " Single new message...\t\t"
174 execute_expecting new "Added 1 new message to the database."
176 printf " Multiple new messages...\t"
179 execute_expecting new "Added 2 new messages to the database."
181 printf " No new messages (non-empty DB)... "
182 execute_expecting new "No new mail."
184 printf " New directories...\t\t"
185 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
186 mkdir ${MAIL_DIR}/def
187 mkdir ${MAIL_DIR}/ghi
188 generate_message [dir]=def
190 execute_expecting new "Added 1 new message to the database."
192 printf " Alternate inode order...\t"
194 rm -rf ${MAIL_DIR}/.notmuch
195 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
197 generate_message [dir]=abc
199 execute_expecting new "Added 1 new message to the database."
201 printf " Message moved in...\t\t"
202 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
204 tmp_msg_filename=tmp/$gen_msg_filename
205 mkdir -p $(dirname $tmp_msg_filename)
206 mv $gen_msg_filename $tmp_msg_filename
207 increment_mtime ${MAIL_DIR}
208 $NOTMUCH new > /dev/null
209 mv $tmp_msg_filename $gen_msg_filename
210 increment_mtime ${MAIL_DIR}
211 execute_expecting new "Added 1 new message to the database."
213 printf " Renamed message...\t\t"
216 $NOTMUCH new > /dev/null
217 mv $gen_msg_filename ${gen_msg_filename}-renamed
218 increment_mtime ${MAIL_DIR}
219 execute_expecting new "No new mail. Detected 1 file rename."
221 printf " Deleted message...\t\t"
223 rm ${gen_msg_filename}-renamed
224 increment_mtime ${MAIL_DIR}
225 execute_expecting new "No new mail. Removed 1 message."
227 printf " Renamed directory...\t\t"
229 generate_message [dir]=dir
230 generate_message [dir]=dir
231 generate_message [dir]=dir
233 $NOTMUCH new > /dev/null
235 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
236 increment_mtime ${MAIL_DIR}
238 execute_expecting new "No new mail. Detected 3 file renames."
240 printf " Deleted directory...\t\t"
242 rm -rf ${MAIL_DIR}/dir-renamed
243 increment_mtime ${MAIL_DIR}
245 execute_expecting new "No new mail. Removed 3 messages."
247 printf " New directory (at end of list)... "
249 generate_message [dir]=zzz
250 generate_message [dir]=zzz
251 generate_message [dir]=zzz
253 execute_expecting new "Added 3 new messages to the database."
255 printf " Deleted directory (end of list)... "
257 rm -rf ${MAIL_DIR}/zzz
258 increment_mtime ${MAIL_DIR}
260 execute_expecting new "No new mail. Removed 3 messages."
262 printf " New symlink to directory...\t"
264 rm -rf ${MAIL_DIR}/.notmuch
265 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
268 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
270 execute_expecting new "Added 1 new message to the database."
272 printf " New symlink to a file...\t"
274 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
275 mkdir -p $(dirname $external_msg_filename)
276 mv $gen_msg_filename $external_msg_filename
277 ln -s $external_msg_filename $gen_msg_filename
278 increment_mtime ${MAIL_DIR}
279 execute_expecting new "Added 1 new message to the database."
281 printf " New two-level directory...\t"
283 generate_message [dir]=two/levels
284 generate_message [dir]=two/levels
285 generate_message [dir]=two/levels
287 execute_expecting new "Added 3 new messages to the database."
289 printf " Deleted two-level directory... "
291 rm -rf ${MAIL_DIR}/two
292 increment_mtime ${MAIL_DIR}
294 execute_expecting new "No new mail. Removed 3 messages."
296 printf "\nTesting \"notmuch reply\" in several variations:\n"
298 printf " Basic reply...\t\t\t"
299 generate_message '[from]="Sender <sender@example.com>"' \
300 [to]=test_suite@notmuchmail.org \
301 [subject]=notmuch-reply-test \
302 '[date]="Tue, 05 Jan 2010 15:43:56 -0800"' \
303 [body]=notmuch-reply-test
305 $NOTMUCH new > /dev/null
306 execute_expecting "reply id:${gen_msg_id}" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
307 Subject: Re: notmuch-reply-test
308 To: Sender <sender@example.com>
309 Bcc: test_suite@notmuchmail.org
310 In-Reply-To: <${gen_msg_id}>
311 References: <${gen_msg_id}>
313 On Tue, 05 Jan 2010 15:43:56 -0800, Sender <sender@example.com> wrote:
314 > notmuch-reply-test"
317 Notmuch test suite complete.
319 Intermediate state can be examined in: