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