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