Merge branch 'release'
[notmuch] / test / multipart
1 #!/usr/bin/env bash
2 test_description="output of multipart message"
3 . ./test-lib.sh
4
5 cat <<EOF > embedded_message
6 From: Carl Worth <cworth@cworth.org>
7 To: cworth@cworth.org
8 Subject: html message
9 Date: Fri, 05 Jan 2001 15:42:57 +0000
10 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
11 Message-ID: <87liy5ap01.fsf@yoom.home.cworth.org>
12 MIME-Version: 1.0
13 Content-Type: multipart/alternative; boundary="==-=-=="
14
15 --==-=-==
16 Content-Type: text/html
17
18 <p>This is an embedded message, with a multipart/alternative part.</p>
19
20 --==-=-==
21 Content-Type: text/plain
22
23 This is an embedded message, with a multipart/alternative part.
24
25 --==-=-==--
26 EOF
27
28 cat <<EOF > ${MAIL_DIR}/multipart
29 From: Carl Worth <cworth@cworth.org>
30 To: cworth@cworth.org
31 Subject: Multipart message
32 Date: Fri, 05 Jan 2001 15:43:57 +0000
33 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
34 Message-ID: <87liy5ap00.fsf@yoom.home.cworth.org>
35 MIME-Version: 1.0
36 Content-Type: multipart/signed; boundary="==-=-=";
37         micalg=pgp-sha1; protocol="application/pgp-signature"
38
39 --==-=-=
40 Content-Type: multipart/mixed; boundary="=-=-="
41
42 --=-=-=
43 Content-Type: message/rfc822
44 Content-Disposition: inline
45
46 EOF
47 cat embedded_message >> ${MAIL_DIR}/multipart
48 cat <<EOF >> ${MAIL_DIR}/multipart
49 --=-=-=
50 Content-Disposition: attachment; filename=attachment
51
52 This is a text attachment.
53
54 --=-=-=
55
56 And this message is signed.
57
58 -Carl
59
60 --=-=-=--
61
62 --==-=-=
63 Content-Type: application/pgp-signature
64
65 -----BEGIN PGP SIGNATURE-----
66 Version: GnuPG v1.4.11 (GNU/Linux)
67
68 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
69 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
70 =zkga
71 -----END PGP SIGNATURE-----
72 --==-=-=--
73 EOF
74
75 cat <<EOF > ${MAIL_DIR}/base64-part-with-crlf
76 From: Carl Worth <cworth@cworth.org>
77 To: cworth@cworth.org
78 Subject: Test message with a BASE64 encoded binary containing CRLF pair
79 Date: Fri, 05 Jan 2001 15:43:57 +0000
80 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
81 Message-ID: <base64-part-with-crlf>
82 MIME-Version: 1.0
83 Content-Type: multipart/mixed; boundary="==-=-=";
84
85 --==-=-=
86
87 The attached BASE64-encoded part expands to a binary containing a CRLF
88 pair (that is one bye of 0x0D followed by one byte of 0x0A). This is
89 designed to ensure that notmuch is not corrupting the output of this
90 part by converting the CRLF pair to an LF only (as would be appropriate
91 for display of a text part on a Linux system, for example).
92
93 The part should be a 3-byte file with the following sequence of 3
94 hexadecimal bytes:
95
96         EF 0D 0A
97
98 --==-=-=
99 Content-Type: application/octet-stream
100 Content-Disposition: attachment; filename=crlf.bin
101 Content-Transfer-Encoding: base64
102
103 7w0K
104 --==-=-=--
105 EOF
106 notmuch new > /dev/null
107
108 test_begin_subtest "--format=text --part=0, full message"
109 notmuch show --format=text --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
110 cat <<EOF >EXPECTED
111 \fmessage{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 excluded:0 filename:${MAIL_DIR}/multipart
112 \fheader{
113 Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed unread)
114 Subject: Multipart message
115 From: Carl Worth <cworth@cworth.org>
116 To: cworth@cworth.org
117 Date: Fri, 05 Jan 2001 15:43:57 +0000
118 \fheader}
119 \fbody{
120 \fpart{ ID: 1, Content-type: multipart/signed
121 \fpart{ ID: 2, Content-type: multipart/mixed
122 \fpart{ ID: 3, Content-type: message/rfc822
123 \fheader{
124 Subject: html message
125 From: Carl Worth <cworth@cworth.org>
126 To: cworth@cworth.org
127 Date: Fri, 05 Jan 2001 15:42:57 +0000
128 \fheader}
129 \fbody{
130 \fpart{ ID: 4, Content-type: multipart/alternative
131 \fpart{ ID: 5, Content-type: text/html
132 Non-text part: text/html
133 \fpart}
134 \fpart{ ID: 6, Content-type: text/plain
135 This is an embedded message, with a multipart/alternative part.
136 \fpart}
137 \fpart}
138 \fbody}
139 \fpart}
140 \fattachment{ ID: 7, Filename: attachment, Content-type: text/plain
141 This is a text attachment.
142 \fattachment}
143 \fpart{ ID: 8, Content-type: text/plain
144 And this message is signed.
145
146 -Carl
147 \fpart}
148 \fpart}
149 \fpart{ ID: 9, Content-type: application/pgp-signature
150 Non-text part: application/pgp-signature
151 \fpart}
152 \fpart}
153 \fbody}
154 \fmessage}
155 EOF
156 test_expect_equal_file OUTPUT EXPECTED
157
158 test_begin_subtest "--format=text --part=1, message body"
159 notmuch show --format=text --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
160 cat <<EOF >EXPECTED
161 \fpart{ ID: 1, Content-type: multipart/signed
162 \fpart{ ID: 2, Content-type: multipart/mixed
163 \fpart{ ID: 3, Content-type: message/rfc822
164 \fheader{
165 Subject: html message
166 From: Carl Worth <cworth@cworth.org>
167 To: cworth@cworth.org
168 Date: Fri, 05 Jan 2001 15:42:57 +0000
169 \fheader}
170 \fbody{
171 \fpart{ ID: 4, Content-type: multipart/alternative
172 \fpart{ ID: 5, Content-type: text/html
173 Non-text part: text/html
174 \fpart}
175 \fpart{ ID: 6, Content-type: text/plain
176 This is an embedded message, with a multipart/alternative part.
177 \fpart}
178 \fpart}
179 \fbody}
180 \fpart}
181 \fattachment{ ID: 7, Filename: attachment, Content-type: text/plain
182 This is a text attachment.
183 \fattachment}
184 \fpart{ ID: 8, Content-type: text/plain
185 And this message is signed.
186
187 -Carl
188 \fpart}
189 \fpart}
190 \fpart{ ID: 9, Content-type: application/pgp-signature
191 Non-text part: application/pgp-signature
192 \fpart}
193 \fpart}
194 EOF
195 test_expect_equal_file OUTPUT EXPECTED
196
197 test_begin_subtest "--format=text --part=2, multipart/mixed"
198 notmuch show --format=text --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
199 cat <<EOF >EXPECTED
200 \fpart{ ID: 2, Content-type: multipart/mixed
201 \fpart{ ID: 3, Content-type: message/rfc822
202 \fheader{
203 Subject: html message
204 From: Carl Worth <cworth@cworth.org>
205 To: cworth@cworth.org
206 Date: Fri, 05 Jan 2001 15:42:57 +0000
207 \fheader}
208 \fbody{
209 \fpart{ ID: 4, Content-type: multipart/alternative
210 \fpart{ ID: 5, Content-type: text/html
211 Non-text part: text/html
212 \fpart}
213 \fpart{ ID: 6, Content-type: text/plain
214 This is an embedded message, with a multipart/alternative part.
215 \fpart}
216 \fpart}
217 \fbody}
218 \fpart}
219 \fattachment{ ID: 7, Filename: attachment, Content-type: text/plain
220 This is a text attachment.
221 \fattachment}
222 \fpart{ ID: 8, Content-type: text/plain
223 And this message is signed.
224
225 -Carl
226 \fpart}
227 \fpart}
228 EOF
229 test_expect_equal_file OUTPUT EXPECTED
230
231 test_begin_subtest "--format=text --part=3, rfc822 part"
232 notmuch show --format=text --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
233 cat <<EOF >EXPECTED
234 \fpart{ ID: 3, Content-type: message/rfc822
235 \fheader{
236 Subject: html message
237 From: Carl Worth <cworth@cworth.org>
238 To: cworth@cworth.org
239 Date: Fri, 05 Jan 2001 15:42:57 +0000
240 \fheader}
241 \fbody{
242 \fpart{ ID: 4, Content-type: multipart/alternative
243 \fpart{ ID: 5, Content-type: text/html
244 Non-text part: text/html
245 \fpart}
246 \fpart{ ID: 6, Content-type: text/plain
247 This is an embedded message, with a multipart/alternative part.
248 \fpart}
249 \fpart}
250 \fbody}
251 \fpart}
252 EOF
253 test_expect_equal_file OUTPUT EXPECTED
254
255 test_begin_subtest "--format=text --part=4, rfc822's multipart"
256 notmuch show --format=text --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
257 cat <<EOF >EXPECTED
258 \fpart{ ID: 4, Content-type: multipart/alternative
259 \fpart{ ID: 5, Content-type: text/html
260 Non-text part: text/html
261 \fpart}
262 \fpart{ ID: 6, Content-type: text/plain
263 This is an embedded message, with a multipart/alternative part.
264 \fpart}
265 \fpart}
266 EOF
267 test_expect_equal_file OUTPUT EXPECTED
268
269 test_begin_subtest "--format=text --part=5, rfc822's html part"
270 notmuch show --format=text --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
271 cat <<EOF >EXPECTED
272 \fpart{ ID: 5, Content-type: text/html
273 Non-text part: text/html
274 \fpart}
275 EOF
276 test_expect_equal_file OUTPUT EXPECTED
277
278 test_begin_subtest "--format=text --part=6, rfc822's text part"
279 notmuch show --format=text --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
280 cat <<EOF >EXPECTED
281 \fpart{ ID: 6, Content-type: text/plain
282 This is an embedded message, with a multipart/alternative part.
283 \fpart}
284 EOF
285 test_expect_equal_file OUTPUT EXPECTED
286
287 test_begin_subtest "--format=text --part=7, inline attachement"
288 notmuch show --format=text --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
289 cat <<EOF >EXPECTED
290 \fattachment{ ID: 7, Filename: attachment, Content-type: text/plain
291 This is a text attachment.
292 \fattachment}
293 EOF
294 test_expect_equal_file OUTPUT EXPECTED
295
296 test_begin_subtest "--format=text --part=8, plain text part"
297 notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
298 cat <<EOF >EXPECTED
299 \fpart{ ID: 8, Content-type: text/plain
300 And this message is signed.
301
302 -Carl
303 \fpart}
304 EOF
305 test_expect_equal_file OUTPUT EXPECTED
306
307 test_begin_subtest "--format=text --part=9, pgp signature (unverified)"
308 notmuch show --format=text --part=9 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
309 cat <<EOF >EXPECTED
310 \fpart{ ID: 9, Content-type: application/pgp-signature
311 Non-text part: application/pgp-signature
312 \fpart}
313 EOF
314 test_expect_equal_file OUTPUT EXPECTED
315
316 test_expect_success \
317     "--format=text --part=8, no part, expect error" \
318     "notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
319
320 test_begin_subtest "--format=json --part=0, full message"
321 notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
322 echo >>OUTPUT # expect *no* newline at end of output
323 cat <<EOF >EXPECTED
324
325 {"id": "87liy5ap00.fsf@yoom.home.cworth.org", "match": true, "excluded": false, "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", "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [
326 {"id": 1, "content-type": "multipart/signed", "content": [
327 {"id": 2, "content-type": "multipart/mixed", "content": [
328 {"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
329 {"id": 4, "content-type": "multipart/alternative", "content": [
330 {"id": 5, "content-type": "text/html"}, 
331 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}, 
332 {"id": 7, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}, 
333 {"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}, 
334 {"id": 9, "content-type": "application/pgp-signature"}]}]}
335 EOF
336 test_expect_equal_file OUTPUT EXPECTED
337
338 test_begin_subtest "--format=json --part=1, message body"
339 notmuch show --format=json --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
340 echo >>OUTPUT # expect *no* newline at end of output
341 cat <<EOF >EXPECTED
342
343 {"id": 1, "content-type": "multipart/signed", "content": [
344 {"id": 2, "content-type": "multipart/mixed", "content": [
345 {"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
346 {"id": 4, "content-type": "multipart/alternative", "content": [
347 {"id": 5, "content-type": "text/html"}, 
348 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}, 
349 {"id": 7, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}, 
350 {"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}, 
351 {"id": 9, "content-type": "application/pgp-signature"}]}
352 EOF
353 test_expect_equal_file OUTPUT EXPECTED
354
355 test_begin_subtest "--format=json --part=2, multipart/mixed"
356 notmuch show --format=json --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
357 echo >>OUTPUT # expect *no* newline at end of output
358 cat <<EOF >EXPECTED
359
360 {"id": 2, "content-type": "multipart/mixed", "content": [
361 {"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
362 {"id": 4, "content-type": "multipart/alternative", "content": [
363 {"id": 5, "content-type": "text/html"}, 
364 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}, 
365 {"id": 7, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}, 
366 {"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}
367 EOF
368 test_expect_equal_file OUTPUT EXPECTED
369
370 test_begin_subtest "--format=json --part=3, rfc822 part"
371 notmuch show --format=json --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
372 echo >>OUTPUT # expect *no* newline at end of output
373 cat <<EOF >EXPECTED
374
375 {"id": 3, "content-type": "message/rfc822", "content": [{"headers": {"Subject": "html message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:42:57 +0000"}, "body": [
376 {"id": 4, "content-type": "multipart/alternative", "content": [
377 {"id": 5, "content-type": "text/html"}, 
378 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}
379 EOF
380 test_expect_equal_file OUTPUT EXPECTED
381
382 test_begin_subtest "--format=json --part=4, rfc822's multipart/alternative"
383 notmuch show --format=json --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
384 echo >>OUTPUT # expect *no* newline at end of output
385 cat <<EOF >EXPECTED
386
387 {"id": 4, "content-type": "multipart/alternative", "content": [
388 {"id": 5, "content-type": "text/html"}, 
389 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}
390 EOF
391 test_expect_equal_file OUTPUT EXPECTED
392
393 test_begin_subtest "--format=json --part=5, rfc822's html part"
394 notmuch show --format=json --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
395 echo >>OUTPUT # expect *no* newline at end of output
396 cat <<EOF >EXPECTED
397
398 {"id": 5, "content-type": "text/html"}
399 EOF
400 test_expect_equal_file OUTPUT EXPECTED
401
402 test_begin_subtest "--format=json --part=6, rfc822's text part"
403 notmuch show --format=json --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
404 echo >>OUTPUT # expect *no* newline at end of output
405 cat <<EOF >EXPECTED
406
407 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}
408 EOF
409 test_expect_equal_file OUTPUT EXPECTED
410
411 test_begin_subtest "--format=json --part=7, inline attachment"
412 notmuch show --format=json --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
413 echo >>OUTPUT # expect *no* newline at end of output
414 cat <<EOF >EXPECTED
415
416 {"id": 7, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}
417 EOF
418 test_expect_equal_file OUTPUT EXPECTED
419
420 test_begin_subtest "--format=json --part=8, plain text part"
421 notmuch show --format=json --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
422 echo >>OUTPUT # expect *no* newline at end of output
423 cat <<EOF >EXPECTED
424
425 {"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}
426 EOF
427 test_expect_equal_file OUTPUT EXPECTED
428
429 test_begin_subtest "--format=json --part=9, pgp signature (unverified)"
430 notmuch show --format=json --part=9 'id:87liy5ap00.fsf@yoom.home.cworth.org' | sed 's|{"id":|\n{"id":|g' >OUTPUT
431 echo >>OUTPUT # expect *no* newline at end of output
432 cat <<EOF >EXPECTED
433
434 {"id": 9, "content-type": "application/pgp-signature"}
435 EOF
436 test_expect_equal_file OUTPUT EXPECTED
437
438 test_expect_success \
439     "--format=json --part=10, no part, expect error" \
440     "notmuch show --format=json --part=10 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
441
442 test_begin_subtest "--format=raw"
443 notmuch show --format=raw 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
444 test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart
445
446 test_begin_subtest "--format=raw --part=0, full message"
447 notmuch show --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
448 test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart
449
450 test_begin_subtest "--format=raw --part=1, message body"
451 notmuch show --format=raw --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
452 # output should *not* include newline
453 echo >>OUTPUT
454 cat <<EOF >EXPECTED
455 Subject: html message
456 From: Carl Worth <cworth@cworth.org>
457 To: cworth@cworth.org
458 Date: Fri, 05 Jan 2001 15:42:57 +0000
459
460 <p>This is an embedded message, with a multipart/alternative part.</p>
461 This is an embedded message, with a multipart/alternative part.
462 This is a text attachment.
463 And this message is signed.
464
465 -Carl
466 -----BEGIN PGP SIGNATURE-----
467 Version: GnuPG v1.4.11 (GNU/Linux)
468
469 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
470 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
471 =zkga
472 -----END PGP SIGNATURE-----
473 EOF
474 test_expect_equal_file OUTPUT EXPECTED
475
476 test_begin_subtest "--format=raw --part=2, multipart/mixed"
477 notmuch show --format=raw --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
478 cat <<EOF >EXPECTED
479 Subject: html message
480 From: Carl Worth <cworth@cworth.org>
481 To: cworth@cworth.org
482 Date: Fri, 05 Jan 2001 15:42:57 +0000
483
484 <p>This is an embedded message, with a multipart/alternative part.</p>
485 This is an embedded message, with a multipart/alternative part.
486 This is a text attachment.
487 And this message is signed.
488
489 -Carl
490 EOF
491 test_expect_equal_file OUTPUT EXPECTED
492
493 test_begin_subtest "--format=raw --part=3, rfc822 part"
494 test_subtest_known_broken
495
496 notmuch show --format=raw --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
497 test_expect_equal_file OUTPUT embedded_message
498
499 test_begin_subtest "--format=raw --part=4, rfc822's html part"
500 notmuch show --format=raw --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
501 cat <<EOF >EXPECTED
502 <p>This is an embedded message, with a multipart/alternative part.</p>
503 This is an embedded message, with a multipart/alternative part.
504 EOF
505 test_expect_equal_file OUTPUT EXPECTED
506
507 test_begin_subtest "--format=raw --part=5, rfc822's html part"
508 notmuch show --format=raw --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
509 cat <<EOF >EXPECTED
510 <p>This is an embedded message, with a multipart/alternative part.</p>
511 EOF
512 test_expect_equal_file OUTPUT EXPECTED
513
514 test_begin_subtest "--format=raw --part=6, rfc822's text part"
515 notmuch show --format=raw --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
516 cat <<EOF >EXPECTED
517 This is an embedded message, with a multipart/alternative part.
518 EOF
519 test_expect_equal_file OUTPUT EXPECTED
520
521 test_begin_subtest "--format=raw --part=7, inline attachment"
522 notmuch show --format=raw --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
523 cat <<EOF >EXPECTED
524 This is a text attachment.
525 EOF
526 test_expect_equal_file OUTPUT EXPECTED
527
528 test_begin_subtest "--format=raw --part=8, plain text part"
529 notmuch show --format=raw --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
530 cat <<EOF >EXPECTED
531 And this message is signed.
532
533 -Carl
534 EOF
535 test_expect_equal_file OUTPUT EXPECTED
536
537 test_begin_subtest "--format=raw --part=9, pgp signature (unverified)"
538 notmuch show --format=raw --part=9 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
539 # output should *not* include newline
540 echo >>OUTPUT
541 cat <<EOF >EXPECTED
542 -----BEGIN PGP SIGNATURE-----
543 Version: GnuPG v1.4.11 (GNU/Linux)
544
545 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
546 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
547 =zkga
548 -----END PGP SIGNATURE-----
549 EOF
550 test_expect_equal_file OUTPUT EXPECTED
551
552 test_expect_success \
553     "--format=raw --part=10, no part, expect error" \
554     "notmuch show --format=raw --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
555
556 test_begin_subtest "--format=mbox"
557 notmuch show --format=mbox 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
558 printf "From cworth@cworth.org Fri Jan  5 15:43:57 2001\n" >EXPECTED
559 cat "${MAIL_DIR}"/multipart >>EXPECTED
560 # mbox output is expected to include a blank line
561 echo >>EXPECTED
562 test_expect_equal_file OUTPUT EXPECTED
563
564 test_expect_success \
565     "--format=mbox --part=1, incompatible, expect error" \
566     "! notmuch show --format=mbox --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
567
568 test_begin_subtest "'notmuch reply' to a multipart message"
569 notmuch reply 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
570 cat <<EOF >EXPECTED
571 From: Notmuch Test Suite <test_suite@notmuchmail.org>
572 Subject: Re: Multipart message
573 To: Carl Worth <cworth@cworth.org>, cworth@cworth.org
574 In-Reply-To: <87liy5ap00.fsf@yoom.home.cworth.org>
575 References: <87liy5ap00.fsf@yoom.home.cworth.org>
576
577 On Fri, 05 Jan 2001 15:43:57 +0000, Carl Worth <cworth@cworth.org> wrote:
578 > From: Carl Worth <cworth@cworth.org>
579 > To: cworth@cworth.org
580 > Subject: html message
581 > Date: Fri, 05 Jan 2001 15:42:57 +0000
582 >
583 Non-text part: text/html
584 > This is an embedded message, with a multipart/alternative part.
585 > This is a text attachment.
586 > And this message is signed.
587
588 > -Carl
589 EOF
590 test_expect_equal_file OUTPUT EXPECTED
591
592 test_begin_subtest "'notmuch show --part' does not corrupt a part with CRLF pair"
593 notmuch show --format=raw --part=3 id:base64-part-with-crlf > crlf.out
594 echo -n -e "\xEF\x0D\x0A" > crlf.expected
595 test_expect_equal_file crlf.out crlf.expected
596
597 test_done