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