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