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