2 test_description='"notmuch new" in several variations'
3 . $(dirname "$0")/test-lib.sh || exit 1
5 test_begin_subtest "No new messages"
6 output=$(NOTMUCH_NEW --debug)
7 test_expect_equal "$output" "No new mail."
10 test_begin_subtest "Single new message"
12 output=$(NOTMUCH_NEW --debug)
13 test_expect_equal "$output" "Added 1 new message to the database."
15 test_begin_subtest "Single message (full-scan)"
17 output=$(NOTMUCH_NEW --debug --full-scan 2>&1)
18 test_expect_equal "$output" "Added 1 new message to the database."
20 test_begin_subtest "Multiple new messages"
23 output=$(NOTMUCH_NEW --debug)
24 test_expect_equal "$output" "Added 2 new messages to the database."
26 test_begin_subtest "Multiple new messages (full-scan)"
29 output=$(NOTMUCH_NEW --debug --full-scan 2>&1)
30 test_expect_equal "$output" "Added 2 new messages to the database."
32 test_begin_subtest "No new messages (non-empty DB)"
33 output=$(NOTMUCH_NEW --debug)
34 test_expect_equal "$output" "No new mail."
36 test_begin_subtest "No new messages (full-scan)"
37 output=$(NOTMUCH_NEW --debug --full-scan 2>&1)
38 test_expect_equal "$output" "No new mail."
40 test_begin_subtest "New directories"
41 rm -rf "${MAIL_DIR}"/* "${MAIL_DIR}"/.notmuch
42 mkdir "${MAIL_DIR}"/def
43 mkdir "${MAIL_DIR}"/ghi
44 generate_message [dir]=def
46 output=$(NOTMUCH_NEW --debug)
47 test_expect_equal "$output" "Added 1 new message to the database."
50 test_begin_subtest "Alternate inode order"
52 rm -rf "${MAIL_DIR}"/.notmuch
53 mv "${MAIL_DIR}"/ghi "${MAIL_DIR}"/abc
54 rm "${MAIL_DIR}"/def/*
55 generate_message [dir]=abc
57 output=$(NOTMUCH_NEW --debug)
58 test_expect_equal "$output" "Added 1 new message to the database."
61 test_begin_subtest "Message moved in"
62 rm -rf "${MAIL_DIR}"/* "${MAIL_DIR}"/.notmuch
64 tmp_msg_filename=tmp/"$gen_msg_filename"
65 mkdir -p "$(dirname "$tmp_msg_filename")"
66 mv "$gen_msg_filename" "$tmp_msg_filename"
67 notmuch new > /dev/null
68 mv "$tmp_msg_filename" "$gen_msg_filename"
69 output=$(NOTMUCH_NEW --debug)
70 test_expect_equal "$output" "Added 1 new message to the database."
73 test_begin_subtest "Renamed message"
76 notmuch new > /dev/null
77 mv "$gen_msg_filename" "${gen_msg_filename}"-renamed
78 output=$(NOTMUCH_NEW --debug)
79 test_expect_equal "$output" "(D) add_files, pass 2: queuing passed file ${gen_msg_filename} for deletion from database
80 No new mail. Detected 1 file rename."
83 test_begin_subtest "Deleted message"
85 rm "${gen_msg_filename}"-renamed
86 output=$(NOTMUCH_NEW --debug)
87 test_expect_equal "$output" "(D) add_files, pass 3: queuing leftover file ${gen_msg_filename}-renamed for deletion from database
88 No new mail. Removed 1 message."
92 test_begin_subtest "Renamed directory"
94 generate_message [dir]=dir
95 generate_message [dir]=dir
96 generate_message [dir]=dir
98 notmuch new > /dev/null
100 mv "${MAIL_DIR}"/dir "${MAIL_DIR}"/dir-renamed
102 output=$(NOTMUCH_NEW --debug --full-scan)
103 test_expect_equal "$output" "(D) add_files, pass 2: queuing passed directory ${MAIL_DIR}/dir for deletion from database
104 No new mail. Detected 3 file renames."
107 test_begin_subtest "Deleted directory"
108 rm -rf "${MAIL_DIR}"/dir-renamed
110 output=$(NOTMUCH_NEW --debug --full-scan)
111 test_expect_equal "$output" "(D) add_files, pass 2: queuing passed directory ${MAIL_DIR}/dir-renamed for deletion from database
112 No new mail. Removed 3 messages."
115 test_begin_subtest "New directory (at end of list)"
117 generate_message [dir]=zzz
118 generate_message [dir]=zzz
119 generate_message [dir]=zzz
121 output=$(NOTMUCH_NEW --debug)
122 test_expect_equal "$output" "Added 3 new messages to the database."
125 test_begin_subtest "Deleted directory (end of list)"
127 rm -rf "${MAIL_DIR}"/zzz
129 output=$(NOTMUCH_NEW --debug --full-scan)
130 test_expect_equal "$output" "(D) add_files, pass 3: queuing leftover directory ${MAIL_DIR}/zzz for deletion from database
131 No new mail. Removed 3 messages."
134 test_begin_subtest "New symlink to directory"
136 rm -rf "${MAIL_DIR}"/.notmuch
137 mv "${MAIL_DIR}" "${TMP_DIRECTORY}"/actual_maildir
140 ln -s "${TMP_DIRECTORY}"/actual_maildir "${MAIL_DIR}"/symlink
142 output=$(NOTMUCH_NEW --debug)
143 test_expect_equal "$output" "Added 1 new message to the database."
146 test_begin_subtest "New symlink to a file"
148 external_msg_filename="${TMP_DIRECTORY}"/external/"$(basename "$gen_msg_filename")"
149 mkdir -p "$(dirname "$external_msg_filename")"
150 mv "$gen_msg_filename" "$external_msg_filename"
151 ln -s "$external_msg_filename" "$gen_msg_filename"
152 output=$(NOTMUCH_NEW --debug)
153 test_expect_equal "$output" "Added 1 new message to the database."
156 test_begin_subtest "Broken symlink aborts"
157 ln -s does-not-exist "${MAIL_DIR}/broken"
158 output=$(NOTMUCH_NEW --debug 2>&1)
159 test_expect_equal "$output" \
160 "Error reading file ${MAIL_DIR}/broken: No such file or directory
161 Note: A fatal error was encountered: Something went wrong trying to read or write a file
163 rm "${MAIL_DIR}/broken"
166 test_begin_subtest "New two-level directory"
168 generate_message [dir]=two/levels
169 generate_message [dir]=two/levels
170 generate_message [dir]=two/levels
172 output=$(NOTMUCH_NEW --debug)
173 test_expect_equal "$output" "Added 3 new messages to the database."
176 test_begin_subtest "Deleted two-level directory"
178 rm -rf "${MAIL_DIR}"/two
180 output=$(NOTMUCH_NEW --debug --full-scan)
181 test_expect_equal "$output" "(D) add_files, pass 3: queuing leftover directory ${MAIL_DIR}/two for deletion from database
182 No new mail. Removed 3 messages."
184 test_begin_subtest "One character directory at top level"
186 generate_message [dir]=A
187 generate_message [dir]=A/B
188 generate_message [dir]=A/B/C
190 output=$(NOTMUCH_NEW --debug)
191 test_expect_equal "$output" "Added 3 new messages to the database."
193 test_begin_subtest "Support single-message mbox"
194 cat > "${MAIL_DIR}"/mbox_file1 <<EOF
195 From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001
196 From: Notmuch Test Suite <test_suite@notmuchmail.org>
197 To: Notmuch Test Suite <test_suite@notmuchmail.org>
198 Subject: Test mbox message 1
202 output=$(NOTMUCH_NEW --debug 2>&1)
203 test_expect_equal "$output" "Added 1 new message to the database."
205 # This test requires that notmuch new has been run at least once.
206 test_begin_subtest "Skip and report non-mail files"
208 mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
209 touch "${MAIL_DIR}"/ignored_file
210 touch "${MAIL_DIR}"/.ignored_hidden_file
211 cat > "${MAIL_DIR}"/mbox_file <<EOF
212 From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001
213 From: Notmuch Test Suite <test_suite@notmuchmail.org>
214 To: Notmuch Test Suite <test_suite@notmuchmail.org>
215 Subject: Test mbox message 1
219 From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001
220 From: Notmuch Test Suite <test_suite@notmuchmail.org>
221 To: Notmuch Test Suite <test_suite@notmuchmail.org>
222 Subject: Test mbox message 2
226 output=$(NOTMUCH_NEW --debug --full-scan 2>&1)
227 test_expect_equal "$output" \
228 "Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config
229 Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file
230 Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
231 Note: Ignoring non-mail file: ${MAIL_DIR}/mbox_file
232 Added 1 new message to the database."
233 rm "${MAIL_DIR}"/mbox_file
235 test_begin_subtest "Ignore files and directories specified in new.ignore"
237 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
238 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
239 NOTMUCH_NEW --debug 2>&1 | sort > OUTPUT
241 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.git
242 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
243 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/ignored_file
244 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.git
245 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
246 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/ignored_file
247 Added 1 new message to the database.
249 test_expect_equal_file EXPECTED OUTPUT
251 test_begin_subtest "Ignore files and directories specified in new.ignore (full-scan)"
253 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
254 NOTMUCH_NEW --debug --full-scan 2>&1 | sort > OUTPUT
255 # reuse EXPECTED from previous test
256 test_expect_equal_file EXPECTED OUTPUT
258 test_begin_subtest "Ignore files and directories specified in new.ignore (multiple occurrences)"
259 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
260 notmuch new > /dev/null # ensure that files/folders will be printed in ASCII order.
261 mkdir -p "${MAIL_DIR}"/one/two/three/.git
262 touch "${MAIL_DIR}"/{one,one/two,one/two/three}/ignored_file
263 output=$(NOTMUCH_NEW --debug --full-scan 2>&1 | sort)
264 test_expect_equal "$output" \
265 "(D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.git
266 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
267 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/ignored_file
268 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/ignored_file
269 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
270 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
271 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
272 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.git
273 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
274 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/ignored_file
275 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/ignored_file
276 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
277 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
278 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
282 test_begin_subtest "Don't stop for ignored broken symlinks"
283 notmuch config set new.ignore .git ignored_file .ignored_hidden_file broken_link
284 ln -s i_do_not_exist "${MAIL_DIR}"/broken_link
285 output=$(NOTMUCH_NEW 2>&1)
286 test_expect_equal "$output" "No new mail."
288 test_begin_subtest "Ignore files and directories specified in new.ignore (regexp)"
289 notmuch config set new.ignore ".git" "/^bro.*ink\$/" "/ignored.*file/"
290 output=$(NOTMUCH_NEW --debug --full-scan 2>&1 | sort)
291 test_expect_equal "$output" \
292 "(D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.git
293 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
294 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/broken_link
295 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/ignored_file
296 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/ignored_file
297 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
298 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
299 (D) add_files, pass 1: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
300 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.git
301 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/.ignored_hidden_file
302 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/broken_link
303 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/ignored_file
304 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/ignored_file
305 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/ignored_file
306 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/.git
307 (D) add_files, pass 2: explicitly ignoring ${MAIL_DIR}/one/two/three/ignored_file
310 test_begin_subtest "Quiet: No new mail."
311 output=$(NOTMUCH_NEW --quiet)
312 test_expect_equal "$output" ""
314 test_begin_subtest "Quiet: new, removed and renamed messages."
318 notmuch search --format=text0 --output=files --limit=1 '*' | xargs -0 rm
320 mkdir "${MAIL_DIR}"/moved_messages
321 notmuch search --format=text0 --output=files --offset=1 --limit=1 '*' | xargs -0 -I {} mv {} "${MAIL_DIR}"/moved_messages
322 output=$(NOTMUCH_NEW --quiet)
323 test_expect_equal "$output" ""
325 OLDCONFIG=$(notmuch config get new.tags)
327 test_begin_subtest "Empty tags in new.tags are ignored"
328 notmuch config set new.tags "foo;;bar"
329 output=$(NOTMUCH_NEW --quiet 2>&1)
330 test_expect_equal "$output" ""
332 test_begin_subtest "leading/trailing whitespace in new.tags is ignored"
333 # avoid complications with leading spaces and "notmuch config"
334 sed -i 's/^tags=.*$/tags= fu bar ; ; bar /' notmuch-config
337 notmuch dump id:$gen_msg_id | sed 's/ --.*$//' > OUTPUT
339 #notmuch-dump batch-tag:3 config,properties,tags
342 test_expect_equal_file EXPECTED OUTPUT
344 test_begin_subtest "Tags starting with '-' in new.tags are forbidden"
345 notmuch config set new.tags "-foo;bar"
346 output=$(NOTMUCH_NEW --debug 2>&1)
347 test_expect_equal "$output" "Error: tag '-foo' in new.tags: tag starting with '-' forbidden"
349 test_begin_subtest "Invalid tags set exit code"
350 test_expect_code 1 "NOTMUCH_NEW --debug 2>&1"
352 notmuch config set new.tags $OLDCONFIG
354 test_begin_subtest ".notmuch only ignored at top level"
355 generate_message '[dir]=foo/bar/.notmuch/cur' '[subject]="Do not ignore, very important"'
357 notmuch search subject:Do-not-ignore | notmuch_search_sanitize >> OUTPUT
359 Added 1 new message to the database.
360 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Do not ignore, very important (inbox unread)
362 test_expect_equal_file EXPECTED OUTPUT
364 test_begin_subtest "RFC822 group names are indexed"
365 test_subtest_known_broken
366 generate_message [to]="undisclosed-recipients:"
368 output=$(notmuch search --output=messages to:undisclosed-recipients)
369 test_expect_equal "${output}" "${gen_msg_id}"
371 test_begin_subtest "Long directory names don't cause rescan"
372 test_subtest_known_broken
373 printf -v name 'z%.0s' {1..234}
374 generate_message [dir]=$name
376 notmuch new >> OUTPUT
377 rm -r ${MAIL_DIR}/${name}
378 notmuch new >> OUTPUT
380 Added 1 new message to the database.
382 No new mail. Removed 1 message.
384 test_expect_equal_file EXPECTED OUTPUT
386 test_begin_subtest "Xapian exception: read only files"
387 chmod u-w ${MAIL_DIR}/.notmuch/xapian/*.*
388 output=$(NOTMUCH_NEW --debug 2>&1 | sed 's/: .*$//' )
389 chmod u+w ${MAIL_DIR}/.notmuch/xapian/*.*
390 test_expect_equal "$output" "A Xapian exception occurred opening database"
393 make_shim dif-shim<<EOF
394 #include <notmuch-test.h>
396 WRAP_DLFUNC(notmuch_status_t, notmuch_database_index_file, \
397 (notmuch_database_t *database, const char *filename, notmuch_indexopts_t *indexopts, notmuch_message_t **message))
399 if (unlink ("${MAIL_DIR}/vanish")) {
400 fprintf (stderr, "unlink failed\n");
403 return notmuch_database_index_file_orig (database, filename, indexopts, message);
407 test_begin_subtest "Handle files vanishing between scandir and add_file"
409 # A file for scandir to find. It won't get indexed, so can be empty.
410 touch ${MAIL_DIR}/vanish
411 notmuch_with_shim dif-shim new 2>OUTPUT 1>/dev/null
412 echo "exit status: $?" >> OUTPUT
414 Unexpected error with file ${MAIL_DIR}/vanish
415 add_file: Something went wrong trying to read or write a file
416 Error opening ${MAIL_DIR}/vanish: No such file or directory
419 test_expect_equal_file EXPECTED OUTPUT
421 test_begin_subtest "Relative database path expanded in new"
422 ln -s "$PWD/mail" home/Maildir
423 notmuch config set database.path Maildir
427 Added 1 new message to the database.
429 notmuch config set database.path ${MAIL_DIR}
431 test_expect_equal_file EXPECTED OUTPUT
433 test_begin_subtest "Relative mail root (in db) expanded in new"
434 ln -s "$PWD/mail" home/Maildir
435 notmuch config set --database database.mail_root Maildir
439 Added 1 new message to the database.
441 notmuch config set database.mail_root
443 test_expect_equal_file EXPECTED OUTPUT
445 add_email_corpus broken
446 test_begin_subtest "reference loop does not crash"
447 test_expect_code 0 "notmuch show --format=json id:mid-loop-12@example.org id:mid-loop-21@example.org > OUTPUT"
449 test_begin_subtest "reference loop ordered by date"
450 threadid=$(notmuch search --output=threads id:mid-loop-12@example.org)
451 notmuch show --format=mbox $threadid | grep '^Date' > OUTPUT
453 Date: Thu, 16 Jun 2016 22:14:41 -0400
454 Date: Fri, 17 Jun 2016 22:14:41 -0400
456 test_expect_equal_file EXPECTED OUTPUT