]> git.notmuchmail.org Git - notmuch/blob - test/maildir-sync
Tests for maildir synchronization
[notmuch] / test / maildir-sync
1 #!/bin/bash
2
3 test_description="Test maildir synchronization"
4
5 . ./test-lib.sh
6
7 filter_show() {
8     sed -e 's/, /,\n/g'|sed -e "s|${MAIL_DIR}/||" -e '/^"tags"/d'
9     echo
10 }
11
12 cat >> "$NOTMUCH_CONFIG" <<EOF
13 [maildir]
14 synchronize_flags=true
15 EOF
16
17 test_begin_subtest "No new messages"
18 output=$(NOTMUCH_NEW)
19 test_expect_equal "$output" "No new mail."
20
21 cat > expected <<EOF
22 Added 1 new message to the database.
23 EOF
24 test_expect_success "Add a message, no flags" '
25 generate_message [subject]="\"test message\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [filename]="\"msg-001:2,\"" &&
26 NOTMUCH_NEW > actual &&
27 test_cmp expected actual
28 #emacs --eval "(gdb \"gdb --annotate=3 --args $(which notmuch) new\")"
29 '
30 cat > expected <<EOF
31 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox unread)
32 EOF
33 test_expect_success 'Search for the message' '
34 notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&
35 test_cmp expected actual
36 '
37 cat > expected <<EOF
38 No new mail. Detected 1 file rename.
39 EOF
40 test_expect_success 'Add seen flag' '
41 mv "${gen_msg_filename}" "${gen_msg_filename}S" &&
42 increment_mtime "$(dirname "${gen_msg_filename}")" &&
43 NOTMUCH_NEW > actual &&
44 test_cmp expected actual
45 '
46 cat > expected <<EOF
47 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)
48 EOF
49 test_expect_success 'Check that tags were updated' '
50 notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize > actual &&
51 test_cmp expected actual
52 '
53 cat > expected <<EOF
54 Added 1 new message to the database.
55 EOF
56 test_expect_success "Add a seen message" '
57 generate_message [subject]="\"test message 2\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [filename]="\"msg-002:2,S\"" &&
58 NOTMUCH_NEW > actual &&
59 test_cmp expected actual
60 '
61 cat > expected <<EOF
62 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)
63 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 2 (inbox)
64 EOF
65 test_expect_success 'Check that the seen message is not tagged unread' '
66 notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize > actual &&
67 test_cmp expected actual
68 '
69 test_expect_success 'Tag the seen messages as replied' '
70 notmuch tag +replied -inbox tag:inbox and not tag:unread
71 '
72
73 cat > expected <<EOF
74 msg-001:2,RS
75 msg-002:2,RS
76 EOF
77 test_expect_success 'Check that R flag was added' '
78 ls -1 "${MAIL_DIR}" > actual &&
79 test_cmp expected actual
80 '
81 cat <<EOF > show-expected
82 [[[{"id": "msg-001@notmuch-test-suite",
83 "match": true,
84 "filename": "msg-001:2,RS",
85 "timestamp": 946728000,
86 "date_relative": "2000-01-01",
87 "headers": {"Subject": "test message",
88 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
89 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
90 "Cc": "",
91 "Bcc": "",
92 "Date": "Sat,
93 01 Jan 2000 12:00:00 -0000"},
94 "body": [{"id": 1,
95 "content-type": "text/plain",
96 "content": "This is just a test message (#1)\n"}]},
97 []]]]
98 EOF
99
100 test_expect_success 'Message renamed due to changed flags can be shown without running notmuch new' '
101 notmuch show --format=json id:msg-001@notmuch-test-suite | filter_show > show-actual &&
102 test_cmp show-expected show-actual
103 '
104
105 test_expect_success 'Test that we can reply to the renamed message' '
106 notmuch reply id:msg-001@notmuch-test-suite
107 '
108
109 echo "No new mail." > expected
110 test_expect_success 'No rename should be detected by notmuch new' '
111 increment_mtime "$(dirname "${gen_msg_filename}")" &&
112 notmuch new > actual &&
113 test_cmp expected actual
114 '
115 test_expect_success "Add a message to new/ without info" '
116 generate_message [subject]="\"test message 3\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [dir]=new &&
117 NOTMUCH_NEW > actual &&
118 test_cmp - actual <<EOF
119 Added 1 new message to the database.
120 EOF
121 '
122 test_expect_success "Check that the message has inbox and unread tags" '
123 notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&
124 test_cmp - actual <<EOF
125 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox unread)
126 EOF
127 '
128 test_expect_success "Tag the message with 'tmp' tag" '
129 notmuch tag +tmp tag:inbox and tag:unread'
130
131 test_expect_success "Check that the message was not moved from new/ to cur/" '
132 echo filename:$gen_msg_filename > expected &&
133 notmuch show id:$gen_msg_id|grep -o "filename:.*$" > actual &&
134 test_cmp expected actual &&
135 test -f "$gen_msg_filename"
136 '
137 test_expect_success "Check that the message was not renamed" '
138 ls "${MAIL_DIR}/new" > actual &&
139 test_cmp - actual <<EOF
140 msg-003
141 EOF
142 '
143 test_expect_success 'Removing of unread tag should fail without cur/' '
144 test_must_fail notmuch tag -unread tag:inbox and tag:unread
145 '
146 test_expect_success "Check that the tags were not changed" '
147 notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&
148 test_cmp - actual <<EOF
149 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox tmp unread)
150 EOF
151 '
152
153 # notmuch new is not necessary here, but we run it in order to check
154 # for 'no rename' later (*).
155 test_expect_success 'Create cur/ and let notmuch know about it' '
156 mkdir "$MAIL_DIR/cur" &&
157 notmuch new
158 '
159 test_expect_success 'Removing of unread tag should pass with cur/' '
160 notmuch tag -unread tag:inbox and tag:unread
161 '
162 test_expect_success 'Check that the message was moved to cur/' '\
163 ls "$MAIL_DIR/cur" > actual &&
164 test_cmp - actual <<EOF
165 msg-003:2,S
166 EOF
167 '
168 test_expect_success 'No rename should be detected by notmuch new' '
169 increment_mtime "$MAIL_DIR/cur" &&
170 notmuch new > actual &&
171 test_cmp - actual <<EOF
172 No new mail.
173 EOF
174 '
175 # (*) If notmuch new was not run we've got "Processed 1 file in almost
176 # no time" here. The reason is that removing unread tag in a previous
177 # test created directory document in the database but this document
178 # was not linked as subdirectory of $MAIL_DIR. Therefore notmuch new
179 # could not reach the cur/ directory and its files in it during
180 # recurive traversal.
181 test_expect_success 'Remove info from file name' '
182 mv "$MAIL_DIR/cur/msg-003:2,S" "$MAIL_DIR/cur/msg-003" &&
183 increment_mtime "$MAIL_DIR/cur" &&
184 NOTMUCH_NEW > actual
185 test_cmp - actual <<EOF
186 No new mail. Detected 1 file rename.
187 EOF
188 '
189 test_expect_success "Check that removing info did not change tags" '
190 notmuch search tag:inbox | notmuch_search_sanitize > actual &&
191 test_cmp - actual <<EOF
192 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox tmp)
193 EOF
194 '
195 test_expect_success "Add a message to fakenew/ without info" '
196 generate_message [subject]="\"test message 4\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [dir]=fakenew &&
197 NOTMUCH_NEW > actual &&
198 test_cmp - actual <<EOF
199 Added 1 new message to the database.
200 EOF
201 '
202 test_expect_success "Check that the message has inbox and unread tags" '
203 notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&
204 test_cmp - actual <<EOF
205 thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 4 (inbox unread)
206 EOF
207 '
208 test_expect_success 'Removing of unread tag should leave the message in fakenew/' '
209 notmuch tag -unread tag:inbox and tag:unread &&
210 ls "$MAIL_DIR/fakenew" > actual &&
211 test_cmp - actual <<EOF
212 msg-004:2,S
213 EOF
214 '
215
216 test_expect_success 'Make maildir flags out of sync with the database' '
217 ls $MAIL_DIR > expected &&
218 mv $MAIL_DIR/msg-001:2,RS $MAIL_DIR/msg-001:2, &&
219 mv $MAIL_DIR/msg-002:2,RS $MAIL_DIR/msg-002:2, &&
220 increment_mtime $MAIL_DIR
221 '
222
223 test_expect_success 'Test whether dump/new/restore synchronizes the maildir flags with the database' '
224 notmuch dump dump.txt &&
225 notmuch new &&
226 notmuch restore dump.txt &&
227 ls $MAIL_DIR > actual &&
228 test_cmp expected actual
229 '
230
231 test_done