]> git.notmuchmail.org Git - notmuch/blob - test/maildir-sync
test: Add some missing maildir synchronization tests
[notmuch] / test / maildir-sync
1 #!/usr/bin/env bash
2
3 test_description="maildir synchronization"
4
5 . ./test-lib.sh
6
7 # Avoid including the local value of MAIL_DIR in the result.
8 filter_show_json() {
9     sed -e "s|${MAIL_DIR}/|MAIL_DIR/|"
10 }
11
12 # Create the expected maildir structure
13 mkdir $MAIL_DIR/cur
14 mkdir $MAIL_DIR/new
15 mkdir $MAIL_DIR/tmp
16
17 test_begin_subtest "Adding 'S' flag to existing filename removes 'unread' tag"
18 add_message [subject]='"Adding S flag"' [filename]='adding-s-flag:2,' [dir]=cur
19 output=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
20 output+="
21 "
22 mv "${gen_msg_filename}" "${gen_msg_filename}S"
23 output+=$(NOTMUCH_NEW)
24 output+="
25 "
26 output+=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
27 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox unread)
28 No new mail. Detected 1 file rename.
29 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox)"
30
31 test_begin_subtest "Adding message with 'S' flag prevents 'unread' tag"
32 add_message [subject]='"Adding message with S"' [filename]='adding-with-s-flag:2,S' [dir]=cur
33 output=$(notmuch search subject:"Adding message with S" | notmuch_search_sanitize)
34 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding message with S (inbox)"
35
36 test_begin_subtest "Adding 'replied' tag adds 'R' flag to filename"
37 add_message [subject]='"Adding replied tag"' [filename]='adding-replied-tag:2,S' [dir]=cur
38 notmuch tag +replied subject:"Adding replied tag"
39 output=$(cd ${MAIL_DIR}/cur; ls -1 adding-replied*)
40 test_expect_equal "$output" "adding-replied-tag:2,RS"
41
42 test_begin_subtest "notmuch show works with renamed file (without notmuch new)"
43 output=$(notmuch show --format=json id:${gen_msg_id} | filter_show_json)
44 test_expect_equal_json "$output" '[[[{"id": "adding-replied-tag@notmuch-test-suite",
45 "match": true,
46 "excluded": false,
47 "filename": "MAIL_DIR/cur/adding-replied-tag:2,RS",
48 "timestamp": 978709437,
49 "date_relative": "2001-01-05",
50 "tags": ["inbox","replied"],
51 "headers": {"Subject": "Adding replied tag",
52 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
53 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
54 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
55 "body": [{"id": 1,
56 "content-type": "text/plain",
57 "content": "This is just a test message (#3)\n"}]},
58 []]]]'
59
60 test_expect_success 'notmuch reply works with renamed file (without notmuch new)' 'notmuch reply id:${gen_msg_id}'
61
62 test_begin_subtest "notmuch new detects no file rename after tag->flag synchronization"
63 output=$(NOTMUCH_NEW)
64 test_expect_equal "$output" "No new mail."
65
66 test_begin_subtest "When read, message moved from new to cur"
67 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
68 notmuch tag -unread subject:"Message to move to cur"
69 output=$(cd "$MAIL_DIR/cur"; ls message-to-move*)
70 test_expect_equal "$output" "message-to-move-to-cur:2,S"
71
72 test_begin_subtest "No rename should be detected by notmuch new"
73 output=$(NOTMUCH_NEW)
74 test_expect_equal "$output" "No new mail."
75 # (*) If notmuch new was not run we've got "Processed 1 file in almost
76 # no time" here. The reason is that removing unread tag in a previous
77 # test created directory document in the database but this document
78 # was not linked as subdirectory of $MAIL_DIR. Therefore notmuch new
79 # could not reach the cur/ directory and its files in it during
80 # recursive traversal.
81 #
82 # XXX: The above sounds like a bug that should be fixed. If notmuch is
83 # creating new directories in the mail store, then it should be
84 # creating all necessary database state for those directories.
85
86 test_begin_subtest "Adding non-maildir tags does not move message from new to cur"
87 test_subtest_known_broken
88 add_message [subject]='"Message to stay in new"' \
89     [date]='"Sat, 01 Jan 2000 12:00:00 -0000"' \
90     [filename]='message-to-stay-in-new' [dir]=new
91 notmuch tag +donotmove subject:"Message to stay in new"
92 output=$(cd "$MAIL_DIR"; ls */message-to-stay-in-new*)
93 test_expect_equal "$output" "new/message-to-stay-in-new"
94
95 test_begin_subtest "Message in cur lacking maildir info gets one on any tag change"
96 add_message [filename]='message-to-get-maildir-info' [dir]=cur
97 notmuch tag +anytag id:$gen_msg_id
98 output=$(cd "$MAIL_DIR"; ls */message-to-get-maildir-info*)
99 test_expect_equal "$output" "cur/message-to-get-maildir-info:2,"
100
101 test_begin_subtest "Message in new with maildir info is moved to cur on any tag change"
102 add_message [filename]='message-with-info-to-be-moved-to-cur:2,' [dir]=new
103 notmuch tag +anytag id:$gen_msg_id
104 output=$(cd "$MAIL_DIR"; ls */message-with-info-to-be-moved-to-cur*)
105 test_expect_equal "$output" "cur/message-with-info-to-be-moved-to-cur:2,"
106
107 test_begin_subtest "Removing 'S' flag from existing filename adds 'unread' tag"
108 add_message [subject]='"Removing S flag"' [filename]='removing-s-flag:2,S' [dir]=cur
109 output=$(notmuch search subject:"Removing S flag" | notmuch_search_sanitize)
110 output+="
111 "
112 mv "${gen_msg_filename}" "${gen_msg_filename%S}"
113 output+=$(NOTMUCH_NEW)
114 output+="
115 "
116 output+=$(notmuch search subject:"Removing S flag" | notmuch_search_sanitize)
117 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Removing S flag (inbox)
118 No new mail. Detected 1 file rename.
119 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Removing S flag (inbox unread)"
120
121 test_begin_subtest "Removing info from filename leaves tags unchanged"
122 add_message [subject]='"Message to lose maildir info"' [filename]='message-to-lose-maildir-info' [dir]=cur
123 notmuch tag -unread subject:"Message to lose maildir info"
124 mv "$MAIL_DIR/cur/message-to-lose-maildir-info:2,S" "$MAIL_DIR/cur/message-without-maildir-info"
125 output=$(NOTMUCH_NEW)
126 output+="
127 "
128 output+=$(notmuch search subject:"Message to lose maildir info" | notmuch_search_sanitize)
129 test_expect_equal "$output" "No new mail. Detected 1 file rename.
130 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Message to lose maildir info (inbox)"
131
132 add_message [subject]='"Non-maildir message"' [dir]=notmaildir [filename]='non-maildir-message'
133 expected=$(notmuch search --output=files subject:"Non-maildir message")
134 test_expect_success "Can remove unread tag from message in non-maildir directory" 'notmuch tag -unread subject:"Non-maildir message"'
135
136 test_begin_subtest "Message in non-maildir directory does not get renamed"
137 output=$(notmuch search --output=files subject:"Non-maildir message")
138 test_expect_equal "$output" "$expected"
139
140 test_begin_subtest "notmuch dump/restore re-synchronizes maildir tags with flags"
141 # Capture current filename state
142 expected=$(ls $MAIL_DIR/cur)
143 # Add/remove some flags from filenames
144 mv $MAIL_DIR/cur/adding-replied-tag:2,RS $MAIL_DIR/cur/adding-replied-tag:2,S
145 mv $MAIL_DIR/cur/adding-s-flag:2,S $MAIL_DIR/cur/adding-s-flag:2,
146 mv $MAIL_DIR/cur/adding-with-s-flag:2,S $MAIL_DIR/cur/adding-with-s-flag:2,RS
147 mv $MAIL_DIR/cur/message-to-move-to-cur:2,S $MAIL_DIR/cur/message-to-move-to-cur:2,DS
148 notmuch dump --output=dump.txt
149 NOTMUCH_NEW >/dev/null
150 notmuch restore --input=dump.txt
151 output=$(ls $MAIL_DIR/cur)
152 test_expect_equal "$output" "$expected"
153
154 test_begin_subtest 'Adding flags to duplicate message tags the mail'
155 add_message [subject]='"Duplicated message"' [dir]=cur [filename]='duplicated-message:2,'
156 cp "$MAIL_DIR/cur/duplicated-message:2," "$MAIL_DIR/cur/duplicated-message-copy:2,RS"
157 NOTMUCH_NEW > output
158 notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output
159 test_expect_equal "$(< output)" "No new mail.
160 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Duplicated message (inbox replied)"
161
162 test_begin_subtest "Adding duplicate message without flags does not remove tags"
163 cp "$MAIL_DIR/cur/duplicated-message-copy:2,RS" "$MAIL_DIR/cur/duplicated-message-another-copy:2,"
164 NOTMUCH_NEW > output
165 notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output
166 test_expect_equal "$(< output)" "No new mail.
167 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Duplicated message (inbox replied)"
168
169 test_begin_subtest "Tag changes modify flags of multiple files"
170 notmuch tag -replied subject:"Duplicated message"
171 (cd $MAIL_DIR/cur/; ls duplicated*) > actual
172 test_expect_equal "$(< actual)"  "duplicated-message-another-copy:2,S
173 duplicated-message-copy:2,S
174 duplicated-message:2,S"
175
176 test_begin_subtest "Synchronizing tag changes preserves unsupported maildir flags"
177 add_message [subject]='"Unsupported maildir flags"' [dir]=cur [filename]='unsupported-maildir-flags:2,FSZxyz'
178 notmuch tag +unread +draft -flagged subject:"Unsupported maildir flags"
179 test_expect_equal "$(cd $MAIL_DIR/cur/; ls unsupported*)" "unsupported-maildir-flags:2,DZxyz"
180
181 test_begin_subtest "A file with non-compliant maildir info will not be renamed"
182 add_message [subject]='"Non-compliant maildir info"' [dir]=cur [filename]='non-compliant-maildir-info:2,These-are-not-flags-in-ASCII-order-donottouch'
183 notmuch tag +unread +draft -flagged subject:"Non-compliant maildir info"
184 test_expect_equal "$(cd $MAIL_DIR/cur/; ls non-compliant*)" "non-compliant-maildir-info:2,These-are-not-flags-in-ASCII-order-donottouch"
185
186 test_begin_subtest "Files in new/ get default synchronized tags"
187 OLDCONFIG=$(notmuch config get new.tags)
188 notmuch config set new.tags test
189 add_message [subject]='"File in new/"' [dir]=new [filename]='file-in-new'
190 notmuch config set new.tags $OLDCONFIG
191 notmuch search 'subject:"File in new"' | notmuch_search_sanitize > output
192 test_expect_equal "$(< output)" \
193 "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; File in new/ (test unread)"
194
195 test_done