]> git.notmuchmail.org Git - notmuch/blob - test/emacs
emacs: Use notmuch tag --batch for large tag queries
[notmuch] / test / emacs
1 #!/usr/bin/env bash
2
3 test_description="emacs interface"
4 . ./test-lib.sh
5
6 EXPECTED=$TEST_DIRECTORY/emacs.expected-output
7
8 add_email_corpus
9
10 test_begin_subtest "Basic notmuch-hello view in emacs"
11 test_emacs '(notmuch-hello)
12             (test-output)'
13 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello
14
15 test_begin_subtest "Saved search with 0 results"
16 test_emacs '(let ((notmuch-show-empty-saved-searches t)
17                   (notmuch-saved-searches
18                    '\''(("inbox" . "tag:inbox")
19                         ("unread" . "tag:unread")
20                         ("empty" . "tag:doesnotexist"))))
21               (notmuch-hello)
22               (test-output))'
23 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-with-empty
24
25 test_begin_subtest "No saved searches displayed (all with 0 results)"
26 test_emacs '(let ((notmuch-saved-searches
27                    '\''(("empty" . "tag:doesnotexist"))))
28               (notmuch-hello)
29               (test-output))'
30 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-no-saved-searches
31
32 test_begin_subtest "Basic notmuch-search view in emacs"
33 test_emacs '(notmuch-search "tag:inbox")
34             (notmuch-test-wait)
35             (test-output)'
36 test_expect_equal_file OUTPUT $EXPECTED/notmuch-search-tag-inbox
37
38 test_begin_subtest "Incremental parsing of search results"
39 test_emacs "(ad-enable-advice 'notmuch-search-process-filter 'around 'pessimal)
40             (ad-activate 'notmuch-search-process-filter)
41             (notmuch-search \"tag:inbox\")
42             (notmuch-test-wait)
43             (ad-disable-advice 'notmuch-search-process-filter 'around 'pessimal)
44             (ad-activate 'notmuch-search-process-filter)
45             (test-output)"
46 test_expect_equal_file OUTPUT $EXPECTED/notmuch-search-tag-inbox
47
48 test_begin_subtest "Navigation of notmuch-hello to search results"
49 test_emacs '(notmuch-hello)
50             (goto-char (point-min))
51             (re-search-forward "inbox")
52             (widget-button-press (1- (point)))
53             (notmuch-test-wait)
54             (test-output)'
55 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-view-inbox
56
57 test_begin_subtest "Basic notmuch-show view in emacs"
58 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
59 test_emacs "(notmuch-show \"$maildir_storage_thread\")
60             (test-output)"
61 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
62
63 test_begin_subtest "Basic notmuch-show view in emacs default indentation"
64 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
65 test_emacs "(let ((notmuch-show-indent-messages-width 1))
66               (notmuch-show \"$maildir_storage_thread\")
67               (test-output))"
68 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
69
70 test_begin_subtest "Basic notmuch-show view in emacs without indentation"
71 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
72 test_emacs "(let ((notmuch-show-indent-messages-width 0))
73               (notmuch-show \"$maildir_storage_thread\")
74               (test-output))"
75 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage-without-indentation
76
77 test_begin_subtest "Basic notmuch-show view in emacs with fourfold indentation"
78 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
79 test_emacs "(let ((notmuch-show-indent-messages-width 4))
80               (notmuch-show \"$maildir_storage_thread\")
81               (test-output))"
82 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage-with-fourfold-indentation
83
84 test_begin_subtest "notmuch-show for message with invalid From"
85 add_message "[subject]=\"message-with-invalid-from\"" \
86             "[from]=\"\\\"Invalid \\\" From\\\" <test_suite@notmuchmail.org>\""
87 thread=$(notmuch search --output=threads subject:message-with-invalid-from)
88 test_emacs "(notmuch-show \"$thread\")
89             (test-output)"
90 cat <<EOF >EXPECTED
91 "Invalid " (2001-01-05) (inbox)
92 Subject: message-with-invalid-from
93 To: Notmuch Test Suite <test_suite@notmuchmail.org>
94 Date: Fri, 05 Jan 2001 15:43:57 +0000
95
96 This is just a test message (#1)
97 EOF
98 test_expect_equal_file OUTPUT EXPECTED
99
100 test_begin_subtest "Navigation of notmuch-search to thread view"
101 test_emacs '(notmuch-search "tag:inbox")
102             (notmuch-test-wait)
103             (goto-char (point-min))
104             (re-search-forward "Working with Maildir")
105             (notmuch-search-show-thread)
106             (notmuch-test-wait)
107             (test-output)'
108 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
109
110 test_begin_subtest "Add tag from search view"
111 os_x_darwin_thread=$(notmuch search --output=threads id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com)
112 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
113             (notmuch-test-wait)
114             (execute-kbd-macro \"+tag-from-search-view\")"
115 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
116 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-search-view unread)"
117
118 test_begin_subtest "Remove tag from search view"
119 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
120             (notmuch-test-wait)
121             (execute-kbd-macro \"-tag-from-search-view\")"
122 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
123 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
124
125 test_begin_subtest "Add tag (large query)"
126 # We use a long query to force us into batch mode and use a funny tag
127 # that requires escaping for batch tagging.
128 test_emacs "(notmuch-tag (concat \"$os_x_darwin_thread\" \" or \" (make-string notmuch-tag-argument-limit ?x)) (list \"+tag-from-%-large-query\"))"
129 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
130 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-%-large-query unread)"
131 notmuch tag -tag-from-%-large-query $os_x_darwin_thread
132
133 test_begin_subtest "notmuch-show: add single tag to single message"
134 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
135             (execute-kbd-macro \"+tag-from-show-view\")"
136 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
137 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-show-view unread)"
138
139 test_begin_subtest "notmuch-show: remove single tag from single message"
140 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
141             (execute-kbd-macro \"-tag-from-show-view\")"
142 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
143 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
144
145 test_begin_subtest "notmuch-show: add multiple tags to single message"
146 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
147             (execute-kbd-macro \"+tag1-from-show-view +tag2-from-show-view\")"
148 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
149 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag1-from-show-view tag2-from-show-view unread)"
150
151 test_begin_subtest "notmuch-show: remove multiple tags from single message"
152 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
153             (execute-kbd-macro \"-tag1-from-show-view -tag2-from-show-view\")"
154 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
155 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
156
157 test_begin_subtest "Message with .. in Message-Id:"
158 add_message [id]=123..456@example '[subject]="Message with .. in Message-Id"'
159 test_emacs '(notmuch-search "id:\"123..456@example\"")
160             (notmuch-test-wait)
161             (execute-kbd-macro "+search-add")
162             (execute-kbd-macro "+search-remove")
163             (execute-kbd-macro "-search-remove")
164             (notmuch-show "id:\"123..456@example\"")
165             (notmuch-test-wait)
166             (execute-kbd-macro "+show-add")
167             (execute-kbd-macro "+show-remove")
168             (execute-kbd-macro "-show-remove")'
169 output=$(notmuch search 'id:"123..456@example"' | notmuch_search_sanitize)
170 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Message with .. in Message-Id (inbox search-add show-add)"
171
172 test_begin_subtest "Message with quote in Message-Id:"
173 add_message '[id]="\"quote\"@example"' '[subject]="Message with quote in Message-Id"'
174 test_emacs '(notmuch-search "subject:\"Message with quote\"")
175             (notmuch-test-wait)
176             (execute-kbd-macro "+search-add")
177             (notmuch-search-show-thread)
178             (notmuch-test-wait)
179             (execute-kbd-macro "+show-add")'
180 output=$(notmuch search 'id:"""quote""@example"' | notmuch_search_sanitize)
181 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Message with quote in Message-Id (inbox search-add show-add)"
182
183 test_begin_subtest "Sending a message via (fake) SMTP"
184 emacs_deliver_message \
185     'Testing message sent via SMTP' \
186     'This is a test that messages are sent via SMTP' \
187     '(message-goto-to)
188      (kill-whole-line)
189      (insert "To: user@example.com\n")'
190 sed \
191     -e s',^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' \
192     -e s',^Message-ID: <.*>$,Message-ID: <XXX>,' \
193     -e s',^\(Content-Type: text/plain\); charset=us-ascii$,\1,' < sent_message >OUTPUT
194 cat <<EOF >EXPECTED
195 From: Notmuch Test Suite <test_suite@notmuchmail.org>
196 To: user@example.com
197 Subject: Testing message sent via SMTP
198 Date: 01 Jan 2000 12:00:00 -0000
199 User-Agent: Notmuch/XXX Emacs/XXX
200 Message-ID: <XXX>
201 MIME-Version: 1.0
202 Content-Type: text/plain
203
204 This is a test that messages are sent via SMTP
205 EOF
206 test_expect_equal_file OUTPUT EXPECTED
207
208 test_begin_subtest "Verify that sent messages are saved/searchable (via FCC)"
209 notmuch new > /dev/null
210 output=$(notmuch search 'subject:"testing message sent via SMTP"' | notmuch_search_sanitize)
211 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; Testing message sent via SMTP (inbox)"
212
213 test_begin_subtest "notmuch-fcc-dirs set to nil"
214 test_emacs "(let ((notmuch-fcc-dirs nil))
215               (notmuch-mua-mail)
216               (test-output))"
217 cat <<EOF >EXPECTED
218 From: Notmuch Test Suite <test_suite@notmuchmail.org>
219 To: 
220 Subject: 
221 --text follows this line--
222 EOF
223 test_expect_equal_file OUTPUT EXPECTED
224
225 # Make another FCC maildir specific for the next test
226 mkdir -p mail/sent-string/cur
227 mkdir -p mail/sent-string/new
228 mkdir -p mail/sent-string/tmp
229
230 test_begin_subtest "notmuch-fcc-dirs set to a string"
231 test_emacs "(let ((notmuch-fcc-dirs \"sent-string\"))
232               (notmuch-mua-mail)
233               (test-output))"
234 cat <<EOF >EXPECTED
235 From: Notmuch Test Suite <test_suite@notmuchmail.org>
236 To: 
237 Subject: 
238 Fcc: ${MAIL_DIR}/sent-string
239 --text follows this line--
240 EOF
241 test_expect_equal_file OUTPUT EXPECTED
242
243 # Make more FCC maildirs specific for the next test
244 mkdir -p mail/sent-list-match/cur
245 mkdir -p mail/sent-list-match/new
246 mkdir -p mail/sent-list-match/tmp
247 mkdir -p mail/failure/cur
248 mkdir -p mail/failure/new
249 mkdir -p mail/failure/tmp
250
251 test_begin_subtest "notmuch-fcc-dirs set to a list (with match)"
252 test_emacs "(let ((notmuch-fcc-dirs
253                    '((\"notmuchmail.org\" . \"sent-list-match\")
254                      (\".*\" . \"failure\"))))
255               (notmuch-mua-mail)
256               (test-output))"
257 cat <<EOF >EXPECTED
258 From: Notmuch Test Suite <test_suite@notmuchmail.org>
259 To: 
260 Subject: 
261 Fcc: ${MAIL_DIR}/sent-list-match
262 --text follows this line--
263 EOF
264 test_expect_equal_file OUTPUT EXPECTED
265
266 # Make another FCC maildir specific for the next test
267 mkdir -p mail/sent-list-catch-all/cur
268 mkdir -p mail/sent-list-catch-all/new
269 mkdir -p mail/sent-list-catch-all/tmp
270
271 test_begin_subtest "notmuch-fcc-dirs set to a list (catch-all)"
272 test_emacs "(let ((notmuch-fcc-dirs
273                    '((\"example.com\" . \"failure\")
274                      (\".*\" . \"sent-list-catch-all\"))))
275               (notmuch-mua-mail)
276               (test-output))"
277 cat <<EOF >EXPECTED
278 From: Notmuch Test Suite <test_suite@notmuchmail.org>
279 To: 
280 Subject: 
281 Fcc: ${MAIL_DIR}/sent-list-catch-all
282 --text follows this line--
283 EOF
284 test_expect_equal_file OUTPUT EXPECTED
285
286 test_begin_subtest "notmuch-fcc-dirs set to a list (no match)"
287 test_emacs "(let ((notmuch-fcc-dirs
288                    '((\"example.com\" . \"failure\")
289                      (\"nomatchhere.net\" . \"failure\"))))
290               (notmuch-mua-mail)
291               (test-output))"
292 cat <<EOF >EXPECTED
293 From: Notmuch Test Suite <test_suite@notmuchmail.org>
294 To: 
295 Subject: 
296 --text follows this line--
297 EOF
298 test_expect_equal_file OUTPUT EXPECTED
299
300 test_begin_subtest "Reply within emacs"
301 test_emacs '(let ((message-hidden-headers ''()))
302             (notmuch-search "subject:\"testing message sent via SMTP\"")
303             (notmuch-test-wait)
304             (notmuch-search-reply-to-thread)
305             (test-output))'
306 sed -i -e 's/^In-Reply-To: <.*>$/In-Reply-To: <XXX>/' OUTPUT
307 sed -i -e 's/^References: <.*>$/References: <XXX>/' OUTPUT
308 sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
309 cat <<EOF >EXPECTED
310 From: Notmuch Test Suite <test_suite@notmuchmail.org>
311 To: user@example.com
312 Subject: Re: Testing message sent via SMTP
313 In-Reply-To: <XXX>
314 Fcc: ${MAIL_DIR}/sent
315 References: <XXX>
316 User-Agent: Notmuch/XXX Emacs/XXX
317 --text follows this line--
318 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
319
320 > This is a test that messages are sent via SMTP
321 EOF
322 test_expect_equal_file OUTPUT EXPECTED
323
324 test_begin_subtest "Reply from alternate address within emacs"
325 add_message '[from]="Sender <sender@example.com>"' \
326              [to]=test_suite_other@notmuchmail.org
327
328 test_emacs "(let ((message-hidden-headers '()))
329             (notmuch-search \"id:\\\"${gen_msg_id}\\\"\")
330             (notmuch-test-wait)
331             (notmuch-search-reply-to-thread)
332             (test-output))"
333 sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
334 cat <<EOF >EXPECTED
335 From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
336 To: Sender <sender@example.com>
337 Subject: Re: ${test_subtest_name}
338 In-Reply-To: <${gen_msg_id}>
339 Fcc: ${MAIL_DIR}/sent
340 References: <${gen_msg_id}>
341 User-Agent: Notmuch/XXX Emacs/XXX
342 --text follows this line--
343 Sender <sender@example.com> writes:
344
345 > This is just a test message (#${gen_msg_cnt})
346 EOF
347 test_expect_equal_file OUTPUT EXPECTED
348
349 test_begin_subtest "Reply from address in named group list within emacs"
350 add_message '[from]="Sender <sender@example.com>"' \
351             '[to]=group:test_suite@notmuchmail.org,someone@example.com\;' \
352              [cc]=test_suite_other@notmuchmail.org
353
354 test_emacs "(let ((message-hidden-headers '()))
355             (notmuch-search \"id:\\\"${gen_msg_id}\\\"\")
356             (notmuch-test-wait)
357             (notmuch-search-reply-to-thread)
358             (test-output))"
359 sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
360 cat <<EOF >EXPECTED
361 From: Notmuch Test Suite <test_suite@notmuchmail.org>
362 To: Sender <sender@example.com>, someone@example.com
363 Subject: Re: ${test_subtest_name}
364 In-Reply-To: <${gen_msg_id}>
365 Fcc: ${MAIL_DIR}/sent
366 References: <${gen_msg_id}>
367 User-Agent: Notmuch/XXX Emacs/XXX
368 --text follows this line--
369 Sender <sender@example.com> writes:
370
371 > This is just a test message (#${gen_msg_cnt})
372 EOF
373 test_expect_equal_file OUTPUT EXPECTED
374
375 test_begin_subtest "Reply within emacs to a multipart/mixed message"
376 test_emacs '(let ((message-hidden-headers ''()))
377             (notmuch-show "id:20091118002059.067214ed@hikari")
378                 (notmuch-show-reply)
379                 (test-output))'
380 sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
381 cat <<EOF >EXPECTED
382 From: Notmuch Test Suite <test_suite@notmuchmail.org>
383 To: Adrian Perez de Castro <aperez@igalia.com>, notmuch@notmuchmail.org
384 Subject: Re: [notmuch] Introducing myself
385 In-Reply-To: <20091118002059.067214ed@hikari>
386 Fcc: ${MAIL_DIR}/sent
387 References: <20091118002059.067214ed@hikari>
388 User-Agent: Notmuch/XXX Emacs/XXX
389 --text follows this line--
390 Adrian Perez de Castro <aperez@igalia.com> writes:
391
392 > Hello to all,
393 >
394 > I have just heard about Not Much today in some random Linux-related news
395 > site (LWN?), my name is Adrian Perez and I work as systems administrator
396 > (although I can do some code as well :P). I have always thought that the
397 > ideas behind Sup were great, but after some time using it, I got tired of
398 > the oddities that it has. I also do not like doing things like having to
399 > install Ruby just for reading and sorting mails. Some time ago I thought
400 > about doing something like Not Much and in fact I played a bit with the
401 > Python+Xapian and the Python+Whoosh combinations, because I find relaxing
402 > to code things in Python when I am not working and also it is installed
403 > by default on most distribution. I got to have some mailboxes indexed and
404 > basic searching working a couple of months ago. Lately I have been very
405 > busy and had no time for coding, and them... boom! Not Much appears -- and
406 > it is almost exactly what I was trying to do, but faster. I have been
407 > playing a bit with Not Much today, and I think it has potential.
408 >
409 > Also, I would like to share one idea I had in mind, that you might find
410 > interesting: One thing I have found very annoying is having to re-tag my
411 > mail when the indexes get b0rked (it happened a couple of times to me while
412 > using Sup), so I was planning to mails as read/unread and adding the tags
413 > not just to the index, but to the mail text itself, e.g. by adding a
414 > "X-Tags" header field or by reusing the "Keywords" one. This way, the index
415 > could be totally recreated by re-reading the mail directories, and this
416 > would also allow to a tools like OfflineIMAP [1] to get the mails into a
417 > local maildir, tagging and indexing the mails with the e-mail reader and
418 > then syncing back the messages with the "X-Tags" header to the IMAP server.
419 > This would allow to use the mail reader from a different computer and still
420 > have everything tagged finely.
421 >
422 > Best regards,
423 >
424 >
425 > ---
426 > [1] http://software.complete.org/software/projects/show/offlineimap
427 >
428 > -- 
429 > Adrian Perez de Castro <aperez@igalia.com>
430 > Igalia - Free Software Engineering
431 > _______________________________________________
432 > notmuch mailing list
433 > notmuch@notmuchmail.org
434 > http://notmuchmail.org/mailman/listinfo/notmuch
435 EOF
436 test_expect_equal_file OUTPUT EXPECTED
437
438 test_begin_subtest "Reply within emacs to a multipart/alternative message"
439 test_emacs '(let ((message-hidden-headers ''()))
440             (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
441                 (notmuch-show-reply)
442                 (test-output))'
443 sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
444 cat <<EOF >EXPECTED
445 From: Notmuch Test Suite <test_suite@notmuchmail.org>
446 To: Alex Botero-Lowry <alex.boterolowry@gmail.com>, notmuch@notmuchmail.org
447 Subject: Re: [notmuch] preliminary FreeBSD support
448 In-Reply-To: <cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com>
449 Fcc: ${MAIL_DIR}/sent
450 References: <cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com>
451 User-Agent: Notmuch/XXX Emacs/XXX
452 --text follows this line--
453 Alex Botero-Lowry <alex.boterolowry@gmail.com> writes:
454
455 > I saw the announcement this morning, and was very excited, as I had been
456 > hoping sup would be turned into a library,
457 > since I like the concept more than the UI (I'd rather an emacs interface).
458 >
459 > I did a preliminary compile which worked out fine, but
460 > sysconf(_SC_SC_GETPW_R_SIZE_MAX) returns -1 on
461 > FreeBSD, so notmuch_config_open segfaulted.
462 >
463 > Attached is a patch that supplies a default buffer size of 64 in cases where
464 > -1 is returned.
465 >
466 > http://www.opengroup.org/austin/docs/austin_328.txt - seems to indicate this
467 > is acceptable behavior,
468 > and http://mail-index.netbsd.org/pkgsrc-bugs/2006/06/07/msg016808.htmlspecifically
469 > uses 64 as the
470 > buffer size.
471 > _______________________________________________
472 > notmuch mailing list
473 > notmuch@notmuchmail.org
474 > http://notmuchmail.org/mailman/listinfo/notmuch
475 EOF
476 test_expect_equal_file OUTPUT EXPECTED
477
478 test_begin_subtest "Reply within emacs to an html-only message"
479 add_message '[content-type]="text/html"' \
480             '[body]="Hi,<br />This is an <b>HTML</b> test message.<br /><br />OK?"'
481 test_emacs "(let ((message-hidden-headers '()) (mm-text-html-renderer 'html2text))
482             (notmuch-show \"id:${gen_msg_id}\")
483             (notmuch-show-reply)
484             (test-output))"
485 sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
486 cat <<EOF >EXPECTED
487 From: Notmuch Test Suite <test_suite@notmuchmail.org>
488 To: 
489 Subject: Re: Reply within emacs to an html-only message
490 In-Reply-To: <${gen_msg_id}>
491 Fcc: ${MAIL_DIR}/sent
492 References: <${gen_msg_id}>
493 User-Agent: Notmuch/XXX Emacs/XXX
494 --text follows this line--
495 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
496
497 > Hi,This is an HTML test message.OK?
498 EOF
499 test_expect_equal_file OUTPUT EXPECTED
500
501 test_begin_subtest "Quote MML tags in reply"
502 message_id='test-emacs-mml-quoting@message.id'
503 add_message [id]="$message_id" \
504             "[subject]='$test_subtest_name'" \
505             '[body]="<#part disposition=inline>"'
506 test_emacs "(let ((message-hidden-headers '()))
507               (notmuch-show \"id:$message_id\")
508               (notmuch-show-reply)
509               (test-output))"
510 sed -i -e 's,^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' OUTPUT
511 cat <<EOF >EXPECTED
512 From: Notmuch Test Suite <test_suite@notmuchmail.org>
513 To: 
514 Subject: Re: Quote MML tags in reply
515 In-Reply-To: <test-emacs-mml-quoting@message.id>
516 Fcc: ${MAIL_DIR}/sent
517 References: <test-emacs-mml-quoting@message.id>
518 User-Agent: Notmuch/XXX Emacs/XXX
519 --text follows this line--
520 Notmuch Test Suite <test_suite@notmuchmail.org> writes:
521
522 > <#!part disposition=inline>
523 EOF
524 test_expect_equal_file OUTPUT EXPECTED
525
526 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-attachments"
527 # save as archive to test that Emacs does not re-compress .gz
528 test_emacs '(let ((standard-input "\"attachment1.gz\""))
529               (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
530               (notmuch-show-save-attachments))'
531 test_expect_equal_file attachment1.gz "$EXPECTED/attachment"
532
533 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-part"
534 # save as archive to test that Emacs does not re-compress .gz
535 test_emacs '(let ((standard-input "\"attachment2.gz\""))
536               (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
537               (search-forward "0001-Deal-with")
538               (notmuch-show-save-part))'
539 test_expect_equal_file attachment2.gz "$EXPECTED/attachment"
540
541 test_begin_subtest "Save 8bit attachment from within emacs using notmuch-show-save-attachments"
542
543 add_message '[subject]="Attachment with 8bit chars"' \
544         '[header]="MIME-Version: 1.0"' \
545         '[content-type]="multipart/mixed; boundary=\"abcd\""' \
546         '[body]="--abcd
547 Content-Type: text/plain
548
549 Attachment follows:
550
551 --abcd
552 Content-Type: application/octet-stream; name=\"sample\"
553 Content-Transfer-Encoding: 8bit
554 Content-Disposition: attachment; filename=\"sample\"
555
556 “¡ Hey ! It compiles ¡ Ship it !”
557
558 --abcd--
559 "'
560 test_emacs '(notmuch-show "id:'"${gen_msg_id}"'")
561             (delete-file "OUTPUT")
562             (let ((standard-input "\"OUTPUT\""))
563               (notmuch-show-save-attachments))'
564
565 test_expect_equal "$(cat OUTPUT)" '“¡ Hey ! It compiles ¡ Ship it !”'
566
567 test_begin_subtest "View raw message within emacs"
568 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
569             (notmuch-show-view-raw-message)
570             (test-output)'
571 test_expect_equal_file OUTPUT $EXPECTED/raw-message-cf0c4d-52ad0a
572
573 test_begin_subtest "Hiding/showing signature in notmuch-show view"
574 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
575 test_emacs "(notmuch-show \"$maildir_storage_thread\")
576             (search-forward \"Click/Enter to show.\")
577             (button-activate (button-at (point)))
578             (search-backward \"Click/Enter to hide.\")
579             (button-activate (button-at (point)))
580             (test-output)"
581 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
582
583 test_begin_subtest "Detection and hiding of top-post quoting of message"
584 add_message '[subject]="The problem with top-posting"' \
585             [id]=top-post-target \
586             '[body]="A: Because it messes up the order in which people normally read text.
587 Q: Why is top-posting such a bad thing?
588 A: Top-posting.
589 Q: What is the most annoying thing in e-mail?"'
590 add_message '[from]="Top Poster <top@poster.com>"' \
591             [in-reply-to]=top-post-target \
592             [references]=top-post-target \
593             '[subject]="Re: The problem with top-posting"' \
594             '[body]="Thanks for the advice! I will be sure to put it to good use.
595
596 -Top Poster
597
598 ----- Original Message -----
599 From: Notmuch Test Suite <test_suite@notmuchmail.org>
600 To: Notmuch Test Suite <test_suite@notmuchmai.org>
601 Sent: Fri, 05 Jan 2001 15:43:57 +0000
602 Subject: The problem with top-posting
603
604 Q: Why is top-posting such a bad thing?
605 A: Top-posting.
606 Q: What is the most annoying thing in e-mail?"'
607 test_emacs "(notmuch-show \"top-posting\")
608             (test-visible-output)"
609 echo "Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
610 Subject: The problem with top-posting
611 To: Notmuch Test Suite <test_suite@notmuchmail.org>
612 Date: Fri, 05 Jan 2001 15:43:57 +0000
613
614 A: Because it messes up the order in which people normally read text.
615 Q: Why is top-posting such a bad thing?
616 A: Top-posting.
617 Q: What is the most annoying thing in e-mail?
618 Top Poster <top@poster.com> (2001-01-05) (inbox unread)
619 Subject: Re: The problem with top-posting
620 To: Notmuch Test Suite <test_suite@notmuchmail.org>
621 Date: Fri, 05 Jan 2001 15:43:57 +0000
622
623 Thanks for the advice! I will be sure to put it to good use.
624
625 -Top Poster
626
627 [ 9-line hidden original message. Click/Enter to show. ]" > EXPECTED
628 test_expect_equal_file OUTPUT EXPECTED
629
630 test_begin_subtest "Hiding message in notmuch-show view"
631 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
632             (notmuch-show-toggle-message)
633             (test-visible-output)'
634 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages
635
636 test_begin_subtest "Hiding message with visible citation in notmuch-show view"
637 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
638             (search-forward "Click/Enter to show.")
639             (button-activate (button-at (point)))
640             (notmuch-show-toggle-message)
641             (test-visible-output)'
642 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages
643
644 test_begin_subtest "notmuch-show: show message headers"
645 test_emacs \
646         '(let ((notmuch-message-headers '\''("Subject" "To" "Cc" "Date"))
647                (notmuch-message-headers-visible t))
648            (notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
649            (test-visible-output))'
650 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-message-with-headers-visible
651
652 test_begin_subtest "notmuch-show: hide message headers"
653 test_emacs \
654         '(let ((notmuch-message-headers '\''("Subject" "To" "Cc" "Date"))
655                (notmuch-message-headers-visible nil))
656            (notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
657            (test-visible-output))'
658 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-message-with-headers-hidden
659
660 test_begin_subtest "notmuch-show: hide message headers (w/ notmuch-show-toggle-visibility-headers)"
661 test_emacs \
662         '(let ((notmuch-message-headers '\''("Subject" "To" "Cc" "Date"))
663                (notmuch-message-headers-visible t))
664            (notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
665            (notmuch-show-toggle-visibility-headers)
666            (test-visible-output))'
667 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-message-with-headers-hidden
668
669 test_begin_subtest "notmuch-show: collapse all messages in thread"
670 test_emacs '(notmuch-show "id:f35dbb950911171435ieecd458o853c873e35f4be95@mail.gmail.com")
671         (let ((current-prefix-arg t))
672           (notmuch-show-open-or-close-all)
673           (test-visible-output))'
674 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-all-messages-collapsed
675
676 test_begin_subtest "notmuch-show: uncollapse all messages in thread"
677 test_emacs '(notmuch-show "id:f35dbb950911171435ieecd458o853c873e35f4be95@mail.gmail.com")
678         (notmuch-show-open-or-close-all)
679         (test-visible-output)'
680 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-all-messages-uncollapsed
681
682 test_begin_subtest "Stashing in notmuch-show"
683 add_message '[date]="Sat, 01 Jan 2000 12:00:00 -0000"' \
684     '[from]="Some One <someone@somewhere.org>"' \
685     '[to]="Some One Else <notsomeone@somewhere.org>"' \
686     '[cc]="Notmuch <notmuch@notmuchmail.org>"' \
687     '[subject]="Stash my stashables"' \
688     '[id]="bought"' \
689     '[body]="Unable to stash body. Where did you get it in the first place?!?"'
690 notmuch tag +stashtest id:${gen_msg_id}
691 test_emacs '(notmuch-show "id:\"bought\"")
692         (notmuch-show-stash-date)
693         (notmuch-show-stash-from)
694         (notmuch-show-stash-to)
695         (notmuch-show-stash-cc)
696         (notmuch-show-stash-subject)
697         (notmuch-show-stash-message-id)
698         (notmuch-show-stash-message-id-stripped)
699         (notmuch-show-stash-tags)
700         (notmuch-show-stash-filename)
701         (notmuch-show-stash-mlarchive-link "Gmane")
702         (notmuch-show-stash-mlarchive-link "MARC")
703         (notmuch-show-stash-mlarchive-link "Mail Archive, The")
704         (switch-to-buffer
705           (generate-new-buffer "*test-stashing*"))
706         (dotimes (i 12)
707           (yank)
708           (insert "\n")
709           (rotate-yank-pointer 1))
710         (reverse-region (point-min) (point-max))
711             (test-output)'
712 cat <<EOF >EXPECTED
713 Sat, 01 Jan 2000 12:00:00 +0000
714 Some One <someone@somewhere.org>
715 Some One Else <notsomeone@somewhere.org>
716 Notmuch <notmuch@notmuchmail.org>
717 Stash my stashables
718 id:bought
719 bought
720 inbox,stashtest
721 ${gen_msg_filename}
722 http://mid.gmane.org/bought
723 http://marc.info/?i=bought
724 http://mail-archive.com/search?l=mid&q=bought
725 EOF
726 test_expect_equal_file OUTPUT EXPECTED
727
728 test_begin_subtest "Stashing in notmuch-search"
729 test_emacs '(notmuch-search "id:\"bought\"")
730         (notmuch-test-wait)
731         (notmuch-search-stash-thread-id)
732         (switch-to-buffer
733           (generate-new-buffer "*test-stashing*"))
734         (yank)
735             (test-output)'
736 sed -i -e 's/^thread:.*$/thread:XXX/' OUTPUT
737 test_expect_equal "$(cat OUTPUT)" "thread:XXX"
738
739 test_begin_subtest 'notmuch-show-advance-and-archive with invisible signature'
740 message1='id:20091118010116.GC25380@dottiness.seas.harvard.edu'
741 message2='id:1258491078-29658-1-git-send-email-dottedmag@dottedmag.net'
742 test_emacs "(notmuch-show \"$message2\")
743             (test-output \"EXPECTED\")"
744 test_emacs "(notmuch-search \"$message1 or $message2\")
745             (notmuch-test-wait)
746             (notmuch-search-show-thread)
747             (goto-char (point-max))
748             (redisplay)
749             (notmuch-show-advance-and-archive)
750             (test-output)"
751 test_expect_equal_file OUTPUT EXPECTED
752
753 test_begin_subtest "Refresh show buffer"
754 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
755             (test-visible-output "EXPECTED")
756             (notmuch-show-refresh-view)
757             (test-visible-output)'
758 test_expect_equal_file OUTPUT EXPECTED
759
760 test_begin_subtest "Refresh modified show buffer"
761 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
762             (notmuch-show-toggle-message)
763             (notmuch-show-next-message)
764             (notmuch-show-toggle-message)
765             (test-visible-output "EXPECTED")
766             (notmuch-show-refresh-view)
767             (test-visible-output)'
768 test_expect_equal_file OUTPUT EXPECTED
769
770 test_begin_subtest "Do not call notmuch for non-inlinable application/mpeg parts"
771 id='message-with-application/mpeg-attachment@notmuchmail.org'
772 emacs_deliver_message \
773     'Message with application/mpeg attachment' \
774     '' \
775     "(message-goto-eoh)
776      (insert \"Message-ID: <$id>\n\")
777      (message-goto-body)
778      (mml-insert-part \"application/mpeg\")
779      (insert \"a fake mp3 file\")"
780 notmuch_counter_reset
781 test_emacs "(let ((notmuch-command \"$notmuch_counter_command\"))
782               (notmuch-show \"id:$id\"))"
783 test_expect_equal $(notmuch_counter_value) 1
784
785 test_begin_subtest "Do not call notmuch for non-inlinable audio/mpeg parts"
786 id='message-with-audio/mpeg-attachment@notmuchmail.org'
787 emacs_deliver_message \
788     'Message with audio/mpeg attachment' \
789     '' \
790     "(message-goto-eoh)
791      (insert \"Message-ID: <$id>\n\")
792      (message-goto-body)
793      (mml-insert-part \"audio/mpeg\")
794      (insert \"a fake mp3 file\")"
795 notmuch_counter_reset
796 test_emacs "(let ((notmuch-command \"$notmuch_counter_command\"))
797               (notmuch-show \"id:$id\"))"
798 test_expect_equal $(notmuch_counter_value) 1
799
800 test_begin_subtest "notmuch-hello-mode hook is called"
801 counter=$(test_emacs \
802     '(let ((notmuch-hello-mode-hook-counter 0))
803        (kill-buffer "*notmuch-hello*")
804        (notmuch-hello)
805        notmuch-hello-mode-hook-counter)'
806 )
807 test_expect_equal "$counter" 1
808
809 test_begin_subtest "notmuch-hello-mode hook is not called on updates"
810 counter=$(test_emacs \
811     '(let ((notmuch-hello-mode-hook-counter 0))
812        (kill-buffer "*notmuch-hello*")
813        (notmuch-hello)
814        (notmuch-hello-update)
815        notmuch-hello-mode-hook-counter)'
816 )
817 test_expect_equal "$counter" 1
818
819 test_begin_subtest "notmuch-hello-refresh hook is called"
820 counter=$(test_emacs \
821     '(let ((notmuch-hello-refresh-hook-counter 0))
822        (kill-buffer "*notmuch-hello*")
823        (notmuch-hello)
824        notmuch-hello-refresh-hook-counter)'
825 )
826 test_expect_equal "$counter" 1
827
828 test_begin_subtest "notmuch-hello-refresh hook is called on updates"
829 counter=$(test_emacs \
830     '(let ((notmuch-hello-refresh-hook-counter 0))
831        (kill-buffer "*notmuch-hello*")
832        (notmuch-hello)
833        (notmuch-hello-update)
834        notmuch-hello-refresh-hook-counter)'
835 )
836 test_expect_equal "$counter" 2
837
838
839 add_message '[subject]="HTML mail with images"' \
840     '[content-type]="multipart/related; boundary=abcd"' \
841     '[body]="--abcd
842 Content-Type: text/html
843
844 <img src="cid:330@goomoji.gmail"> smiley
845
846 --abcd
847 Content-Type: image/gif
848 Content-Transfer-Encoding: base64
849 Content-ID: <330@goomoji.gmail>
850
851 R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMl
852 WLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7
853 --abcd--"'
854 test_emacs "(let ((mm-text-html-renderer
855                    (if (assq 'shr mm-text-html-renderer-alist)
856                        'shr 'html2text)))
857               (notmuch-show \"id:${gen_msg_id}\"))
858             (test-output)" > /dev/null
859 # Different Emacs versions and renderers give very different results,
860 # so just check that something reasonable showed up.  We first cat the
861 # output so the test framework will print it if the test fails.
862 test_expect_success "Rendering HTML mail with images" \
863     'cat OUTPUT && grep -q smiley OUTPUT'
864
865
866 test_begin_subtest "Search handles subprocess error exit codes"
867 cat > notmuch_fail <<EOF
868 #!/bin/sh
869 echo '()'
870 exit 1
871 EOF
872 chmod a+x notmuch_fail
873 test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))
874                (with-current-buffer \"*Messages*\" (erase-buffer))
875                (with-current-buffer (get-buffer-create \"*Notmuch errors*\")
876                  (erase-buffer))
877                (notmuch-search \"tag:inbox\")
878                (notmuch-test-wait)
879                (with-current-buffer \"*Messages*\"
880                   (test-output \"MESSAGES\"))
881                (with-current-buffer \"*Notmuch errors*\"
882                   (test-output \"ERROR\"))
883                (test-output))"
884 sed -i -e 's/^\[.*\]$/[XXX]/' ERROR
885 test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\
886 End of search results.
887 ---
888 $PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)
889 ---
890 [XXX]
891 $PWD/notmuch_fail exited with status 1
892 command: $PWD/notmuch_fail search --format\=sexp --format-version\=1 --sort\=newest-first tag\:inbox
893 exit status: 1"
894
895 test_begin_subtest "Search handles subprocess warnings"
896 cat > notmuch_fail <<EOF
897 #!/bin/sh
898 echo '()'
899 echo This is a warning >&2
900 echo This is another warning >&2
901 exit 0
902 EOF
903 chmod a+x notmuch_fail
904 test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))
905                (with-current-buffer \"*Messages*\" (erase-buffer))
906                (with-current-buffer (get-buffer-create \"*Notmuch errors*\")
907                  (erase-buffer))
908                (notmuch-search \"tag:inbox\")
909                (notmuch-test-wait)
910                (with-current-buffer \"*Messages*\"
911                   (test-output \"MESSAGES\"))
912                (with-current-buffer \"*Notmuch errors*\"
913                   (test-output \"ERROR\"))
914                (test-output))"
915 sed -i -e 's/^\[.*\]$/[XXX]/' ERROR
916 test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\
917 End of search results.
918 ---
919 This is a warning (see *Notmuch errors* for more details)
920 ---
921 [XXX]
922 This is a warning
923 This is another warning"
924
925 test_done