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