]> git.cworth.org Git - notmuch/blob - test/T450-emacs-show.sh
Merge tag '0.32'
[notmuch] / test / T450-emacs-show.sh
1 #!/usr/bin/env bash
2
3 test_description="emacs notmuch-show view"
4 . $(dirname "$0")/test-lib.sh || exit 1
5
6 EXPECTED=$NOTMUCH_SRCDIR/test/emacs-show.expected-output
7
8 test_require_emacs
9 add_email_corpus
10
11 test_begin_subtest "Hiding Original Message region at beginning of a message"
12 message_id='OriginalMessageHiding.1@notmuchmail.org'
13 add_message \
14     [id]="$message_id" \
15     '[subject]="Hiding Original Message region at beginning of a message"' \
16     '[body]="-----Original Message-----
17 Text here."'
18
19 cat <<EOF >EXPECTED
20 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
21 Subject: Hiding Original Message region at beginning of a message
22 To: Notmuch Test Suite <test_suite@notmuchmail.org>
23 Date: GENERATED_DATE
24
25 [ 2-line hidden original message. Click/Enter to show. ]
26 EOF
27
28 test_emacs "(notmuch-show \"id:$message_id\")
29             (test-visible-output \"OUTPUT.raw\")"
30 notmuch_date_sanitize < OUTPUT.raw > OUTPUT
31 test_expect_equal_file EXPECTED OUTPUT
32
33 test_begin_subtest "Bare subject #1"
34 output=$(test_emacs '(notmuch-show-strip-re "Re: subject")')
35 test_expect_equal "$output" '"subject"'
36
37 test_begin_subtest "Bare subject #2"
38 output=$(test_emacs '(notmuch-show-strip-re "re:Re: re:  Re:  re:subject")')
39 test_expect_equal "$output" '"subject"'
40
41 test_begin_subtest "Bare subject #3"
42 output=$(test_emacs '(notmuch-show-strip-re "the cure: fix the regexp")')
43 test_expect_equal "$output" '"the cure: fix the regexp"'
44
45 test_begin_subtest "don't process cryptographic MIME parts"
46 test_emacs '(let ((notmuch-crypto-process-mime nil))
47         (notmuch-show "id:20091117203301.GV3165@dottiness.seas.harvard.edu")
48         (test-visible-output))'
49 test_expect_equal_file $EXPECTED/notmuch-show-process-crypto-mime-parts-off OUTPUT
50
51 test_begin_subtest "process cryptographic MIME parts"
52 test_emacs '(let ((notmuch-crypto-process-mime t))
53         (notmuch-show "id:20091117203301.GV3165@dottiness.seas.harvard.edu")
54         (test-visible-output))'
55 test_expect_equal_file $EXPECTED/notmuch-show-process-crypto-mime-parts-on OUTPUT
56
57 test_begin_subtest "process cryptographic MIME parts (w/ notmuch-show-toggle-process-crypto)"
58 test_emacs '(let ((notmuch-crypto-process-mime nil))
59         (notmuch-show "id:20091117203301.GV3165@dottiness.seas.harvard.edu")
60         (notmuch-show-toggle-process-crypto)
61         (test-visible-output))'
62 test_expect_equal_file $EXPECTED/notmuch-show-process-crypto-mime-parts-on OUTPUT
63
64 test_begin_subtest "notmuch-show: don't elide non-matching messages"
65 test_emacs '(let ((notmuch-show-only-matching-messages nil))
66         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
67         (notmuch-test-wait)
68         (notmuch-search-show-thread)
69         (notmuch-test-wait)
70         (test-visible-output))'
71 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-off OUTPUT
72
73 test_begin_subtest "notmuch-show: elide non-matching messages"
74 test_emacs '(let ((notmuch-show-only-matching-messages t))
75         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
76         (notmuch-test-wait)
77         (notmuch-search-show-thread)
78         (notmuch-test-wait)
79         (test-visible-output))'
80 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
81
82 test_begin_subtest "notmuch-show: elide non-matching messages (w/ notmuch-show-toggle-elide-non-matching)"
83 test_emacs '(let ((notmuch-show-only-matching-messages nil))
84         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
85         (notmuch-test-wait)
86         (notmuch-search-show-thread)
87         (notmuch-test-wait)
88         (notmuch-show-toggle-elide-non-matching)
89         (test-visible-output))'
90 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
91
92 test_begin_subtest "notmuch-show: elide non-matching messages (w/ prefix arg to notmuch-show)"
93 test_emacs '(let ((notmuch-show-only-matching-messages nil))
94         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
95         (notmuch-test-wait)
96         (notmuch-search-show-thread t)
97         (notmuch-test-wait)
98         (test-visible-output))'
99 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
100
101 test_begin_subtest "notmuch-show: disable indentation of thread content (w/ notmuch-show-toggle-thread-indentation)"
102 test_emacs '(notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
103         (notmuch-test-wait)
104         (notmuch-search-show-thread)
105         (notmuch-test-wait)
106         (notmuch-show-toggle-thread-indentation)
107         (test-visible-output)'
108 test_expect_equal_file $EXPECTED/notmuch-show-indent-thread-content-off OUTPUT
109
110 test_begin_subtest "id buttonization"
111 add_message '[body]="
112 id:abc
113 id:abc.def. id:abc,def, id:abc;def; id:abc:def:
114 id:foo@bar.?baz? id:foo@bar!.baz!
115 (id:foo@bar.baz) [id:foo@bar.baz]
116 id:foo@bar.baz...
117 id:2+2=5
118 id:=_-:/.[]@$%+
119 id:abc)def
120 id:ab\"c def
121 id:\"abc\"def
122 id:\"ab\"\"c\"def
123 id:\"ab c\"def
124 id:\"abc\".def
125 id:\"abc
126 \"
127 id:)
128 id:
129 cid:xxx
130 mid:abc mid:abc/def
131 mid:abc%20def
132 mid:abc. mid:abc, mid:abc;"'
133 test_emacs '(notmuch-show "id:'$gen_msg_id'")
134         (notmuch-test-mark-links)
135         (test-visible-output "OUTPUT.raw")'
136 cat <<EOF >EXPECTED
137 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
138 Subject: id buttonization
139 To: Notmuch Test Suite <test_suite@notmuchmail.org>
140 Date: GENERATED_DATE
141
142 <<id:abc>>
143 <<id:abc.def>>. <<id:abc,def>>, <<id:abc;def>>; <<id:abc:def>>:
144 <<id:foo@bar.?baz>>? <<id:foo@bar!.baz>>!
145 (<<id:foo@bar.baz>>) [<<id:foo@bar.baz>>]
146 <<id:foo@bar.baz>>...
147 <<id:2+2=5>>
148 <<id:=_-:/.[]@$%+>>
149 <<id:abc>>)def
150 <<id:ab"c>> def
151 <<id:"abc">>def
152 <<id:"ab""c">>def
153 <<id:"ab c">>def
154 <<id:"abc">>.def
155 id:"abc
156 "
157 id:)
158 id:
159 cid:xxx
160 <<mid:abc>> <<mid:abc/def>>
161 <<mid:abc%20def>>
162 <<mid:abc>>. <<mid:abc>>, <<mid:abc>>;
163 EOF
164 notmuch_date_sanitize < OUTPUT.raw > OUTPUT
165 test_expect_equal_file EXPECTED OUTPUT
166
167
168 test_begin_subtest "Show handles subprocess errors"
169 cat > notmuch_fail <<EOF
170 #!/bin/sh
171 echo This is output
172 echo This is an error >&2
173 exit 1
174 EOF
175 chmod a+x notmuch_fail
176 test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))
177                (with-current-buffer \"*Messages*\"
178                   (let ((inhibit-read-only t)) (erase-buffer)))
179                (condition-case err
180                    (notmuch-show \"*\")
181                  (error (message \"%s\" (cadr err))))
182                (notmuch-test-wait)
183                (with-current-buffer \"*Messages*\"
184                   (test-output \"MESSAGES\"))
185                (with-current-buffer \"*Notmuch errors*\"
186                   (test-output \"ERROR\"))
187                (test-output))"
188 test_expect_equal "$(notmuch_emacs_error_sanitize notmuch_fail OUTPUT MESSAGES ERROR)" "\
189 === OUTPUT ===
190 === MESSAGES ===
191 This is an error (see *Notmuch errors* for more details)
192 === ERROR ===
193 [XXX]
194 This is an error
195 command: YYY/notmuch_fail show --format\\=sexp --format-version\\=4 --decrypt\\=true --exclude\\=false \\' \\* \\'
196 exit status: 1
197 stderr:
198 This is an error
199 stdout:
200 This is output"
201
202 test_begin_subtest "text/enriched exploit mitigation"
203 add_message '[content-type]="text/enriched"
204              [body]="
205 <x-display><param>(when (progn (read-only-mode -1) (insert ?p ?0 ?w ?n ?e ?d)) nil)</param>test</x-display>
206 "'
207 test_emacs '(notmuch-show "id:'$gen_msg_id'")
208         (test-visible-output "OUTPUT.raw")'
209 output=$(head -1 OUTPUT.raw|cut -f1-4 -d' ')
210 test_expect_equal "$output" "Notmuch Test Suite <test_suite@notmuchmail.org>"
211
212
213 # switching to the crypto corpus, using gpg from here on:
214 add_gnupg_home
215 add_email_corpus crypto
216
217 test_begin_subtest "show decrypted message"
218 test_emacs '(notmuch-show "id:basic-encrypted@crypto.notmuchmail.org")
219             (test-visible-output)'
220 test_expect_equal_file $EXPECTED/notmuch-show-decrypted-message OUTPUT
221
222 test_begin_subtest "show undecryptable message"
223 test_emacs '(notmuch-show "id:simple-encrypted@crypto.notmuchmail.org")
224             (test-visible-output)'
225 test_expect_equal_file $EXPECTED/notmuch-show-undecryptable-message OUTPUT
226
227 test_begin_subtest "show encrypted message when not processing crypto"
228 test_emacs '(let ((notmuch-crypto-process-mime nil))
229              (notmuch-show "id:basic-encrypted@crypto.notmuchmail.org")
230              (test-visible-output))'
231 test_expect_equal_file $EXPECTED/notmuch-show-decrypted-message-no-crypto OUTPUT
232
233 test_done