]> git.notmuchmail.org Git - notmuch/blob - test/T450-emacs-show.sh
6266ffc54b48bea31bae15216ccdc96c0a4e5d88
[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-show: don't elide non-matching messages"
66 test_emacs '(let ((notmuch-show-only-matching-messages nil))
67         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
68         (notmuch-test-wait)
69         (notmuch-search-show-thread)
70         (notmuch-test-wait)
71         (test-visible-output))'
72 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-off OUTPUT
73
74 test_begin_subtest "notmuch-show: elide non-matching messages"
75 test_emacs '(let ((notmuch-show-only-matching-messages t))
76         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
77         (notmuch-test-wait)
78         (notmuch-search-show-thread)
79         (notmuch-test-wait)
80         (test-visible-output))'
81 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
82
83 test_begin_subtest "notmuch-show: elide non-matching messages (w/ notmuch-show-toggle-elide-non-matching)"
84 test_emacs '(let ((notmuch-show-only-matching-messages nil))
85         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
86         (notmuch-test-wait)
87         (notmuch-search-show-thread)
88         (notmuch-test-wait)
89         (notmuch-show-toggle-elide-non-matching)
90         (test-visible-output))'
91 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
92
93 test_begin_subtest "notmuch-show: elide non-matching messages (w/ prefix arg to notmuch-show)"
94 test_emacs '(let ((notmuch-show-only-matching-messages nil))
95         (notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
96         (notmuch-test-wait)
97         (notmuch-search-show-thread t)
98         (notmuch-test-wait)
99         (test-visible-output))'
100 test_expect_equal_file $EXPECTED/notmuch-show-elide-non-matching-messages-on OUTPUT
101
102 test_begin_subtest "notmuch-show: disable indentation of thread content (w/ notmuch-show-toggle-thread-indentation)"
103 test_emacs '(notmuch-search "from:lars@seas.harvard.edu and subject:\"Maildir storage\"")
104         (notmuch-test-wait)
105         (notmuch-search-show-thread)
106         (notmuch-test-wait)
107         (notmuch-show-toggle-thread-indentation)
108         (test-visible-output)'
109 test_expect_equal_file $EXPECTED/notmuch-show-indent-thread-content-off OUTPUT
110
111 test_begin_subtest "id buttonization"
112 add_message '[body]="
113 id:abc
114 id:abc.def. id:abc,def, id:abc;def; id:abc:def:
115 id:foo@bar.?baz? id:foo@bar!.baz!
116 (id:foo@bar.baz) [id:foo@bar.baz]
117 id:foo@bar.baz...
118 id:2+2=5
119 id:=_-:/.[]@$%+
120 id:abc)def
121 id:ab\"c def
122 id:\"abc\"def
123 id:\"ab\"\"c\"def
124 id:\"ab c\"def
125 id:\"abc\".def
126 id:\"abc
127 \"
128 id:)
129 id:
130 cid:xxx
131 mid:abc mid:abc/def
132 mid:abc%20def
133 mid:abc. mid:abc, mid:abc;"'
134 test_emacs '(notmuch-show "id:'$gen_msg_id'")
135         (notmuch-test-mark-links)
136         (test-visible-output "OUTPUT.raw")'
137 cat <<EOF >EXPECTED
138 Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
139 Subject: id buttonization
140 To: Notmuch Test Suite <test_suite@notmuchmail.org>
141 Date: GENERATED_DATE
142
143 <<id:abc>>
144 <<id:abc.def>>. <<id:abc,def>>, <<id:abc;def>>; <<id:abc:def>>:
145 <<id:foo@bar.?baz>>? <<id:foo@bar!.baz>>!
146 (<<id:foo@bar.baz>>) [<<id:foo@bar.baz>>]
147 <<id:foo@bar.baz>>...
148 <<id:2+2=5>>
149 <<id:=_-:/.[]@$%+>>
150 <<id:abc>>)def
151 <<id:ab"c>> def
152 <<id:"abc">>def
153 <<id:"ab""c">>def
154 <<id:"ab c">>def
155 <<id:"abc">>.def
156 id:"abc
157 "
158 id:)
159 id:
160 cid:xxx
161 <<mid:abc>> <<mid:abc/def>>
162 <<mid:abc%20def>>
163 <<mid:abc>>. <<mid:abc>>, <<mid:abc>>;
164 EOF
165 notmuch_date_sanitize < OUTPUT.raw > OUTPUT
166 test_expect_equal_file EXPECTED OUTPUT
167
168
169 test_begin_subtest "Show handles subprocess errors"
170 cat > notmuch_fail <<EOF
171 #!/bin/sh
172 echo This is output
173 echo This is an error >&2
174 exit 1
175 EOF
176 chmod a+x notmuch_fail
177 test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))
178                (with-current-buffer \"*Messages*\"
179                   (let ((inhibit-read-only t)) (erase-buffer)))
180                (condition-case err
181                    (notmuch-show \"*\")
182                  (error (message \"%s\" (cadr err))))
183                (notmuch-test-wait)
184                (with-current-buffer \"*Messages*\"
185                   (test-output \"MESSAGES\"))
186                (with-current-buffer \"*Notmuch errors*\"
187                   (test-output \"ERROR\"))
188                (test-output))"
189 test_expect_equal "$(notmuch_emacs_error_sanitize notmuch_fail OUTPUT MESSAGES ERROR)" "\
190 === OUTPUT ===
191 === MESSAGES ===
192 This is an error (see *Notmuch errors* for more details)
193 === ERROR ===
194 This is an error
195 command: YYY/notmuch_fail show --format\\=sexp --format-version\\=5 --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 encrypted rfc822 message"
223 if ${TEST_EMACS} --quick --batch --eval '(kill-emacs (if (version< emacs-version "28") 0 1))'; then
224     test_subtest_known_broken
225 fi
226 test_emacs '(notmuch-show "id:encrypted-rfc822-attachment@crypto.notmuchmail.org")
227             (test-visible-output)'
228 test_expect_code 1 'fgrep "!!!" OUTPUT'
229
230 test_begin_subtest "show undecryptable message"
231 test_emacs '(notmuch-show "id:simple-encrypted@crypto.notmuchmail.org")
232             (test-visible-output)'
233 test_expect_equal_file $EXPECTED/notmuch-show-undecryptable-message OUTPUT
234
235 test_begin_subtest "show encrypted message when not processing crypto"
236 test_emacs '(let ((notmuch-crypto-process-mime nil))
237              (notmuch-show "id:basic-encrypted@crypto.notmuchmail.org")
238              (test-visible-output))'
239 test_expect_equal_file $EXPECTED/notmuch-show-decrypted-message-no-crypto OUTPUT
240
241 test_begin_subtest "notmuch-show with nonexistent CWD"
242 tid=$(notmuch search --limit=1 --output=threads '*' | sed s/thread://)
243 test_emacs "(test-log-error
244               (let ((default-directory \"/nonexistent\"))
245                 (notmuch-show \"$tid\")))"
246 test_expect_equal "$(cat MESSAGES)" "COMPLETE"
247
248 add_email_corpus attachment
249
250 test_begin_subtest "tar not inlined by default"
251 test_emacs '(notmuch-show "id:874llc2bkp.fsf@curie.anarc.at")
252         (test-visible-output "OUTPUT")'
253 cat <<EOF > EXPECTED
254 Antoine Beaupré <anarcat@orangeseeds.org> (2018-03-19) (attachment inbox)
255 Subject: Re: bug: "no top level messages" crash on Zen email loops
256 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
257 Date: Mon, 19 Mar 2018 13:56:54 -0400
258
259 [ multipart/mixed ]
260 [ text/plain ]
261 And obviously I forget the frigging attachment.
262 [ zendesk-email-loop2.tgz: application/x-gtar-compressed ]
263 [ text/plain ]
264
265 PS: don't we have a "you forgot to actually attach the damn file" plugin
266 when we detect the word "attachment" and there's no attach? :p
267 EOF
268 test_expect_equal_file EXPECTED OUTPUT
269
270 test_done