]> git.notmuchmail.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 "notmuch-show: elide non-matching messages (w/ notmuch-show-toggle-elide-non-matching)"
95 test_emacs '(let ((notmuch-show-only-matching-messages nil))
96         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
97         (notmuch-test-wait)
98         (notmuch-search-show-thread)
99         (notmuch-test-wait)
100         (notmuch-show-toggle-elide-non-matching)
101         (test-visible-output))'
102 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
103
104 test_begin_subtest "notmuch-show: elide non-matching messages (w/ prefix arg to notmuch-show)"
105 test_emacs '(let ((notmuch-show-only-matching-messages nil))
106         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
107         (notmuch-test-wait)
108         (notmuch-search-show-thread t)
109         (notmuch-test-wait)
110         (test-visible-output))'
111 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
112
113 test_begin_subtest "notmuch-show: disable indentation of thread content (w/ notmuch-show-toggle-thread-indentation)"
114 test_emacs '(notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
115         (notmuch-test-wait)
116         (notmuch-search-show-thread)
117         (notmuch-test-wait)
118         (notmuch-show-toggle-thread-indentation)
119         (test-visible-output)'
120 test_expect_equal_file $EXPECTED/notmuch-show-indent-thread-content-off OUTPUT
121
122 test_begin_subtest "id buttonization"
123 add_message '[body]="
124 id:abc
125 id:abc.def. id:abc,def, id:abc;def; id:abc:def:
126 id:foo@bar.?baz? id:foo@bar!.baz!
127 (id:foo@bar.baz) [id:foo@bar.baz]
128 id:foo@bar.baz...
129 id:2+2=5
130 id:=_-:/.[]@$%+
131 id:abc)def
132 id:ab\"c def
133 id:\"abc\"def
134 id:\"ab\"\"c\"def
135 id:\"ab c\"def
136 id:\"abc\".def
137 id:\"abc
138 \"
139 id:)
140 id:
141 cid:xxx
142 mid:abc mid:abc/def
143 mid:abc%20def
144 mid:abc. mid:abc, mid:abc;"'
145 test_emacs '(notmuch-show "id:'$gen_msg_id'")
146         (notmuch-test-mark-links)
147         (test-visible-output "OUTPUT.raw")'
148 cat <<EOF >EXPECTED
149 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
150 Subject: id buttonization
151 To: Notmuch Test Suite <test_suite@notmuchmail.org>
152 Date: GENERATED_DATE
153
154 <<id:abc>>
155 <<id:abc.def>>. <<id:abc,def>>, <<id:abc;def>>; <<id:abc:def>>:
156 <<id:foo@bar.?baz>>? <<id:foo@bar!.baz>>!
157 (<<id:foo@bar.baz>>) [<<id:foo@bar.baz>>]
158 <<id:foo@bar.baz>>...
159 <<id:2+2=5>>
160 <<id:=_-:/.[]@$%+>>
161 <<id:abc>>)def
162 <<id:ab"c>> def
163 <<id:"abc">>def
164 <<id:"ab""c">>def
165 <<id:"ab c">>def
166 <<id:"abc">>.def
167 id:"abc
168 "
169 id:)
170 id:
171 cid:xxx
172 <<mid:abc>> <<mid:abc/def>>
173 <<mid:abc%20def>>
174 <<mid:abc>>. <<mid:abc>>, <<mid:abc>>;
175 EOF
176 notmuch_date_sanitize < OUTPUT.raw > OUTPUT
177 test_expect_equal_file EXPECTED OUTPUT
178
179
180 test_begin_subtest "Show handles subprocess errors"
181 cat > notmuch_fail <<EOF
182 #!/bin/sh
183 echo This is output
184 echo This is an error >&2
185 exit 1
186 EOF
187 chmod a+x notmuch_fail
188 test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))
189                (with-current-buffer \"*Messages*\"
190                   (let ((inhibit-read-only t)) (erase-buffer)))
191                (condition-case err
192                    (notmuch-show \"*\")
193                  (error (message \"%s\" (cadr err))))
194                (notmuch-test-wait)
195                (with-current-buffer \"*Messages*\"
196                   (test-output \"MESSAGES\"))
197                (with-current-buffer \"*Notmuch errors*\"
198                   (test-output \"ERROR\"))
199                (test-output))"
200 test_expect_equal "$(notmuch_emacs_error_sanitize notmuch_fail OUTPUT MESSAGES ERROR)" "\
201 === OUTPUT ===
202 === MESSAGES ===
203 This is an error (see *Notmuch errors* for more details)
204 === ERROR ===
205 This is an error
206 command: YYY/notmuch_fail show --format\\=sexp --format-version\\=5 --decrypt\\=true --exclude\\=false \\' \\* \\'
207 exit status: 1
208 stderr:
209 This is an error
210 stdout:
211 This is output"
212
213 test_begin_subtest "text/enriched exploit mitigation"
214 add_message '[content-type]="text/enriched"
215              [body]="
216 <x-display><param>(when (progn (read-only-mode -1) (insert ?p ?0 ?w ?n ?e ?d)) nil)</param>test</x-display>
217 "'
218 test_emacs '(notmuch-show "id:'$gen_msg_id'")
219         (test-visible-output "OUTPUT.raw")'
220 output=$(head -1 OUTPUT.raw|cut -f1-4 -d' ')
221 test_expect_equal "$output" "Notmuch Test Suite <test_suite@notmuchmail.org>"
222
223 test_begin_subtest "multipart/alternative hides html by default"
224 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
225             (test-visible-output)'
226 test_expect_equal_file $EXPECTED/notmuch-show-multipart-alternative OUTPUT
227
228 # switching to the crypto corpus, using gpg from here on:
229 add_gnupg_home
230 add_email_corpus crypto
231
232 test_begin_subtest "show decrypted message"
233 test_emacs '(notmuch-show "id:basic-encrypted@crypto.notmuchmail.org")
234             (test-visible-output)'
235 test_expect_equal_file $EXPECTED/notmuch-show-decrypted-message OUTPUT
236
237 test_begin_subtest "show encrypted rfc822 message"
238 if ${TEST_EMACS} --quick --batch --eval '(kill-emacs (if (version< emacs-version "28") 0 1))'; then
239     test_subtest_known_broken
240 fi
241 test_emacs '(notmuch-show "id:encrypted-rfc822-attachment@crypto.notmuchmail.org")
242             (test-visible-output)'
243 test_expect_code 1 'fgrep "!!!" OUTPUT'
244
245 test_begin_subtest "show undecryptable message"
246 test_emacs '(notmuch-show "id:simple-encrypted@crypto.notmuchmail.org")
247             (test-visible-output)'
248 test_expect_equal_file $EXPECTED/notmuch-show-undecryptable-message OUTPUT
249
250 test_begin_subtest "show encrypted message when not processing crypto"
251 test_emacs '(let ((notmuch-crypto-process-mime nil))
252              (notmuch-show "id:basic-encrypted@crypto.notmuchmail.org")
253              (test-visible-output))'
254 test_expect_equal_file $EXPECTED/notmuch-show-decrypted-message-no-crypto OUTPUT
255
256 test_begin_subtest "notmuch-show with nonexistent CWD"
257 tid=$(notmuch search --limit=1 --output=threads '*' | sed s/thread://)
258 test_emacs "(test-log-error
259               (let ((default-directory \"/nonexistent\"))
260                 (notmuch-show \"$tid\")))"
261 test_expect_equal "$(cat MESSAGES)" "COMPLETE"
262
263 add_email_corpus attachment
264
265 test_begin_subtest "tar not inlined by default"
266 test_emacs '(notmuch-show "id:874llc2bkp.fsf@curie.anarc.at")
267         (test-visible-output "OUTPUT")'
268 cat <<EOF > EXPECTED
269 Antoine Beaupré <anarcat@orangeseeds.org> (2018-03-19) (attachment inbox)
270 Subject: Re: bug: "no top level messages" crash on Zen email loops
271 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
272 Date: Mon, 19 Mar 2018 13:56:54 -0400
273
274 [ multipart/mixed ]
275 [ text/plain ]
276 And obviously I forget the frigging attachment.
277 [ zendesk-email-loop2.tgz: application/x-gtar-compressed ]
278 [ text/plain ]
279
280 PS: don't we have a "you forgot to actually attach the damn file" plugin
281 when we detect the word "attachment" and there's no attach? :p
282 EOF
283 test_expect_equal_file EXPECTED OUTPUT
284
285 test_done