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