notmuch.el: controlling what does and doesn't get expanded in searches
[notmuch-archives.git] / 74 / 0ad226ebb286eb587131b3d9fbccd31d1a1763
1 Return-Path: <sojkam1@fel.cvut.cz>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id CF11A40D145\r
6         for <notmuch@notmuchmail.org>; Wed, 13 Oct 2010 05:14:40 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9] autolearn=ham\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id M52nZbZCb4xG for <notmuch@notmuchmail.org>;\r
16         Wed, 13 Oct 2010 05:14:25 -0700 (PDT)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id 4B57640D146\r
19         for <notmuch@notmuchmail.org>; Wed, 13 Oct 2010 05:14:13 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.4])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id 2199E19F33E5;\r
22         Wed, 13 Oct 2010 14:14:12 +0200 (CEST)\r
23 X-Virus-Scanned: IMAP AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,\r
26         port 10044)\r
27         with ESMTP id nktoBPHYVgZj; Wed, 13 Oct 2010 14:14:10 +0200 (CEST)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id 0E8CA19F33E0;\r
30         Wed, 13 Oct 2010 14:14:10 +0200 (CEST)\r
31 Received: from steelpick.2x.cz (note-sojka.felk.cvut.cz [147.32.86.30])\r
32         (Authenticated sender: sojkam1)\r
33         by imap.feld.cvut.cz (Postfix) with ESMTPSA id 08CA115C082;\r
34         Wed, 13 Oct 2010 14:14:10 +0200 (CEST)\r
35 Received: from wsh by steelpick.2x.cz with local (Exim 4.72)\r
36         (envelope-from <sojkam1@fel.cvut.cz>)\r
37         id 1P60Dh-0005VS-N9; Wed, 13 Oct 2010 14:14:09 +0200\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 4/4] Tests for maildir synchronization\r
41 Date: Wed, 13 Oct 2010 14:13:58 +0200\r
42 Message-Id: <1286972038-21064-5-git-send-email-sojkam1@fel.cvut.cz>\r
43 X-Mailer: git-send-email 1.7.1.3.g75e44\r
44 In-Reply-To: <1286972038-21064-1-git-send-email-sojkam1@fel.cvut.cz>\r
45 References: <1286972038-21064-1-git-send-email-sojkam1@fel.cvut.cz>\r
46 X-BeenThere: notmuch@notmuchmail.org\r
47 X-Mailman-Version: 2.1.13\r
48 Precedence: list\r
49 List-Id: "Use and development of the notmuch mail system."\r
50         <notmuch.notmuchmail.org>\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
54 List-Post: <mailto:notmuch@notmuchmail.org>\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
58 X-List-Received-Date: Wed, 13 Oct 2010 12:14:41 -0000\r
59 \r
60 Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\r
61 ---\r
62  test/maildir-sync |  216 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
63  test/notmuch-test |    2 +-\r
64  test/test-lib.sh  |   14 +++-\r
65  3 files changed, 229 insertions(+), 3 deletions(-)\r
66  create mode 100755 test/maildir-sync\r
67 \r
68 diff --git a/test/maildir-sync b/test/maildir-sync\r
69 new file mode 100755\r
70 index 0000000..a5f8c36\r
71 --- /dev/null\r
72 +++ b/test/maildir-sync\r
73 @@ -0,0 +1,216 @@\r
74 +#!/bin/bash\r
75 +\r
76 +test_description="Test maildir synchronization"\r
77 +\r
78 +. ./test-lib.sh\r
79 +\r
80 +filter_show() {\r
81 +    sed -e 's/, /,\n/g'|sed -e "s|${MAIL_DIR}/||" -e '/^"tags"/d'\r
82 +    echo\r
83 +}\r
84 +\r
85 +cat >> "$NOTMUCH_CONFIG" <<EOF\r
86 +[maildir]\r
87 +sync_level=4\r
88 +EOF\r
89 +\r
90 +test_begin_subtest "No new messages"\r
91 +output=$(NOTMUCH_NEW)\r
92 +test_expect_equal "$output" "No new mail."\r
93 +\r
94 +cat > expected <<EOF\r
95 +Added 1 new message to the database.\r
96 +EOF\r
97 +test_expect_success "Add a message, no flags" '\r
98 +generate_message [subject]="\"test message\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [filename]="\"msg-001:2,\"" &&\r
99 +NOTMUCH_NEW > actual &&\r
100 +test_cmp expected actual\r
101 +#emacs --eval "(gdb \"gdb --annotate=3 --args $(which notmuch) new\")"\r
102 +'\r
103 +cat > expected <<EOF\r
104 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox unread)\r
105 +EOF\r
106 +test_expect_success 'Search for the message' '\r
107 +notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
108 +test_cmp expected actual\r
109 +'\r
110 +cat > expected <<EOF\r
111 +No new mail. Detected 1 file rename.\r
112 +EOF\r
113 +test_expect_success 'Add seen flag' '\r
114 +mv "${gen_msg_filename}" "${gen_msg_filename}S" &&\r
115 +increment_mtime "$(dirname "${gen_msg_filename}")" &&\r
116 +NOTMUCH_NEW > actual &&\r
117 +test_cmp expected actual\r
118 +'\r
119 +cat > expected <<EOF\r
120 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)\r
121 +EOF\r
122 +test_expect_success 'Check that tags were updated' '\r
123 +notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize > actual &&\r
124 +test_cmp expected actual\r
125 +'\r
126 +cat > expected <<EOF\r
127 +Added 1 new message to the database.\r
128 +EOF\r
129 +test_expect_success "Add a seen message" '\r
130 +generate_message [subject]="\"test message 2\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [filename]="\"msg-002:2,S\"" &&\r
131 +NOTMUCH_NEW > actual &&\r
132 +test_cmp expected actual\r
133 +'\r
134 +cat > expected <<EOF\r
135 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message (inbox)\r
136 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 2 (inbox)\r
137 +EOF\r
138 +test_expect_success 'Check that the seen message is not tagged unread' '\r
139 +notmuch search tag:inbox and not tag:unread | notmuch_search_sanitize > actual &&\r
140 +test_cmp expected actual\r
141 +'\r
142 +test_expect_success 'Tag the seen messages as replied' '\r
143 +notmuch tag +replied -inbox tag:inbox and not tag:unread\r
144 +'\r
145 +\r
146 +cat > expected <<EOF\r
147 +msg-001:2,RS\r
148 +msg-002:2,RS\r
149 +EOF\r
150 +test_expect_success 'Check that R flag was added' '\r
151 +ls -1 "${MAIL_DIR}" > actual &&\r
152 +test_cmp expected actual\r
153 +'\r
154 +cat <<EOF > show-expected\r
155 +[[[{"id": "msg-001@notmuch-test-suite",\r
156 +"match": true,\r
157 +"filename": "msg-001:2,RS",\r
158 +"timestamp": 946728000,\r
159 +"date_relative": "2000-01-01",\r
160 +"headers": {"Subject": "test message",\r
161 +"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
162 +"To": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
163 +"Cc": "",\r
164 +"Bcc": "",\r
165 +"Date": "Sat,\r
166 +01 Jan 2000 12:00:00 -0000"},\r
167 +"body": [{"id": 1,\r
168 +"content-type": "text/plain",\r
169 +"content": "This is just a test message (#1)\n"}]},\r
170 +[]]]]\r
171 +EOF\r
172 +\r
173 +test_expect_success 'Renamed message can be shown without running notmuch new' '\r
174 +notmuch show --format=json id:msg-001@notmuch-test-suite | filter_show > show-actual &&\r
175 +test_cmp show-expected show-actual\r
176 +'\r
177 +\r
178 +test_expect_success 'Test that we can reply to the renamed message' '\r
179 +notmuch reply id:msg-001@notmuch-test-suite\r
180 +'\r
181 +\r
182 +echo "No new mail." > expected\r
183 +test_expect_success 'No rename should be detected by notmuch new' '\r
184 +increment_mtime "$(dirname "${gen_msg_filename}")" &&\r
185 +notmuch new > actual &&\r
186 +test_cmp expected actual\r
187 +'\r
188 +test_expect_success "Add a message to new/ without info" '\r
189 +generate_message [subject]="\"test message 3\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [dir]=new &&\r
190 +NOTMUCH_NEW > actual &&\r
191 +test_cmp - actual <<EOF\r
192 +Added 1 new message to the database.\r
193 +EOF\r
194 +'\r
195 +test_expect_success "Check that the message has inbox and unread tags" '\r
196 +notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
197 +test_cmp - actual <<EOF\r
198 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox unread)\r
199 +EOF\r
200 +'\r
201 +test_expect_success "Tag the message with 'tmp' tag" '\r
202 +notmuch tag +tmp tag:inbox and tag:unread'\r
203 +\r
204 +test_expect_success "Check that the message was not moved from new/ to cur/" '\r
205 +echo filename:$gen_msg_filename > expected &&\r
206 +notmuch show id:$gen_msg_id|grep -o "filename:.*$" > actual &&\r
207 +test_cmp expected actual &&\r
208 +test -f "$gen_msg_filename"\r
209 +'\r
210 +test_expect_success "Check that the message was not renamed" '\r
211 +ls "${MAIL_DIR}/new" > actual &&\r
212 +test_cmp - actual <<EOF\r
213 +msg-003\r
214 +EOF\r
215 +'\r
216 +test_expect_success 'Removing of unread tag should fail without cur/' '\r
217 +test_must_fail notmuch tag -unread tag:inbox and tag:unread\r
218 +'\r
219 +test_expect_success "Check that the tags were not changed" '\r
220 +notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
221 +test_cmp - actual <<EOF\r
222 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox tmp unread)\r
223 +EOF\r
224 +'\r
225 +\r
226 +# notmuch new is not necessary here, but we run it in order to check\r
227 +# for 'no rename' later (*).\r
228 +test_expect_success 'Create cur/ and let notmuch know about it' '\r
229 +mkdir "$MAIL_DIR/cur" &&\r
230 +notmuch new\r
231 +'\r
232 +test_expect_success 'Removing of unread tag should pass with cur/' '\r
233 +notmuch tag -unread tag:inbox and tag:unread\r
234 +'\r
235 +test_expect_success 'Check that the message was moved to cur/' '\\r
236 +ls "$MAIL_DIR/cur" > actual &&\r
237 +test_cmp - actual <<EOF\r
238 +msg-003:2,S\r
239 +EOF\r
240 +'\r
241 +test_expect_success 'No rename should be detected by notmuch new' '\r
242 +increment_mtime "$MAIL_DIR/cur" &&\r
243 +notmuch new > actual &&\r
244 +test_cmp - actual <<EOF\r
245 +No new mail.\r
246 +EOF\r
247 +'\r
248 +# (*) If notmuch new was not run we've got "Processed 1 file in almost\r
249 +# no time" here. The reason is that removing unread tag in a previous\r
250 +# test created directory document in the database but this document\r
251 +# was not linked as subdirectory of $MAIL_DIR. Therefore notmuch new\r
252 +# could not reach the cur/ directory and its files in it during\r
253 +# recurive traversal.\r
254 +test_expect_success 'Remove info from file name' '\r
255 +mv "$MAIL_DIR/cur/msg-003:2,S" "$MAIL_DIR/cur/msg-003" &&\r
256 +increment_mtime "$MAIL_DIR/cur" &&\r
257 +NOTMUCH_NEW > actual\r
258 +test_cmp - actual <<EOF\r
259 +No new mail. Detected 1 file rename.\r
260 +EOF\r
261 +'\r
262 +test_expect_success "Check that removing info did not change tags" '\r
263 +notmuch search tag:inbox | notmuch_search_sanitize > actual &&\r
264 +test_cmp - actual <<EOF\r
265 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 3 (inbox tmp)\r
266 +EOF\r
267 +'\r
268 +test_expect_success "Add a message to fakenew/ without info" '\r
269 +generate_message [subject]="\"test message 4\"" [date]="\"Sat, 01 Jan 2000 12:00:00 -0000\"" [dir]=fakenew &&\r
270 +NOTMUCH_NEW > actual &&\r
271 +test_cmp - actual <<EOF\r
272 +Added 1 new message to the database.\r
273 +EOF\r
274 +'\r
275 +test_expect_success "Check that the message has inbox and unread tags" '\r
276 +notmuch search tag:inbox and tag:unread | notmuch_search_sanitize > actual &&\r
277 +test_cmp - actual <<EOF\r
278 +thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; test message 4 (inbox unread)\r
279 +EOF\r
280 +'\r
281 +test_expect_success 'Removing of unread tag should leave the message in fakenew/' '\r
282 +notmuch tag -unread tag:inbox and tag:unread &&\r
283 +ls "$MAIL_DIR/fakenew" > actual &&\r
284 +test_cmp - actual <<EOF\r
285 +msg-004:2,S\r
286 +EOF\r
287 +'\r
288 +\r
289 +test_done\r
290 diff --git a/test/notmuch-test b/test/notmuch-test\r
291 index 13c5d80..39e0fea 100755\r
292 --- a/test/notmuch-test\r
293 +++ b/test/notmuch-test\r
294 @@ -8,7 +8,7 @@\r
295  \r
296  cd $(dirname "$0")\r
297  \r
298 -TESTS="basic new search json thread-naming reply dump-restore uuencode thread-order author-order from-guessing long-id encoding"\r
299 +TESTS="basic new search json thread-naming reply dump-restore uuencode thread-order author-order from-guessing long-id encoding maildir-sync"\r
300  \r
301  # Clean up any results from a previous run\r
302  rm -r test-results >/dev/null 2>/dev/null\r
303 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
304 index 5f7fa14..2036669 100644\r
305 --- a/test/test-lib.sh\r
306 +++ b/test/test-lib.sh\r
307 @@ -237,6 +237,12 @@ increment_mtime ()\r
308  #      Generate the message in directory 'directory/of/choice' within\r
309  #      the mail store. The directory will be created if necessary.\r
310  #\r
311 +#  [filename]=name\r
312 +#\r
313 +#      Store the message in file 'name'. The default is to store it\r
314 +#      in 'msg-<count>', where <count> is three-digit number of the\r
315 +#      message.\r
316 +#      \r
317  #  [body]=text\r
318  #\r
319  #      Text to use as the body of the email message\r
320 @@ -273,10 +279,14 @@ generate_message ()\r
321      local additional_headers\r
322  \r
323      gen_msg_cnt=$((gen_msg_cnt + 1))\r
324 -    gen_msg_name=msg-$(printf "%03d" $gen_msg_cnt)\r
325 +    if [ -z "${template[filename]}" ]; then\r
326 +       gen_msg_name="msg-$(printf "%03d" $gen_msg_cnt)"\r
327 +    else\r
328 +       gen_msg_name=${template[filename]}\r
329 +    fi\r
330  \r
331      if [ -z "${template[id]}" ]; then\r
332 -       gen_msg_id="${gen_msg_name}@notmuch-test-suite"\r
333 +       gen_msg_id="${gen_msg_name%:2,*}@notmuch-test-suite"\r
334      else\r
335         gen_msg_id="${template[id]}"\r
336      fi\r
337 -- \r
338 1.7.1.3.g75e44\r
339 \r