]> git.cworth.org Git - notmuch/blob - test/T450-emacs-show.sh
emacs: Add new option notmuch-search-hide-excluded
[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
104 test_begin_subtest "Hide bodies of messages by height"
105 test_emacs '(let ((notmuch-show-height-limit -1))
106         (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}")
107         (notmuch-test-wait)
108         (notmuch-search-show-thread)
109         (notmuch-test-wait)
110         (test-visible-output))'
111 # folding all messages by height or depth should look the same
112 test_expect_equal_file $EXPECTED/notmuch-show-depth OUTPUT
113
114 test_begin_subtest "Hide bodies of messages; show only leaves."
115 test_emacs '(let ((notmuch-show-height-limit 0))
116         (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}")
117         (notmuch-test-wait)
118         (notmuch-search-show-thread)
119         (notmuch-test-wait)
120         (test-visible-output))'
121 test_expect_equal_file $EXPECTED/notmuch-show-height-0 OUTPUT
122
123 test_begin_subtest "Hide bodies of messages (depth > 1)"
124 test_emacs '(let ((notmuch-show-depth-limit 1))
125         (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}")
126         (notmuch-test-wait)
127         (notmuch-search-show-thread)
128         (notmuch-test-wait)
129         (test-visible-output))'
130 test_expect_equal_file $EXPECTED/notmuch-show-depth-1 OUTPUT
131
132 test_begin_subtest "Hide bodies of messages by size"
133 test_emacs '(let ((notmuch-show-max-text-part-size 1))
134         (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}")
135         (notmuch-test-wait)
136         (notmuch-search-show-thread)
137         (notmuch-test-wait)
138         (test-visible-output))'
139 test_expect_equal_file $EXPECTED/notmuch-show-size OUTPUT
140
141 test_begin_subtest "Hide bodies of messages by size > 450"
142 test_emacs '(let ((notmuch-show-max-text-part-size 450))
143         (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}")
144         (notmuch-test-wait)
145         (notmuch-search-show-thread)
146         (notmuch-test-wait)
147         (test-visible-output))'
148 test_expect_equal_file $EXPECTED/notmuch-show-size-450 OUTPUT
149
150 test_begin_subtest "notmuch-show: elide non-matching messages (w/ notmuch-show-toggle-elide-non-matching)"
151 test_emacs '(let ((notmuch-show-only-matching-messages nil))
152         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
153         (notmuch-test-wait)
154         (notmuch-search-show-thread)
155         (notmuch-test-wait)
156         (notmuch-show-toggle-elide-non-matching)
157         (test-visible-output))'
158 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
159
160 test_begin_subtest "notmuch-show: elide non-matching messages (w/ prefix arg to notmuch-show)"
161 test_emacs '(let ((notmuch-show-only-matching-messages nil))
162         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
163         (notmuch-test-wait)
164         (notmuch-search-show-thread t)
165         (notmuch-test-wait)
166         (test-visible-output))'
167 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
168
169 test_begin_subtest "notmuch-show: disable indentation of thread content (w/ notmuch-show-toggle-thread-indentation)"
170 test_emacs '(notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
171         (notmuch-test-wait)
172         (notmuch-search-show-thread)
173         (notmuch-test-wait)
174         (notmuch-show-toggle-thread-indentation)
175         (test-visible-output)'
176 test_expect_equal_file $EXPECTED/notmuch-show-indent-thread-content-off OUTPUT
177
178 test_begin_subtest "id buttonization"
179 add_message '[body]="
180 id:abc
181 id:abc.def. id:abc,def, id:abc;def; id:abc:def:
182 id:foo@bar.?baz? id:foo@bar!.baz!
183 (id:foo@bar.baz) [id:foo@bar.baz]
184 id:foo@bar.baz...
185 id:2+2=5
186 id:=_-:/.[]@$%+
187 id:abc)def
188 id:ab\"c def
189 id:\"abc\"def
190 id:\"ab\"\"c\"def
191 id:\"ab c\"def
192 id:\"abc\".def
193 id:\"abc
194 \"
195 id:)
196 id:
197 cid:xxx
198 mid:abc mid:abc/def
199 mid:abc%20def
200 mid:abc. mid:abc, mid:abc;"'
201 test_emacs '(notmuch-show "id:'$gen_msg_id'")
202         (notmuch-test-mark-links)
203         (test-visible-output "OUTPUT.raw")'
204 cat <<EOF >EXPECTED
205 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
206 Subject: id buttonization
207 To: Notmuch Test Suite <test_suite@notmuchmail.org>
208 Date: GENERATED_DATE
209
210 <<id:abc>>
211 <<id:abc.def>>. <<id:abc,def>>, <<id:abc;def>>; <<id:abc:def>>:
212 <<id:foo@bar.?baz>>? <<id:foo@bar!.baz>>!
213 (<<id:foo@bar.baz>>) [<<id:foo@bar.baz>>]
214 <<id:foo@bar.baz>>...
215 <<id:2+2=5>>
216 <<id:=_-:/.[]@$%+>>
217 <<id:abc>>)def
218 <<id:ab"c>> def
219 <<id:"abc">>def
220 <<id:"ab""c">>def
221 <<id:"ab c">>def
222 <<id:"abc">>.def
223 id:"abc
224 "
225 id:)
226 id:
227 cid:xxx
228 <<mid:abc>> <<mid:abc/def>>
229 <<mid:abc%20def>>
230 <<mid:abc>>. <<mid:abc>>, <<mid:abc>>;
231 EOF
232 notmuch_date_sanitize < OUTPUT.raw > OUTPUT
233 test_expect_equal_file EXPECTED OUTPUT
234
235
236 test_begin_subtest "Show handles subprocess errors"
237 cat > notmuch_fail <<EOF
238 #!/bin/sh
239 echo This is output
240 echo This is an error >&2
241 exit 1
242 EOF
243 chmod a+x notmuch_fail
244 test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))
245                (with-current-buffer \"*Messages*\"
246                   (let ((inhibit-read-only t)) (erase-buffer)))
247                (condition-case err
248                    (notmuch-show \"*\")
249                  (error (message \"%s\" (cadr err))))
250                (notmuch-test-wait)
251                (with-current-buffer \"*Messages*\"
252                   (test-output \"MESSAGES\"))
253                (with-current-buffer \"*Notmuch errors*\"
254                   (test-output \"ERROR\"))
255                (test-output))"
256 test_expect_equal "$(notmuch_emacs_error_sanitize notmuch_fail OUTPUT MESSAGES ERROR)" "\
257 === OUTPUT ===
258 === MESSAGES ===
259 This is an error (see *Notmuch errors* for more details)
260 === ERROR ===
261 This is an error
262 command: YYY/notmuch_fail show --format\\=sexp --format-version\\=5 --decrypt\\=true --exclude\\=false \\' \\* \\'
263 exit status: 1
264 stderr:
265 This is an error
266 stdout:
267 This is output"
268
269 test_begin_subtest "text/enriched exploit mitigation"
270 add_message '[content-type]="text/enriched"
271              [body]="
272 <x-display><param>(when (progn (read-only-mode -1) (insert ?p ?0 ?w ?n ?e ?d)) nil)</param>test</x-display>
273 "'
274 test_emacs '(notmuch-show "id:'$gen_msg_id'")
275         (test-visible-output "OUTPUT.raw")'
276 output=$(head -1 OUTPUT.raw|cut -f1-4 -d' ')
277 test_expect_equal "$output" "Notmuch Test Suite <test_suite@notmuchmail.org>"
278
279 test_begin_subtest "multipart/alternative hides html by default"
280 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
281             (test-visible-output)'
282 test_expect_equal_file $EXPECTED/notmuch-show-multipart-alternative OUTPUT
283
284 # switching to the crypto corpus, using gpg from here on:
285 add_gnupg_home
286 add_email_corpus crypto
287
288 test_begin_subtest "show decrypted message"
289 test_emacs '(notmuch-show "id:basic-encrypted@crypto.notmuchmail.org")
290             (test-visible-output)'
291 test_expect_equal_file $EXPECTED/notmuch-show-decrypted-message OUTPUT
292
293 test_begin_subtest "show encrypted rfc822 message"
294 if ${TEST_EMACS} --quick --batch --eval '(kill-emacs (if (version< emacs-version "28") 0 1))'; then
295     test_subtest_known_broken
296 fi
297 test_emacs '(notmuch-show "id:encrypted-rfc822-attachment@crypto.notmuchmail.org")
298             (test-visible-output)'
299 test_expect_code 1 'fgrep "!!!" OUTPUT'
300
301 test_begin_subtest "show undecryptable message"
302 test_emacs '(notmuch-show "id:simple-encrypted@crypto.notmuchmail.org")
303             (test-visible-output)'
304 test_expect_equal_file $EXPECTED/notmuch-show-undecryptable-message OUTPUT
305
306 test_begin_subtest "show encrypted message when not processing crypto"
307 test_emacs '(let ((notmuch-crypto-process-mime nil))
308              (notmuch-show "id:basic-encrypted@crypto.notmuchmail.org")
309              (test-visible-output))'
310 test_expect_equal_file $EXPECTED/notmuch-show-decrypted-message-no-crypto OUTPUT
311
312 test_begin_subtest "notmuch-show with nonexistent CWD"
313 tid=$(notmuch search --limit=1 --output=threads '*' | sed s/thread://)
314 test_emacs "(test-log-error
315               (let ((default-directory \"/nonexistent\"))
316                 (notmuch-show \"$tid\")))"
317 test_expect_equal "$(cat MESSAGES)" "COMPLETE"
318
319 add_email_corpus attachment
320
321 test_begin_subtest "tar not inlined by default"
322 test_emacs '(notmuch-show "id:874llc2bkp.fsf@curie.anarc.at")
323         (test-visible-output "OUTPUT")'
324 cat <<EOF > EXPECTED
325 Antoine Beaupré <anarcat@orangeseeds.org> (2018-03-19) (attachment inbox)
326 Subject: Re: bug: "no top level messages" crash on Zen email loops
327 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
328 Date: Mon, 19 Mar 2018 13:56:54 -0400
329
330 [ multipart/mixed ]
331 [ text/plain ]
332 And obviously I forget the frigging attachment.
333 [ zendesk-email-loop2.tgz: application/x-gtar-compressed ]
334 [ text/plain ]
335
336 PS: don't we have a "you forgot to actually attach the damn file" plugin
337 when we detect the word "attachment" and there's no attach? :p
338 EOF
339 test_expect_equal_file EXPECTED OUTPUT
340
341 add_email_corpus duplicate
342
343 ID3=87r2ecrr6x.fsf@zephyr.silentflame.com
344 test_begin_subtest "duplicate=3, subject"
345 test_emacs "(notmuch-show \"id:${ID3}\")
346            (notmuch-show-choose-duplicate 3)
347            (test-visible-output \"OUTPUT\")"
348 output=$(grep "Subject:" OUTPUT)
349 file=$(notmuch search --output=files id:${ID3} | head -n 3 | tail -n 1)
350 subject=$(grep '^Subject:' $file)
351 test_expect_equal "$output" "$subject"
352
353 FILE3=$(notmuch search --output=files --duplicate=3 "id:${ID3}")
354 test_begin_subtest "duplicate=3, stash"
355 test_emacs_expect_t \
356         "(notmuch-show \"id:${ID3}\")
357          (notmuch-show-choose-duplicate 3)
358          (notmuch-show-stash-filename)
359          (notmuch-test-expect-equal (list (car kill-ring)) (list \"${FILE3}\"))"
360
361 test_begin_subtest "duplicate=0"
362 test_emacs "(test-log-error
363               (notmuch-show \"id:${ID3}\")
364               (notmuch-show-choose-duplicate 0))"
365 cat <<EOF > EXPECTED
366 (error Duplicate 0 out of range [1,5])
367 EOF
368 test_expect_equal_file EXPECTED MESSAGES
369
370 test_begin_subtest "duplicate=1000"
371 test_emacs "(test-log-error
372               (notmuch-show \"id:${ID3}\")
373               (notmuch-show-choose-duplicate 1000))"
374 cat <<EOF > EXPECTED
375 (error Duplicate 1000 out of range [1,5])
376 EOF
377 test_expect_equal_file EXPECTED MESSAGES
378 test_begin_subtest "duplicate=4"
379 test_emacs "(notmuch-show \"id:${ID3}\")
380            (notmuch-show-choose-duplicate 4)
381            (test-visible-output \"OUTPUT\")"
382 test_expect_equal_file_nonempty $EXPECTED/notmuch-show-duplicate-4 OUTPUT
383
384 FILE4=$(notmuch search --output=files --duplicate=4 "id:${ID3}")
385 test_begin_subtest "duplicate=4, raw"
386 test_emacs "(notmuch-show \"id:${ID3}\")
387            (notmuch-show-choose-duplicate 4)
388            (notmuch-show-view-raw-message)
389            (test-visible-output \"OUTPUT\")"
390 subject4=$(grep '^Subject:' $FILE4)
391 subject=$(grep '^Subject:' OUTPUT)
392 test_expect_equal "$subject4" "$subject"
393
394 test_done