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