3 test_description="Test maildir synchronization"
8 sed -e 's/, /,\n/g'|sed -e "s|${MAIL_DIR}/||" -e '/^"tags"/d'
12 cat >> "$NOTMUCH_CONFIG" <<EOF
14 synchronize_flags=true
17 test_begin_subtest "No new messages"
19 test_expect_equal "$output" "No new mail."
22 Added 1 new message to the database.
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\")"
31 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test message (inbox unread)
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
38 No new mail. Detected 1 file rename.
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
47 thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)
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
54 Added 1 new message to the database.
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
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)
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
69 test_expect_success 'Tag the seen messages as replied' '
70 notmuch tag +replied -inbox tag:inbox and not tag:unread
77 test_expect_success 'Check that R flag was added' '
78 ls -1 "${MAIL_DIR}" > actual &&
79 test_cmp expected actual
81 cat <<EOF > show-expected
82 [[[{"id": "msg-001@notmuch-test-suite",
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>",
93 01 Jan 2000 12:00:00 -0000"},
95 "content-type": "text/plain",
96 "content": "This is just a test message (#1)\n"}]},
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
105 test_expect_success 'Test that we can reply to the renamed message' '
106 notmuch reply id:msg-001@notmuch-test-suite
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
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.
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)
128 test_expect_success "Tag the message with 'tmp' tag" '
129 notmuch tag +tmp tag:inbox and tag:unread'
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"
137 test_expect_success "Check that the message was not renamed" '
138 ls "${MAIL_DIR}/new" > actual &&
139 test_cmp - actual <<EOF
143 test_expect_success 'Removing of unread tag should fail without cur/' '
144 test_must_fail notmuch tag -unread tag:inbox and tag:unread
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)
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" &&
159 test_expect_success 'Removing of unread tag should pass with cur/' '
160 notmuch tag -unread tag:inbox and tag:unread
162 test_expect_success 'Check that the message was moved to cur/' '\
163 ls "$MAIL_DIR/cur" > actual &&
164 test_cmp - actual <<EOF
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
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" &&
185 test_cmp - actual <<EOF
186 No new mail. Detected 1 file rename.
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)
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.
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)
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
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
223 test_expect_success 'Test whether dump/new/restore synchronizes the maildir flags with the database' '
224 notmuch dump dump.txt &&
226 notmuch restore dump.txt &&
227 ls $MAIL_DIR > actual &&
228 test_cmp expected actual