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