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