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