3 test_description="maildir synchronization"
7 # Much easier to examine differences if the "notmuch show
8 # --format=json" output includes some newlines. Also, need to avoid
9 # including the local value of MAIL_DIR in the result.
11 sed -e 's/, /,\n/g' | sed -e "s|${MAIL_DIR}/|MAIL_DIR/|"
15 # Create the expected maildir structure
20 test_begin_subtest "Adding 'S' flag to existing filename removes 'unread' tag"
21 add_message [subject]='"Adding S flag"' [filename]='adding-s-flag:2,' [dir]=cur
22 output=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
25 mv "${gen_msg_filename}" "${gen_msg_filename}S"
26 output+=$(NOTMUCH_NEW)
29 output+=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
30 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox unread)
31 No new mail. Detected 1 file rename.
32 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox)"
34 test_begin_subtest "Adding message with 'S' flag prevents 'unread' tag"
35 add_message [subject]='"Adding message with S"' [filename]='adding-with-s-flag:2,S' [dir]=cur
36 output=$(notmuch search subject:"Adding message with S" | notmuch_search_sanitize)
37 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Adding message with S (inbox)"
39 test_begin_subtest "Adding 'replied' tag adds 'R' flag to filename"
40 add_message [subject]='"Adding replied tag"' [filename]='adding-replied-tag:2,S' [dir]=cur
41 notmuch tag +replied subject:"Adding replied tag"
42 output=$(cd ${MAIL_DIR}/cur; ls -1 adding-replied*)
43 test_expect_equal "$output" "adding-replied-tag:2,RS"
45 test_begin_subtest "notmuch show works with renamed file (without notmuch new)"
46 output=$(notmuch show --format=json id:${gen_msg_id} | filter_show_json)
47 test_expect_equal "$output" '[[[{"id": "adding-replied-tag@notmuch-test-suite",
50 "filename": "MAIL_DIR/cur/adding-replied-tag:2,RS",
51 "timestamp": 978709437,
52 "date_relative": "2001-01-05",
53 "tags": ["inbox","replied"],
54 "headers": {"Subject": "Adding replied tag",
55 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
56 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
58 05 Jan 2001 15:43:57 +0000"},
60 "content-type": "text/plain",
61 "content": "This is just a test message (#3)\n"}]},
64 test_expect_success 'notmuch reply works with renamed file (without notmuch new)' 'notmuch reply id:${gen_msg_id}'
66 test_begin_subtest "notmuch new detects no file rename after tag->flag synchronization"
68 test_expect_equal "$output" "No new mail."
70 test_begin_subtest "When read, message moved from new to cur"
71 add_message [subject]='"Message to move to cur"' [date]='"Sat, 01 Jan 2000 12:00:00 -0000"' [filename]='message-to-move-to-cur' [dir]=new
72 notmuch tag -unread subject:"Message to move to cur"
73 output=$(cd "$MAIL_DIR/cur"; ls message-to-move*)
74 test_expect_equal "$output" "message-to-move-to-cur:2,S"
76 test_begin_subtest "No rename should be detected by notmuch new"
78 test_expect_equal "$output" "No new mail."
79 # (*) If notmuch new was not run we've got "Processed 1 file in almost
80 # no time" here. The reason is that removing unread tag in a previous
81 # test created directory document in the database but this document
82 # was not linked as subdirectory of $MAIL_DIR. Therefore notmuch new
83 # could not reach the cur/ directory and its files in it during
84 # recursive traversal.
86 # XXX: The above sounds like a bug that should be fixed. If notmuch is
87 # creating new directories in the mail store, then it should be
88 # creating all necessary database state for those directories.
90 test_begin_subtest "Removing 'S' flag from existing filename adds 'unread' tag"
91 add_message [subject]='"Removing S flag"' [filename]='removing-s-flag:2,S' [dir]=cur
92 output=$(notmuch search subject:"Removing S flag" | notmuch_search_sanitize)
95 mv "${gen_msg_filename}" "${gen_msg_filename%S}"
96 output+=$(NOTMUCH_NEW)
99 output+=$(notmuch search subject:"Removing S flag" | notmuch_search_sanitize)
100 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Removing S flag (inbox)
101 No new mail. Detected 1 file rename.
102 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Removing S flag (inbox unread)"
104 test_begin_subtest "Removing info from filename leaves tags unchanged"
105 add_message [subject]='"Message to lose maildir info"' [filename]='message-to-lose-maildir-info' [dir]=cur
106 notmuch tag -unread subject:"Message to lose maildir info"
107 mv "$MAIL_DIR/cur/message-to-lose-maildir-info:2,S" "$MAIL_DIR/cur/message-without-maildir-info"
108 output=$(NOTMUCH_NEW)
111 output+=$(notmuch search subject:"Message to lose maildir info" | notmuch_search_sanitize)
112 test_expect_equal "$output" "No new mail. Detected 1 file rename.
113 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Message to lose maildir info (inbox)"
115 add_message [subject]='"Non-maildir message"' [dir]=notmaildir [filename]='non-maildir-message'
116 expected=$(notmuch search --output=files subject:"Non-maildir message")
117 test_expect_success "Can remove unread tag from message in non-maildir directory" 'notmuch tag -unread subject:"Non-maildir message"'
119 test_begin_subtest "Message in non-maildir directory does not get renamed"
120 output=$(notmuch search --output=files subject:"Non-maildir message")
121 test_expect_equal "$output" "$expected"
123 test_begin_subtest "notmuch dump/restore re-synchronizes maildir tags with flags"
124 # Capture current filename state
125 expected=$(ls $MAIL_DIR/cur)
126 # Add/remove some flags from filenames
127 mv $MAIL_DIR/cur/adding-replied-tag:2,RS $MAIL_DIR/cur/adding-replied-tag:2,S
128 mv $MAIL_DIR/cur/adding-s-flag:2,S $MAIL_DIR/cur/adding-s-flag:2,
129 mv $MAIL_DIR/cur/adding-with-s-flag:2,S $MAIL_DIR/cur/adding-with-s-flag:2,RS
130 mv $MAIL_DIR/cur/message-to-move-to-cur:2,S $MAIL_DIR/cur/message-to-move-to-cur:2,DS
131 notmuch dump dump.txt
132 NOTMUCH_NEW >/dev/null
133 notmuch restore dump.txt
134 output=$(ls $MAIL_DIR/cur)
135 test_expect_equal "$output" "$expected"
137 test_begin_subtest 'Adding flags to duplicate message tags the mail'
138 add_message [subject]='"Duplicated message"' [dir]=cur [filename]='duplicated-message:2,'
139 cp "$MAIL_DIR/cur/duplicated-message:2," "$MAIL_DIR/cur/duplicated-message-copy:2,RS"
141 notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output
142 test_expect_equal "$(< output)" "No new mail.
143 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Duplicated message (inbox replied)"
145 test_begin_subtest "Adding duplicate message without flags does not remove tags"
146 cp "$MAIL_DIR/cur/duplicated-message-copy:2,RS" "$MAIL_DIR/cur/duplicated-message-another-copy:2,"
148 notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output
149 test_expect_equal "$(< output)" "No new mail.
150 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Duplicated message (inbox replied)"
152 test_begin_subtest "Tag changes modify flags of multiple files"
153 notmuch tag -replied subject:"Duplicated message"
154 (cd $MAIL_DIR/cur/; ls duplicated*) > actual
155 test_expect_equal "$(< actual)" "duplicated-message-another-copy:2,S
156 duplicated-message-copy:2,S
157 duplicated-message:2,S"
159 test_begin_subtest "Synchronizing tag changes preserves unsupported maildir flags"
160 add_message [subject]='"Unsupported maildir flags"' [dir]=cur [filename]='unsupported-maildir-flags:2,FSZxyz'
161 notmuch tag +unread +draft -flagged subject:"Unsupported maildir flags"
162 test_expect_equal "$(cd $MAIL_DIR/cur/; ls unsupported*)" "unsupported-maildir-flags:2,DZxyz"
164 test_begin_subtest "A file with non-compliant maildir info will not be renamed"
165 add_message [subject]='"Non-compliant maildir info"' [dir]=cur [filename]='non-compliant-maildir-info:2,These-are-not-flags-in-ASCII-order-donottouch'
166 notmuch tag +unread +draft -flagged subject:"Non-compliant maildir info"
167 test_expect_equal "$(cd $MAIL_DIR/cur/; ls non-compliant*)" "non-compliant-maildir-info:2,These-are-not-flags-in-ASCII-order-donottouch"