]> git.cworth.org Git - notmuch/blob - test/T450-emacs-show.sh
emacs/show: obey notmuch-show-max-text-part-size for part 0
[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 . $NOTMUCH_SRCDIR/test/test-lib-emacs.sh || exit 1
6
7 EXPECTED=$NOTMUCH_SRCDIR/test/emacs-show.expected-output
8
9 test_require_emacs
10 add_email_corpus
11
12 test_begin_subtest "Hiding Original Message region at beginning of a message"
13 message_id='OriginalMessageHiding.1@notmuchmail.org'
14 add_message \
15     [id]="$message_id" \
16     '[subject]="Hiding Original Message region at beginning of a message"' \
17     '[body]="-----Original Message-----
18 Text here."'
19
20 cat <<EOF >EXPECTED
21 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
22 Subject: Hiding Original Message region at beginning of a message
23 To: Notmuch Test Suite <test_suite@notmuchmail.org>
24 Date: GENERATED_DATE
25
26 [ 2-line hidden original message. Click/Enter to show. ]
27 EOF
28
29 test_emacs "(notmuch-show \"id:$message_id\")
30             (test-visible-output \"OUTPUT.raw\")"
31 notmuch_date_sanitize < OUTPUT.raw > OUTPUT
32 test_expect_equal_file EXPECTED OUTPUT
33
34 test_begin_subtest "Bare subject #1"
35 output=$(test_emacs '(notmuch-show-strip-re "Re: subject")')
36 test_expect_equal "$output" '"subject"'
37
38 test_begin_subtest "Bare subject #2"
39 output=$(test_emacs '(notmuch-show-strip-re "re:Re: re:  Re:  re:subject")')
40 test_expect_equal "$output" '"subject"'
41
42 test_begin_subtest "Bare subject #3"
43 output=$(test_emacs '(notmuch-show-strip-re "the cure: fix the regexp")')
44 test_expect_equal "$output" '"the cure: fix the regexp"'
45
46 test_begin_subtest "don't process cryptographic MIME parts"
47 test_emacs '(let ((notmuch-crypto-process-mime nil))
48         (notmuch-show "id:20091117203301.GV3165@dottiness.seas.harvard.edu")
49         (test-visible-output))'
50 test_expect_equal_file $EXPECTED/notmuch-show-process-crypto-mime-parts-off OUTPUT
51
52 test_begin_subtest "process cryptographic MIME parts"
53 test_emacs '(let ((notmuch-crypto-process-mime t))
54         (notmuch-show "id:20091117203301.GV3165@dottiness.seas.harvard.edu")
55         (test-visible-output))'
56 test_expect_equal_file $EXPECTED/notmuch-show-process-crypto-mime-parts-on OUTPUT
57
58 test_begin_subtest "process cryptographic MIME parts (w/ notmuch-show-toggle-process-crypto)"
59 test_emacs '(let ((notmuch-crypto-process-mime nil))
60         (notmuch-show "id:20091117203301.GV3165@dottiness.seas.harvard.edu")
61         (notmuch-show-toggle-process-crypto)
62         (test-visible-output))'
63 test_expect_equal_file $EXPECTED/notmuch-show-process-crypto-mime-parts-on OUTPUT
64
65 test_begin_subtest "notmuch-search-show-thread returns non-nil on success"
66 test_emacs_expect_t  '(notmuch-search "id:20091117203301.GV3165@dottiness.seas.harvard.edu")
67                       (notmuch-test-wait)
68                       (and (notmuch-search-show-thread)
69                            (not (notmuch-show-next-thread)))'
70
71 test_begin_subtest "notmuch-search-show-thread returns nil when there are no messages"
72 test_emacs_expect_t  '(notmuch-search "id:non-existing-id")
73                       (notmuch-test-wait)
74                       (not (notmuch-search-show-thread))'
75
76 test_begin_subtest "notmuch-show: don't elide non-matching messages"
77 test_emacs '(let ((notmuch-show-only-matching-messages nil))
78         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
79         (notmuch-test-wait)
80         (notmuch-search-show-thread)
81         (notmuch-test-wait)
82         (test-visible-output))'
83 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-off OUTPUT
84
85 test_begin_subtest "notmuch-show: elide non-matching messages"
86 test_emacs '(let ((notmuch-show-only-matching-messages t))
87         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
88         (notmuch-test-wait)
89         (notmuch-search-show-thread)
90         (notmuch-test-wait)
91         (test-visible-output))'
92 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
93
94 test_begin_subtest "Hide bodies of messages by depth"
95 test_emacs '(let ((notmuch-show-depth-limit -1))
96         (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}")
97         (notmuch-test-wait)
98         (notmuch-search-show-thread)
99         (notmuch-test-wait)
100         (test-visible-output))'
101 test_expect_equal_file $EXPECTED/notmuch-show-depth OUTPUT
102
103 test_begin_subtest "Hide bodies of messages (depth > 1)"
104 test_emacs '(let ((notmuch-show-depth-limit 1))
105         (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}")
106         (notmuch-test-wait)
107         (notmuch-search-show-thread)
108         (notmuch-test-wait)
109         (test-visible-output))'
110 test_expect_equal_file $EXPECTED/notmuch-show-depth-1 OUTPUT
111
112 test_begin_subtest "Hide bodies of messages by size"
113 test_emacs '(let ((notmuch-show-max-text-part-size 1))
114         (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}")
115         (notmuch-test-wait)
116         (notmuch-search-show-thread)
117         (notmuch-test-wait)
118         (test-visible-output))'
119 test_expect_equal_file $EXPECTED/notmuch-show-size OUTPUT
120
121 test_begin_subtest "Hide bodies of messages by size > 450"
122 test_emacs '(let ((notmuch-show-max-text-part-size 450))
123         (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}")
124         (notmuch-test-wait)
125         (notmuch-search-show-thread)
126         (notmuch-test-wait)
127         (test-visible-output))'
128 test_expect_equal_file $EXPECTED/notmuch-show-size-450 OUTPUT
129
130 test_begin_subtest "notmuch-show: elide non-matching messages (w/ notmuch-show-toggle-elide-non-matching)"
131 test_emacs '(let ((notmuch-show-only-matching-messages nil))
132         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
133         (notmuch-test-wait)
134         (notmuch-search-show-thread)
135         (notmuch-test-wait)
136         (notmuch-show-toggle-elide-non-matching)
137         (test-visible-output))'
138 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
139
140 test_begin_subtest "notmuch-show: elide non-matching messages (w/ prefix arg to notmuch-show)"
141 test_emacs '(let ((notmuch-show-only-matching-messages nil))
142         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
143         (notmuch-test-wait)
144         (notmuch-search-show-thread t)
145         (notmuch-test-wait)
146         (test-visible-output))'
147 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
148
149 test_begin_subtest "notmuch-show: disable indentation of thread content (w/ notmuch-show-toggle-thread-indentation)"
150 test_emacs '(notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
151         (notmuch-test-wait)
152         (notmuch-search-show-thread)
153         (notmuch-test-wait)
154         (notmuch-show-toggle-thread-indentation)
155         (test-visible-output)'
156 test_expect_equal_file $EXPECTED/notmuch-show-indent-thread-content-off OUTPUT
157
158 test_begin_subtest "id buttonization"
159 add_message '[body]="
160 id:abc
161 id:abc.def. id:abc,def, id:abc;def; id:abc:def:
162 id:foo@bar.?baz? id:foo@bar!.baz!
163 (id:foo@bar.baz) [id:foo@bar.baz]
164 id:foo@bar.baz...
165 id:2+2=5
166 id:=_-:/.[]@$%+
167 id:abc)def
168 id:ab\"c def
169 id:\"abc\"def
170 id:\"ab\"\"c\"def
171 id:\"ab c\"def
172 id:\"abc\".def
173 id:\"abc
174 \"
175 id:)
176 id:
177 cid:xxx
178 mid:abc mid:abc/def
179 mid:abc%20def
180 mid:abc. mid:abc, mid:abc;"'
181 test_emacs '(notmuch-show "id:'$gen_msg_id'")
182         (notmuch-test-mark-links)
183         (test-visible-output "OUTPUT.raw")'
184 cat <<EOF >EXPECTED
185 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
186 Subject: id buttonization
187 To: Notmuch Test Suite <test_suite@notmuchmail.org>
188 Date: GENERATED_DATE
189
190 <<id:abc>>
191 <<id:abc.def>>. <<id:abc,def>>, <<id:abc;def>>; <<id:abc:def>>:
192 <<id:foo@bar.?baz>>? <<id:foo@bar!.baz>>!
193 (<<id:foo@bar.baz>>) [<<id:foo@bar.baz>>]
194 <<id:foo@bar.baz>>...
195 <<id:2+2=5>>
196 <<id:=_-:/.[]@$%+>>
197 <<id:abc>>)def
198 <<id:ab"c>> def
199 <<id:"abc">>def
200 <<id:"ab""c">>def
201 <<id:"ab c">>def
202 <<id:"abc">>.def
203 id:"abc
204 "
205 id:)
206 id:
207 cid:xxx
208 <<mid:abc>> <<mid:abc/def>>
209 <<mid:abc%20def>>
210 <<mid:abc>>. <<mid:abc>>, <<mid:abc>>;
211 EOF
212 notmuch_date_sanitize < OUTPUT.raw > OUTPUT
213 test_expect_equal_file EXPECTED OUTPUT
214
215
216 test_begin_subtest "Show handles subprocess errors"
217 cat > notmuch_fail <<EOF
218 #!/bin/sh
219 echo This is output
220 echo This is an error >&2
221 exit 1
222 EOF
223 chmod a+x notmuch_fail
224 test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))
225                (with-current-buffer \"*Messages*\"
226                   (let ((inhibit-read-only t)) (erase-buffer)))
227                (condition-case err
228                    (notmuch-show \"*\")
229                  (error (message \"%s\" (cadr err))))
230                (notmuch-test-wait)
231                (with-current-buffer \"*Messages*\"
232                   (test-output \"MESSAGES\"))
233                (with-current-buffer \"*Notmuch errors*\"
234                   (test-output \"ERROR\"))
235                (test-output))"
236 test_expect_equal "$(notmuch_emacs_error_sanitize notmuch_fail OUTPUT MESSAGES ERROR)" "\
237 === OUTPUT ===
238 === MESSAGES ===
239 This is an error (see *Notmuch errors* for more details)
240 === ERROR ===
241 This is an error
242 command: YYY/notmuch_fail show --format\\=sexp --format-version\\=5 --decrypt\\=true --exclude\\=false \\' \\* \\'
243 exit status: 1
244 stderr:
245 This is an error
246 stdout:
247 This is output"
248
249 test_begin_subtest "text/enriched exploit mitigation"
250 add_message '[content-type]="text/enriched"
251              [body]="
252 <x-display><param>(when (progn (read-only-mode -1) (insert ?p ?0 ?w ?n ?e ?d)) nil)</param>test</x-display>
253 "'
254 test_emacs '(notmuch-show "id:'$gen_msg_id'")
255         (test-visible-output "OUTPUT.raw")'
256 output=$(head -1 OUTPUT.raw|cut -f1-4 -d' ')
257 test_expect_equal "$output" "Notmuch Test Suite <test_suite@notmuchmail.org>"
258
259 test_begin_subtest "multipart/alternative hides html by default"
260 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
261             (test-visible-output)'
262 test_expect_equal_file $EXPECTED/notmuch-show-multipart-alternative OUTPUT
263
264 # switching to the crypto corpus, using gpg from here on:
265 add_gnupg_home
266 add_email_corpus crypto
267
268 test_begin_subtest "show decrypted message"
269 test_emacs '(notmuch-show "id:basic-encrypted@crypto.notmuchmail.org")
270             (test-visible-output)'
271 test_expect_equal_file $EXPECTED/notmuch-show-decrypted-message OUTPUT
272
273 test_begin_subtest "show encrypted rfc822 message"
274 if ${TEST_EMACS} --quick --batch --eval '(kill-emacs (if (version< emacs-version "28") 0 1))'; then
275     test_subtest_known_broken
276 fi
277 test_emacs '(notmuch-show "id:encrypted-rfc822-attachment@crypto.notmuchmail.org")
278             (test-visible-output)'
279 test_expect_code 1 'fgrep "!!!" OUTPUT'
280
281 test_begin_subtest "show undecryptable message"
282 test_emacs '(notmuch-show "id:simple-encrypted@crypto.notmuchmail.org")
283             (test-visible-output)'
284 test_expect_equal_file $EXPECTED/notmuch-show-undecryptable-message OUTPUT
285
286 test_begin_subtest "show encrypted message when not processing crypto"
287 test_emacs '(let ((notmuch-crypto-process-mime nil))
288              (notmuch-show "id:basic-encrypted@crypto.notmuchmail.org")
289              (test-visible-output))'
290 test_expect_equal_file $EXPECTED/notmuch-show-decrypted-message-no-crypto OUTPUT
291
292 test_begin_subtest "notmuch-show with nonexistent CWD"
293 tid=$(notmuch search --limit=1 --output=threads '*' | sed s/thread://)
294 test_emacs "(test-log-error
295               (let ((default-directory \"/nonexistent\"))
296                 (notmuch-show \"$tid\")))"
297 test_expect_equal "$(cat MESSAGES)" "COMPLETE"
298
299 add_email_corpus attachment
300
301 test_begin_subtest "tar not inlined by default"
302 test_emacs '(notmuch-show "id:874llc2bkp.fsf@curie.anarc.at")
303         (test-visible-output "OUTPUT")'
304 cat <<EOF > EXPECTED
305 Antoine Beaupré <anarcat@orangeseeds.org> (2018-03-19) (attachment inbox)
306 Subject: Re: bug: "no top level messages" crash on Zen email loops
307 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
308 Date: Mon, 19 Mar 2018 13:56:54 -0400
309
310 [ multipart/mixed ]
311 [ text/plain ]
312 And obviously I forget the frigging attachment.
313 [ zendesk-email-loop2.tgz: application/x-gtar-compressed ]
314 [ text/plain ]
315
316 PS: don't we have a "you forgot to actually attach the damn file" plugin
317 when we detect the word "attachment" and there's no attach? :p
318 EOF
319 test_expect_equal_file EXPECTED OUTPUT
320
321 test_done