3 test_description="maildir synchronization"
5 . $(dirname "$0")/test-lib.sh || exit 1
7 # Create the expected maildir structure
12 test_begin_subtest "Adding 'S' flag to existing filename removes 'unread' tag"
13 add_message [subject]='"Adding S flag"' [filename]='adding-s-flag:2,' [dir]=cur
14 output=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
17 mv "${gen_msg_filename}" "${gen_msg_filename}S"
18 output+=$(NOTMUCH_NEW)
21 output+=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
22 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox unread)
23 No new mail. Detected 1 file rename.
24 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox)"
26 test_begin_subtest "Adding message with 'S' flag prevents 'unread' tag"
27 add_message [subject]='"Adding message with S"' [filename]='adding-with-s-flag:2,S' [dir]=cur
28 output=$(notmuch search subject:"Adding message with S" | notmuch_search_sanitize)
29 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Adding message with S (inbox)"
31 test_begin_subtest "Adding message with 'S' w/o 'unread' in new.tags prevents 'unread' tag"
32 OLDCONFIG=$(notmuch config get new.tags)
33 notmuch config set new.tags "inbox"
34 add_message [subject]='"Adding message with S 2"' [filename]='adding-with-s-flag2:2,S' [dir]=cur
35 notmuch config set new.tags $OLDCONFIG
36 output=$(notmuch search subject:Adding-message-with-S-2 | notmuch_search_sanitize)
37 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Adding message with S 2 (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} | notmuch_json_show_sanitize)
47 test_expect_equal_json "$output" '[[[{"id": "XXXXX",
50 "filename": ["YYYYY"],
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>",
57 "Date": "GENERATED_DATE"},
59 "content-type": "text/plain",
60 "content": "This is just a test message (#4)\n"}]},
63 test_begin_subtest "notmuch reply works with renamed file (without notmuch new)"
64 test_expect_success '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 "Adding non-maildir tags does not move message from new to cur"
91 add_message [subject]='"Message to stay in new"' \
92 [date]='"Sat, 01 Jan 2000 12:00:00 -0000"' \
93 [filename]='message-to-stay-in-new' [dir]=new
94 notmuch tag +donotmove subject:"Message to stay in new"
95 output=$(cd "$MAIL_DIR"; ls */message-to-stay-in-new*)
96 test_expect_equal "$output" "new/message-to-stay-in-new"
98 test_begin_subtest "Message in cur lacking maildir info gets one on any tag change"
99 add_message [filename]='message-to-get-maildir-info' [dir]=cur
100 notmuch tag +anytag id:$gen_msg_id
101 output=$(cd "$MAIL_DIR"; ls */message-to-get-maildir-info*)
102 test_expect_equal "$output" "cur/message-to-get-maildir-info:2,"
104 test_begin_subtest "Message in new with maildir info is moved to cur on any tag change"
105 add_message [filename]='message-with-info-to-be-moved-to-cur:2,' [dir]=new
106 notmuch tag +anytag id:$gen_msg_id
107 output=$(cd "$MAIL_DIR"; ls */message-with-info-to-be-moved-to-cur*)
108 test_expect_equal "$output" "cur/message-with-info-to-be-moved-to-cur:2,"
110 test_begin_subtest "Removing 'S' flag from existing filename adds 'unread' tag"
111 add_message [subject]='"Removing S flag"' [filename]='removing-s-flag:2,S' [dir]=cur
112 output=$(notmuch search subject:"Removing S flag" | notmuch_search_sanitize)
115 mv "${gen_msg_filename}" "${gen_msg_filename%S}"
116 output+=$(NOTMUCH_NEW)
119 output+=$(notmuch search subject:"Removing S flag" | notmuch_search_sanitize)
120 test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Removing S flag (inbox)
121 No new mail. Detected 1 file rename.
122 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Removing S flag (inbox unread)"
124 test_begin_subtest "Removing info from filename leaves tags unchanged"
125 add_message [subject]='"Message to lose maildir info"' [filename]='message-to-lose-maildir-info' [dir]=cur
126 notmuch tag -unread subject:"Message to lose maildir info"
127 mv "$MAIL_DIR/cur/message-to-lose-maildir-info:2,S" "$MAIL_DIR/cur/message-without-maildir-info"
128 output=$(NOTMUCH_NEW)
131 output+=$(notmuch search subject:"Message to lose maildir info" | notmuch_search_sanitize)
132 test_expect_equal "$output" "No new mail. Detected 1 file rename.
133 thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Message to lose maildir info (inbox)"
135 test_begin_subtest "Can remove unread tag from message in non-maildir directory"
136 add_message [subject]='"Non-maildir message"' [dir]=notmaildir [filename]='non-maildir-message'
137 expected=$(notmuch search --output=files subject:"Non-maildir message")
138 test_expect_success 'notmuch tag -unread subject:"Non-maildir message"'
140 test_begin_subtest "Message in non-maildir directory does not get renamed"
141 output=$(notmuch search --output=files subject:"Non-maildir message")
142 test_expect_equal "$output" "$expected"
144 test_begin_subtest "notmuch dump/restore re-synchronizes maildir tags with flags"
145 # Capture current filename state
146 expected=$(ls $MAIL_DIR/cur)
147 # Add/remove some flags from filenames
148 mv $MAIL_DIR/cur/adding-replied-tag:2,RS $MAIL_DIR/cur/adding-replied-tag:2,S
149 mv $MAIL_DIR/cur/adding-s-flag:2,S $MAIL_DIR/cur/adding-s-flag:2,
150 mv $MAIL_DIR/cur/adding-with-s-flag:2,S $MAIL_DIR/cur/adding-with-s-flag:2,RS
151 mv $MAIL_DIR/cur/message-to-move-to-cur:2,S $MAIL_DIR/cur/message-to-move-to-cur:2,DS
152 notmuch dump --output=dump.txt
153 NOTMUCH_NEW >/dev/null
154 notmuch restore --input=dump.txt
155 output=$(ls $MAIL_DIR/cur)
156 test_expect_equal "$output" "$expected"
158 test_begin_subtest 'Adding flags to duplicate message tags the mail'
159 add_message [subject]='"Duplicated message"' [dir]=cur [filename]='duplicated-message:2,'
160 cp "$MAIL_DIR/cur/duplicated-message:2," "$MAIL_DIR/cur/duplicated-message-copy:2,RS"
162 notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output
163 test_expect_equal "$(< output)" "No new mail.
164 thread:XXX 2001-01-05 [1/1(2)] Notmuch Test Suite; Duplicated message (inbox replied)"
166 test_begin_subtest "Adding duplicate message without flags does not remove tags"
167 cp "$MAIL_DIR/cur/duplicated-message-copy:2,RS" "$MAIL_DIR/cur/duplicated-message-another-copy:2,"
169 notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output
170 test_expect_equal "$(< output)" "No new mail.
171 thread:XXX 2001-01-05 [1/1(3)] Notmuch Test Suite; Duplicated message (inbox replied)"
173 test_begin_subtest "Tag changes modify flags of multiple files"
174 notmuch tag -replied subject:"Duplicated message"
175 (cd $MAIL_DIR/cur/; ls duplicated*) > actual
176 test_expect_equal "$(< actual)" "duplicated-message-another-copy:2,S
177 duplicated-message-copy:2,S
178 duplicated-message:2,S"
180 test_begin_subtest "Synchronizing tag changes preserves unsupported maildir flags"
181 add_message [subject]='"Unsupported maildir flags"' [dir]=cur [filename]='unsupported-maildir-flags:2,FSZxyz'
182 notmuch tag +unread +draft -flagged subject:"Unsupported maildir flags"
183 test_expect_equal "$(cd $MAIL_DIR/cur/; ls unsupported*)" "unsupported-maildir-flags:2,DZxyz"
185 test_begin_subtest "A file with non-compliant maildir info will not be renamed"
186 add_message [subject]='"Non-compliant maildir info"' [dir]=cur [filename]='non-compliant-maildir-info:2,These-are-not-flags-in-ASCII-order-donottouch'
187 notmuch tag +unread +draft -flagged subject:"Non-compliant maildir info"
188 test_expect_equal "$(cd $MAIL_DIR/cur/; ls non-compliant*)" "non-compliant-maildir-info:2,These-are-not-flags-in-ASCII-order-donottouch"
190 test_begin_subtest "Files in new/ get default synchronized tags"
191 OLDCONFIG=$(notmuch config get new.tags)
192 notmuch config set new.tags "test;unread"
193 add_message [subject]='"File in new/"' [dir]=new [filename]='file-in-new'
194 notmuch config set new.tags $OLDCONFIG
195 notmuch search 'subject:"File in new"' | notmuch_search_sanitize > output
196 test_expect_equal "$(< output)" \
197 "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; File in new/ (test unread)"
199 for tag in draft flagged passed replied; do
200 test_begin_subtest "$tag is valid in new.tags"
201 OLDCONFIG=$(notmuch config get new.tags)
202 notmuch config set new.tags "$tag;unread"
203 add_message [subject]="\"$tag sync in new\"" [dir]=new
204 notmuch config set new.tags $OLDCONFIG
205 notmuch search "subject:\"$tag sync in new\"" | notmuch_search_sanitize > output
206 test_expect_equal "$(< output)" \
207 "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; $tag sync in new ($tag unread)"