8 while [ -n "$dir" ]; do
15 if [ "$dir" = "/" ]; then
23 # Generate a new message in the mail directory, with
24 # a unique message ID and subject.
26 # The filename of the message generated is available as
29 # This function supports named parameters with the bash syntax for
30 # assigning a value to an associative array ([name]=value). The
31 # supported parameters are:
33 # [dir]=directory/of/choice
35 # Generate the message in directory 'directory/of/choice' within
36 # the mail store. The directory will be created if necessary.
40 # Text to use as the body of the email message
42 # '[from]="Some User <user@example.com>"'
43 # '[to]="Some User <user@example.com>"'
44 # '[subject]="Subject of email message"'
46 # Values for email headers. If not provided, default values will
47 # be generated instead.
49 # '[cc]="Some User <user@example.com>"'
50 # [in-reply-to]=<message-id>
52 # Additional values for email headers. If these are not provided
53 # then the relevant headers will simply not appear in the
59 # This is our (bash-specific) magic for doing named parameters
60 local -A template="($@)"
61 local additional_headers
63 gen_msg_cnt=$((gen_msg_cnt + 1))
64 gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)
66 if [ -z "${template[dir]}" ]; then
67 gen_msg_filename="${MAIL_DIR}/$gen_msg_name"
69 gen_msg_filename="${MAIL_DIR}/${template[dir]}/$gen_msg_name"
70 mkdir -p $(dirname $gen_msg_filename)
73 if [ -z "${template[body]}" ]; then
74 template[body]="This is just a test message at ${gen_msg_filename}"
77 if [ -z "${template[from]}" ]; then
78 template[from]="Notmuch Test Suite <test_suite@notmuchmail.org>"
81 if [ -z "${template[to]}" ]; then
82 template[to]="Notmuch Test Suite <test_suite@notmuchmail.org>"
85 if [ -z "${template[subject]}" ]; then
86 template[subject]="Test message ${gen_msg_filename}"
90 if [ ! -z "${template[cc]}" ]; then
91 additional_headers="Cc: ${template[cc]}
92 ${additional_headers}"
95 if [ ! -z "${template[in-reply-to]}" ]; then
96 additional_headers="In-Reply-To: ${template[in-reply-to]}
97 ${additional_headers}"
100 cat <<EOF >$gen_msg_filename
101 From: ${template[from]}
103 Message-Id: <msg-${gen_msg_cnt}@notmuch-test-suite>
104 Subject: ${template[subject]}
105 Date: Tue, 05 Jan 2010 15:43:57 -0800
106 ${additional_headers}
116 NOTMUCH_IGNORED_OUTPUT_REGEXP='^Processed [0-9]*( total)? file|Found [0-9]* total file'
123 output=$($NOTMUCH $args | grep -v -E -e "$NOTMUCH_IGNORED_OUTPUT_REGEXP")
124 if [ "$output" = "$expected" ]; then
128 echo " Expected output: $expected"
129 echo " Actual output: $output"
133 TEST_DIR=$(pwd)/test.$$
134 MAIL_DIR=${TEST_DIR}/mail
135 export NOTMUCH_CONFIG=${TEST_DIR}/notmuch-config
136 NOTMUCH=$(find_notmuch_binary $(pwd))
144 cat <<EOF > ${NOTMUCH_CONFIG}
149 name=Notmuch Test Suite
150 primary_email=test_suite@notmuchmail.org
153 printf "Testing \"notmuch new\" in several variations:\n"
154 printf " No new messages...\t\t"
155 execute_expecting new "No new mail."
157 printf " Single new message...\t\t"
160 execute_expecting new "Added 1 new message to the database."
162 printf " Multiple new messages...\t"
166 execute_expecting new "Added 2 new messages to the database."
168 printf " No new messages (non-empty DB)... "
169 execute_expecting new "No new mail."
171 printf " New directories...\t\t"
172 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
173 mkdir ${MAIL_DIR}/def
174 mkdir ${MAIL_DIR}/ghi
175 generate_message [dir]=def
177 execute_expecting new "Added 1 new message to the database."
179 printf " Alternate inode order...\t"
181 rm -rf ${MAIL_DIR}/.notmuch
182 mv ${MAIL_DIR}/ghi ${MAIL_DIR}/abc
184 generate_message [dir]=abc
186 execute_expecting new "Added 1 new message to the database."
188 printf " Message moved in...\t\t"
189 rm -rf ${MAIL_DIR}/* ${MAIL_DIR}/.notmuch
191 tmp_msg_filename=tmp/$gen_msg_filename
192 mkdir -p $(dirname $tmp_msg_filename)
193 mv $gen_msg_filename $tmp_msg_filename
195 $NOTMUCH new > /dev/null
197 mv $tmp_msg_filename $gen_msg_filename
198 execute_expecting new "Added 1 new message to the database."
200 printf " Renamed message...\t\t"
204 $NOTMUCH new > /dev/null
206 mv $gen_msg_filename ${gen_msg_filename}-renamed
207 execute_expecting new "No new mail. Detected 1 file rename."
209 printf " Deleted message...\t\t"
212 rm ${gen_msg_filename}-renamed
213 execute_expecting new "No new mail. Removed 1 message."
215 printf " Renamed directory...\t\t"
218 generate_message [dir]=dir
219 generate_message [dir]=dir
220 generate_message [dir]=dir
222 $NOTMUCH new > /dev/null
225 mv ${MAIL_DIR}/dir ${MAIL_DIR}/dir-renamed
227 execute_expecting new "No new mail. Detected 3 file renames."
229 printf " Deleted directory...\t\t"
232 rm -rf ${MAIL_DIR}/dir-renamed
234 execute_expecting new "No new mail. Removed 3 messages."
236 printf " New directory (at end of list)... "
239 generate_message [dir]=zzz
240 generate_message [dir]=zzz
241 generate_message [dir]=zzz
243 execute_expecting new "Added 3 new messages to the database."
245 printf " Deleted directory (end of list)... "
248 rm -rf ${MAIL_DIR}/zzz
250 execute_expecting new "No new mail. Removed 3 messages."
252 printf " New symlink to directory...\t"
254 rm -rf ${MAIL_DIR}/.notmuch
255 mv ${MAIL_DIR} ${TEST_DIR}/actual_maildir
258 ln -s ${TEST_DIR}/actual_maildir ${MAIL_DIR}/symlink
260 execute_expecting new "Added 1 new message to the database."
262 printf " New symlink to a file...\t"
265 external_msg_filename=${TEST_DIR}/external/$(basename $gen_msg_filename)
266 mkdir -p $(dirname $external_msg_filename)
267 mv $gen_msg_filename $external_msg_filename
268 ln -s $external_msg_filename $gen_msg_filename
270 execute_expecting new "Added 1 new message to the database."
272 printf " New two-level directory...\t"
275 generate_message [dir]=two/levels
276 generate_message [dir]=two/levels
277 generate_message [dir]=two/levels
279 execute_expecting new "Added 3 new messages to the database."
281 printf " Deleted two-level directory... "
284 rm -rf ${MAIL_DIR}/two
286 execute_expecting new "No new mail. Removed 3 messages."
289 Notmuch test suite complete.
291 Intermediate state can be examined in: