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