test: modify multipart test to use test_expect_equal_file
[notmuch] / test / multipart
1 #!/usr/bin/env bash
2 test_description="output of multipart message"
3 . ./test-lib.sh
4
5 cat <<EOF > ${MAIL_DIR}/multipart
6 From: Carl Worth <cworth@cworth.org>
7 To: cworth@cworth.org
8 Subject: Multipart message
9 Date: Tue, 05 Jan 2001 15:43:57 -0000
10 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
11 Message-ID: <87liy5ap00.fsf@yoom.home.cworth.org>
12 MIME-Version: 1.0
13 Content-Type: multipart/signed; boundary="==-=-=";
14         micalg=pgp-sha1; protocol="application/pgp-signature"
15
16 --==-=-=
17 Content-Type: multipart/mixed; boundary="=-=-="
18
19 --=-=-=
20 Content-Type: message/rfc822
21 Content-Disposition: inline
22
23 From: Carl Worth <cworth@cworth.org>
24 To: cworth@cworth.org
25 Subject: html message
26 Date: Tue, 05 Jan 2001 15:42:57 -0000
27 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
28 Message-ID: <87liy5ap01.fsf@yoom.home.cworth.org>
29 MIME-Version: 1.0
30 Content-Type: text/html
31
32 <p>This is an embedded message, with a single html part.</p>
33
34 --=-=-=
35 Content-Disposition: attachment; filename=attachment
36
37 This is a text attachment.
38
39 --=-=-=
40
41 And this message is signed.
42
43 -Carl
44
45 --=-=-=--
46
47 --==-=-=
48 Content-Type: application/pgp-signature
49
50 -----BEGIN PGP SIGNATURE-----
51 Version: GnuPG v1.4.11 (GNU/Linux)
52
53 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
54 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
55 =zkga
56 -----END PGP SIGNATURE-----
57 --==-=-=--
58 EOF
59
60 cat <<EOF > ${MAIL_DIR}/base64-part-with-crlf
61 From: Carl Worth <cworth@cworth.org>
62 To: cworth@cworth.org
63 Subject: Test message with a BASE64 encoded binary containing CRLF pair
64 Date: Tue, 05 Jan 2001 15:43:57 -0000
65 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
66 Message-ID: <base64-part-with-crlf>
67 MIME-Version: 1.0
68 Content-Type: multipart/mixed; boundary="==-=-=";
69
70 --==-=-=
71
72 The attached BASE64-encoded part expands to a binary containing a CRLF
73 pair (that is one bye of 0x0D followed by one byte of 0x0A). This is
74 designed to ensure that notmuch is not corrupting the output of this
75 part by converting the CRLF pair to an LF only (as would be appropriate
76 for display of a text part on a Linux system, for example).
77
78 The part should be a 3-byte file with the following sequence of 3
79 hexadecimal bytes:
80
81         EF 0D 0A
82
83 --==-=-=
84 Content-Type: application/octet-stream
85 Content-Disposition: attachment; filename=crlf.bin
86 Content-Transfer-Encoding: base64
87
88 7w0K
89 --==-=-=--
90 EOF
91 increment_mtime "$MAIL_DIR"
92 notmuch new > /dev/null
93
94 test_begin_subtest "--format=text --part=0, full message"
95 notmuch show --format=text --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
96 cat <<EOF >EXPECTED
97 \fmessage{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 filename:${MAIL_DIR}/multipart
98 \fheader{
99 Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed unread)
100 Subject: Multipart message
101 From: Carl Worth <cworth@cworth.org>
102 To: cworth@cworth.org
103 Date: Tue, 05 Jan 2001 15:43:57 -0000
104 \fheader}
105 \fbody{
106 \fpart{ ID: 1, Content-type: multipart/signed
107 \fpart{ ID: 2, Content-type: multipart/mixed
108 \fpart{ ID: 3, Content-type: message/rfc822
109 \fpart{ ID: 4, Content-type: text/html
110 Non-text part: text/html
111 \fpart}
112 \fpart}
113 \fattachment{ ID: 5, Content-type: text/plain
114 Attachment: attachment (text/plain)
115 This is a text attachment.
116 \fattachment}
117 \fpart{ ID: 6, Content-type: text/plain
118 And this message is signed.
119
120 -Carl
121 \fpart}
122 \fpart}
123 \fpart{ ID: 7, Content-type: application/pgp-signature
124 Non-text part: application/pgp-signature
125 \fpart}
126 \fpart}
127 \fbody}
128 \fmessage}
129 EOF
130 test_expect_equal_file OUTPUT EXPECTED
131
132 test_begin_subtest "--format=text --part=0, full message"
133 notmuch show --format=text --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
134 cat <<EOF >EXPECTED
135 \fmessage{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 filename:${MAIL_DIR}/multipart
136 \fheader{
137 Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed unread)
138 Subject: Multipart message
139 From: Carl Worth <cworth@cworth.org>
140 To: cworth@cworth.org
141 Date: Tue, 05 Jan 2001 15:43:57 -0000
142 \fheader}
143 \fbody{
144 \fpart{ ID: 1, Content-type: multipart/signed
145 \fpart{ ID: 2, Content-type: multipart/mixed
146 \fpart{ ID: 3, Content-type: message/rfc822
147 \fpart{ ID: 4, Content-type: text/html
148 Non-text part: text/html
149 \fpart}
150 \fpart}
151 \fattachment{ ID: 5, Content-type: text/plain
152 Attachment: attachment (text/plain)
153 This is a text attachment.
154 \fattachment}
155 \fpart{ ID: 6, Content-type: text/plain
156 And this message is signed.
157
158 -Carl
159 \fpart}
160 \fpart}
161 \fpart{ ID: 7, Content-type: application/pgp-signature
162 Non-text part: application/pgp-signature
163 \fpart}
164 \fpart}
165 \fbody}
166 \fmessage}
167 EOF
168 test_expect_equal_file OUTPUT EXPECTED
169
170 test_begin_subtest "--format=text --part=2, multipart/mixed"
171 notmuch show --format=text --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
172 cat <<EOF >EXPECTED
173 \fpart{ ID: 2, Content-type: multipart/mixed
174 \fpart{ ID: 3, Content-type: message/rfc822
175 \fpart{ ID: 4, Content-type: text/html
176 Non-text part: text/html
177 \fpart}
178 \fpart}
179 \fattachment{ ID: 5, Content-type: text/plain
180 Attachment: attachment (text/plain)
181 This is a text attachment.
182 \fattachment}
183 \fpart{ ID: 6, Content-type: text/plain
184 And this message is signed.
185
186 -Carl
187 \fpart}
188 \fpart}
189 EOF
190 test_expect_equal_file OUTPUT EXPECTED
191
192 test_begin_subtest "--format=text --part=3, rfc822 multipart"
193 notmuch show --format=text --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
194 cat <<EOF >EXPECTED
195 \fpart{ ID: 3, Content-type: message/rfc822
196 \fpart{ ID: 4, Content-type: text/html
197 Non-text part: text/html
198 \fpart}
199 \fpart}
200 EOF
201 test_expect_equal_file OUTPUT EXPECTED
202
203 test_begin_subtest "--format=text --part=4, html part"
204 notmuch show --format=text --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
205 cat <<EOF >EXPECTED
206 \fpart{ ID: 4, Content-type: text/html
207 Non-text part: text/html
208 \fpart}
209 EOF
210 test_expect_equal_file OUTPUT EXPECTED
211
212 test_begin_subtest "--format=text --part=5, inline attachement"
213 notmuch show --format=text --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
214 cat <<EOF >EXPECTED
215 \fattachment{ ID: 5, Content-type: text/plain
216 Attachment: attachment (text/plain)
217 This is a text attachment.
218 \fattachment}
219 EOF
220 test_expect_equal_file OUTPUT EXPECTED
221
222 test_begin_subtest "--format=text --part=6, plain text part"
223 notmuch show --format=text --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
224 cat <<EOF >EXPECTED
225 \fpart{ ID: 6, Content-type: text/plain
226 And this message is signed.
227
228 -Carl
229 \fpart}
230 EOF
231 test_expect_equal_file OUTPUT EXPECTED
232
233 test_begin_subtest "--format=text --part=7, pgp signature (unverified)"
234 notmuch show --format=text --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
235 cat <<EOF >EXPECTED
236 \fpart{ ID: 7, Content-type: application/pgp-signature
237 Non-text part: application/pgp-signature
238 \fpart}
239 EOF
240 test_expect_equal_file OUTPUT EXPECTED
241
242 test_expect_success \
243     "--format=text --part=8, no part, expect error" \
244     "notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
245
246 test_begin_subtest "--format=json --part=0, full message"
247 output=$(notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org')
248 test_expect_equal "$output" \
249 '{"id": "87liy5ap00.fsf@yoom.home.cworth.org", "match": true, "filename": "'"${MAIL_DIR}/multipart"'", "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["attachment","inbox","signed","unread"], "headers": {"Subject": "Multipart message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Cc": "", "Bcc": "", "Date": "Tue, 05 Jan 2001 15:43:57 -0000"}, "body": [{"id": 1, "content-type": "multipart/signed", "content": [{"id": 2, "content-type": "multipart/mixed", "content": [{"id": 3, "content-type": "message/rfc822", "content": [{"id": 4, "content-type": "text/html"}]}, {"id": 5, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}, {"id": 6, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}, {"id": 7, "content-type": "application/pgp-signature"}]}]}'
250
251 test_begin_subtest "--format=json --part=1, message body"
252 output=$(notmuch show --format=json --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org')
253 test_expect_equal "$output" \
254 '{"id": 1, "content-type": "multipart/signed", "content": [{"id": 2, "content-type": "multipart/mixed", "content": [{"id": 3, "content-type": "message/rfc822", "content": [{"id": 4, "content-type": "text/html"}]}, {"id": 5, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}, {"id": 6, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}, {"id": 7, "content-type": "application/pgp-signature"}]}'
255
256 test_begin_subtest "--format=json --part=2, multipart/mixed"
257 output=$(notmuch show --format=json --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org')
258 test_expect_equal "$output" \
259 '{"id": 2, "content-type": "multipart/mixed", "content": [{"id": 3, "content-type": "message/rfc822", "content": [{"id": 4, "content-type": "text/html"}]}, {"id": 5, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}, {"id": 6, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}'
260 test_expect_equal_file OUTPUT EXPECTED
261
262 test_begin_subtest "--format=json --part=3, rfc822 multipart"
263 output=$(notmuch show --format=json --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org')
264 test_expect_equal "$output" \
265 '{"id": 3, "content-type": "message/rfc822", "content": [{"id": 4, "content-type": "text/html"}]}'
266 test_expect_equal_file OUTPUT EXPECTED
267
268 test_begin_subtest "--format=json --part=4, html part"
269 output=$(notmuch show --format=json --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org')
270 test_expect_equal "$output" \
271 '{"id": 4, "content-type": "text/html"}'
272
273 test_begin_subtest "--format=json --part=5, inline attachment"
274 output=$(notmuch show --format=json --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org')
275 test_expect_equal "$output" \
276 '{"id": 5, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}'
277
278 test_begin_subtest "--format=json --part=6, plain text part"
279 output=$(notmuch show --format=json --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org')
280 test_expect_equal "$output" \
281 '{"id": 6, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}'
282
283 test_begin_subtest "--format=json --part=7, pgp signature (unverified)"
284 output=$(notmuch show --format=json --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org')
285 test_expect_equal "$output" \
286 '{"id": 7, "content-type": "application/pgp-signature"}'
287
288 test_expect_success \
289     "--format=json --part=8, no part, expect error" \
290     "notmuch show --format=json --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
291
292 test_begin_subtest "--format=raw"
293 notmuch show --format=raw 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
294 test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart
295
296 test_begin_subtest "--format=raw --part=0, full message"
297 notmuch show --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
298 test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart
299
300 test_begin_subtest "--format=raw --part=1, message body"
301 notmuch show --format=raw --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
302 # output should *not* include newline
303 echo >>OUTPUT
304 cat <<EOF >EXPECTED
305 <p>This is an embedded message, with a single html part.</p>
306 This is a text attachment.
307 And this message is signed.
308
309 -Carl
310 -----BEGIN PGP SIGNATURE-----
311 Version: GnuPG v1.4.11 (GNU/Linux)
312
313 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
314 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
315 =zkga
316 -----END PGP SIGNATURE-----
317 EOF
318 test_expect_equal_file OUTPUT EXPECTED
319
320 test_begin_subtest "--format=raw --part=2, multipart/mixed"
321 notmuch show --format=raw --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
322 cat <<EOF >EXPECTED
323 <p>This is an embedded message, with a single html part.</p>
324 This is a text attachment.
325 And this message is signed.
326
327 -Carl
328 EOF
329 test_expect_equal_file OUTPUT EXPECTED
330
331 test_begin_subtest "--format=raw --part=3, rfc822 multipart"
332 notmuch show --format=raw --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
333 cat <<EOF >EXPECTED
334 <p>This is an embedded message, with a single html part.</p>
335 EOF
336 test_expect_equal_file OUTPUT EXPECTED
337
338 test_begin_subtest "--format=raw --part=4, html part"
339 notmuch show --format=raw --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
340 cat <<EOF >EXPECTED
341 <p>This is an embedded message, with a single html part.</p>
342 EOF
343 test_expect_equal_file OUTPUT EXPECTED
344
345 test_begin_subtest "--format=raw --part=5, inline attachment"
346 notmuch show --format=raw --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
347 cat <<EOF >EXPECTED
348 This is a text attachment.
349 EOF
350 test_expect_equal_file OUTPUT EXPECTED
351
352 test_begin_subtest "--format=raw --part=6, plain text part"
353 notmuch show --format=raw --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
354 cat <<EOF >EXPECTED
355 And this message is signed.
356
357 -Carl
358 EOF
359 test_expect_equal_file OUTPUT EXPECTED
360
361 test_begin_subtest "--format=raw --part=7, pgp signature (unverified)"
362 notmuch show --format=raw --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
363 # output should *not* include newline
364 echo >>OUTPUT
365 cat <<EOF >EXPECTED
366 -----BEGIN PGP SIGNATURE-----
367 Version: GnuPG v1.4.11 (GNU/Linux)
368
369 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
370 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
371 =zkga
372 -----END PGP SIGNATURE-----
373 EOF
374 test_expect_equal_file OUTPUT EXPECTED
375
376 test_expect_success \
377     "--format=raw --part=8, no part, expect error" \
378     "notmuch show --format=raw --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
379
380 test_begin_subtest "--format=mbox"
381 notmuch show --format=mbox 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
382 printf "From cworth@cworth.org Fri Jan  5 15:43:57 2001\n" >EXPECTED
383 cat "${MAIL_DIR}"/multipart >>EXPECTED
384 # mbox output is expected to include a blank line
385 echo >>EXPECTED
386 test_expect_equal_file OUTPUT EXPECTED
387
388 test_expect_success \
389     "--format=mbox --part=1, incompatible, expect error" \
390     "! notmuch show --format=mbox --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
391
392 test_begin_subtest "'notmuch reply' to a multipart message"
393 notmuch reply 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
394 cat <<EOF >EXPECTED
395 From: Notmuch Test Suite <test_suite@notmuchmail.org>
396 Subject: Re: Multipart message
397 To: Carl Worth <cworth@cworth.org>, cworth@cworth.org
398 In-Reply-To: <87liy5ap00.fsf@yoom.home.cworth.org>
399 References: <87liy5ap00.fsf@yoom.home.cworth.org>
400
401 On Tue, 05 Jan 2001 15:43:57 -0000, Carl Worth <cworth@cworth.org> wrote:
402 Non-text part: multipart/signed
403 Non-text part: multipart/mixed
404 Non-text part: message/rfc822
405 Non-text part: text/html
406 > This is a text attachment.
407 > And this message is signed.
408
409 > -Carl
410 Non-text part: application/pgp-signature
411 EOF
412 test_expect_equal_file OUTPUT EXPECTED
413
414 test_begin_subtest "'notmuch show --part' does not corrupt a part with CRLF pair"
415 notmuch show --format=raw --part=3 id:base64-part-with-crlf > crlf.out
416 echo -n -e "\xEF\x0D\x0A" > crlf.expected
417 test_expect_equal_file crlf.out crlf.expected
418
419 test_done