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