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