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