]> git.notmuchmail.org Git - notmuch/blob - test/T190-multipart.sh
cli: notmuch show support for --include-html with --format=text
[notmuch] / test / T190-multipart.sh
1 #!/usr/bin/env bash
2 test_description="output of multipart message"
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 cat <<EOF > embedded_message_body
6 Content-Type: multipart/alternative; boundary="==-=-=="
7
8 --==-=-==
9 Content-Type: text/html
10
11 <p>This is an embedded message, with a multipart/alternative part.</p>
12
13 --==-=-==
14 Content-Type: text/plain
15
16 This is an embedded message, with a multipart/alternative part.
17
18 --==-=-==--
19 EOF
20 cat <<EOF > embedded_message
21 From: Carl Worth <cworth@cworth.org>
22 To: cworth@cworth.org
23 Subject: html message
24 Date: Fri, 05 Jan 2001 15:42:57 +0000
25 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
26 Message-ID: <87liy5ap01.fsf@yoom.home.cworth.org>
27 MIME-Version: 1.0
28 EOF
29
30 cat embedded_message_body >> embedded_message
31
32 cat <<EOF > multipart_body
33 Content-Type: multipart/signed; boundary="==-=-=";
34         micalg=pgp-sha1; protocol="application/pgp-signature"
35
36 --==-=-=
37 Content-Type: multipart/mixed; boundary="=-=-="
38
39 --=-=-=
40 Content-Type: message/rfc822
41 Content-Disposition: inline
42
43 EOF
44
45 cat embedded_message >> multipart_body
46 cat <<EOF >> multipart_body
47
48 --=-=-=
49 Content-Disposition: attachment; filename=attachment
50
51 This is a text attachment.
52
53 --=-=-=
54
55 And this message is signed.
56
57 -Carl
58
59 --=-=-=--
60
61 --==-=-=
62 Content-Type: application/pgp-signature
63
64 -----BEGIN PGP SIGNATURE-----
65 Version: GnuPG v1.4.11 (GNU/Linux)
66
67 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
68 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
69 =zkga
70 -----END PGP SIGNATURE-----
71 --==-=-=--
72 EOF
73
74 cat <<EOF > ${MAIL_DIR}/multipart
75 From: Carl Worth <cworth@cworth.org>
76 To: cworth@cworth.org
77 Subject: Multipart message
78 Date: Fri, 05 Jan 2001 15:43:57 +0000
79 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
80 Message-ID: <87liy5ap00.fsf@yoom.home.cworth.org>
81 MIME-Version: 1.0
82 EOF
83
84 cat multipart_body >> ${MAIL_DIR}/multipart
85
86 cat <<EOF > ${MAIL_DIR}/base64-part-with-crlf
87 From: Carl Worth <cworth@cworth.org>
88 To: cworth@cworth.org
89 Subject: Test message with a BASE64 encoded binary containing CRLF pair
90 Date: Fri, 05 Jan 2001 15:43:57 +0000
91 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
92 Message-ID: <base64-part-with-crlf>
93 MIME-Version: 1.0
94 Content-Type: multipart/mixed; boundary="==-=-=";
95
96 --==-=-=
97
98 The attached BASE64-encoded part expands to a binary containing a CRLF
99 pair (that is one bye of 0x0D followed by one byte of 0x0A). This is
100 designed to ensure that notmuch is not corrupting the output of this
101 part by converting the CRLF pair to an LF only (as would be appropriate
102 for display of a text part on a Linux system, for example).
103
104 The part should be a 3-byte file with the following sequence of 3
105 hexadecimal bytes:
106
107         EF 0D 0A
108
109 --==-=-=
110 Content-Type: application/octet-stream
111 Content-Disposition: attachment; filename=crlf.bin
112 Content-Transfer-Encoding: base64
113
114 7w0K
115 --==-=-=--
116 EOF
117
118 cat <<EOF > content_types
119 From: Todd <todd@example.com>
120 To: todd@example.com
121 Subject: odd content types
122 Date: Mon, 12 Jan 2014 18:12:32 +0000
123 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
124 Message-ID: <KfjfO2WJBw2hrV2p0gjT@example.com>
125 MIME-Version: 1.0
126 Content-Type: multipart/alternative; boundary="==-=-=="
127
128 --==-=-==
129 Content-Type: application/unique_identifier
130
131 <p>This is an embedded message, with a multipart/alternative part.</p>
132
133 --==-=-==
134 Content-Type: text/some_other_identifier
135
136 This is an embedded message, with a multipart/alternative part.
137
138 --==-=-==--
139 EOF
140 cat content_types >> ${MAIL_DIR}/odd_content_type
141 notmuch new > /dev/null
142
143 test_begin_subtest "--format=text --part=0, full message"
144 notmuch show --format=text --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
145 cat <<EOF >EXPECTED
146 \fmessage{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 excluded:0 filename:${MAIL_DIR}/multipart
147 \fheader{
148 Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed unread)
149 Subject: Multipart message
150 From: Carl Worth <cworth@cworth.org>
151 To: cworth@cworth.org
152 Date: Fri, 05 Jan 2001 15:43:57 +0000
153 \fheader}
154 \fbody{
155 \fpart{ ID: 1, Content-type: multipart/signed
156 \fpart{ ID: 2, Content-type: multipart/mixed
157 \fpart{ ID: 3, Content-type: message/rfc822
158 \fheader{
159 Subject: html message
160 From: Carl Worth <cworth@cworth.org>
161 To: cworth@cworth.org
162 Date: Fri, 05 Jan 2001 15:42:57 +0000
163 \fheader}
164 \fbody{
165 \fpart{ ID: 4, Content-type: multipart/alternative
166 \fpart{ ID: 5, Content-type: text/html
167 Non-text part: text/html
168 \fpart}
169 \fpart{ ID: 6, Content-type: text/plain
170 This is an embedded message, with a multipart/alternative part.
171 \fpart}
172 \fpart}
173 \fbody}
174 \fpart}
175 \fattachment{ ID: 7, Filename: attachment, Content-type: text/plain
176 This is a text attachment.
177 \fattachment}
178 \fpart{ ID: 8, Content-type: text/plain
179 And this message is signed.
180
181 -Carl
182 \fpart}
183 \fpart}
184 \fpart{ ID: 9, Content-type: application/pgp-signature
185 Non-text part: application/pgp-signature
186 \fpart}
187 \fpart}
188 \fbody}
189 \fmessage}
190 EOF
191 test_expect_equal_file EXPECTED OUTPUT
192
193 test_begin_subtest "--format=text --part=0 --body=false, message header"
194 notmuch show --format=text --part=0  --body=false 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
195 cat <<EOF >EXPECTED
196 \fmessage{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 excluded:0 filename:${MAIL_DIR}/multipart
197 \fheader{
198 Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed unread)
199 Subject: Multipart message
200 From: Carl Worth <cworth@cworth.org>
201 To: cworth@cworth.org
202 Date: Fri, 05 Jan 2001 15:43:57 +0000
203 \fheader}
204 \fmessage}
205 EOF
206 test_expect_equal_file EXPECTED OUTPUT
207
208 test_begin_subtest "--format=text --part=1, message body"
209 notmuch show --format=text --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
210 cat <<EOF >EXPECTED
211 \fpart{ ID: 1, Content-type: multipart/signed
212 \fpart{ ID: 2, Content-type: multipart/mixed
213 \fpart{ ID: 3, Content-type: message/rfc822
214 \fheader{
215 Subject: html message
216 From: Carl Worth <cworth@cworth.org>
217 To: cworth@cworth.org
218 Date: Fri, 05 Jan 2001 15:42:57 +0000
219 \fheader}
220 \fbody{
221 \fpart{ ID: 4, Content-type: multipart/alternative
222 \fpart{ ID: 5, Content-type: text/html
223 Non-text part: text/html
224 \fpart}
225 \fpart{ ID: 6, Content-type: text/plain
226 This is an embedded message, with a multipart/alternative part.
227 \fpart}
228 \fpart}
229 \fbody}
230 \fpart}
231 \fattachment{ ID: 7, Filename: attachment, Content-type: text/plain
232 This is a text attachment.
233 \fattachment}
234 \fpart{ ID: 8, Content-type: text/plain
235 And this message is signed.
236
237 -Carl
238 \fpart}
239 \fpart}
240 \fpart{ ID: 9, Content-type: application/pgp-signature
241 Non-text part: application/pgp-signature
242 \fpart}
243 \fpart}
244 EOF
245 test_expect_equal_file EXPECTED OUTPUT
246
247 test_begin_subtest "--format=text --part=2, multipart/mixed"
248 notmuch show --format=text --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
249 cat <<EOF >EXPECTED
250 \fpart{ ID: 2, Content-type: multipart/mixed
251 \fpart{ ID: 3, Content-type: message/rfc822
252 \fheader{
253 Subject: html message
254 From: Carl Worth <cworth@cworth.org>
255 To: cworth@cworth.org
256 Date: Fri, 05 Jan 2001 15:42:57 +0000
257 \fheader}
258 \fbody{
259 \fpart{ ID: 4, Content-type: multipart/alternative
260 \fpart{ ID: 5, Content-type: text/html
261 Non-text part: text/html
262 \fpart}
263 \fpart{ ID: 6, Content-type: text/plain
264 This is an embedded message, with a multipart/alternative part.
265 \fpart}
266 \fpart}
267 \fbody}
268 \fpart}
269 \fattachment{ ID: 7, Filename: attachment, Content-type: text/plain
270 This is a text attachment.
271 \fattachment}
272 \fpart{ ID: 8, Content-type: text/plain
273 And this message is signed.
274
275 -Carl
276 \fpart}
277 \fpart}
278 EOF
279 test_expect_equal_file EXPECTED OUTPUT
280
281 test_begin_subtest "--format=text --part=3, rfc822 part"
282 notmuch show --format=text --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
283 cat <<EOF >EXPECTED
284 \fpart{ ID: 3, Content-type: message/rfc822
285 \fheader{
286 Subject: html message
287 From: Carl Worth <cworth@cworth.org>
288 To: cworth@cworth.org
289 Date: Fri, 05 Jan 2001 15:42:57 +0000
290 \fheader}
291 \fbody{
292 \fpart{ ID: 4, Content-type: multipart/alternative
293 \fpart{ ID: 5, Content-type: text/html
294 Non-text part: text/html
295 \fpart}
296 \fpart{ ID: 6, Content-type: text/plain
297 This is an embedded message, with a multipart/alternative part.
298 \fpart}
299 \fpart}
300 \fbody}
301 \fpart}
302 EOF
303 test_expect_equal_file EXPECTED OUTPUT
304
305 test_begin_subtest "--format=text --part=4, rfc822's multipart"
306 notmuch show --format=text --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
307 cat <<EOF >EXPECTED
308 \fpart{ ID: 4, Content-type: multipart/alternative
309 \fpart{ ID: 5, Content-type: text/html
310 Non-text part: text/html
311 \fpart}
312 \fpart{ ID: 6, Content-type: text/plain
313 This is an embedded message, with a multipart/alternative part.
314 \fpart}
315 \fpart}
316 EOF
317 test_expect_equal_file EXPECTED OUTPUT
318
319 test_begin_subtest "--format=text --part=5, rfc822's html part"
320 notmuch show --format=text --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
321 cat <<EOF >EXPECTED
322 \fpart{ ID: 5, Content-type: text/html
323 Non-text part: text/html
324 \fpart}
325 EOF
326 test_expect_equal_file EXPECTED OUTPUT
327
328 test_begin_subtest "--format=text --include-html --part=5, rfc822's html part"
329 notmuch show --format=text --include-html --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
330 cat <<EOF >EXPECTED
331 \fpart{ ID: 5, Content-type: text/html
332 <p>This is an embedded message, with a multipart/alternative part.</p>
333 \fpart}
334 EOF
335 test_expect_equal_file EXPECTED OUTPUT
336
337 test_begin_subtest "--format=text --part=6, rfc822's text part"
338 notmuch show --format=text --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
339 cat <<EOF >EXPECTED
340 \fpart{ ID: 6, Content-type: text/plain
341 This is an embedded message, with a multipart/alternative part.
342 \fpart}
343 EOF
344 test_expect_equal_file EXPECTED OUTPUT
345
346 test_begin_subtest "--format=text --part=7, inline attachment"
347 notmuch show --format=text --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
348 cat <<EOF >EXPECTED
349 \fattachment{ ID: 7, Filename: attachment, Content-type: text/plain
350 This is a text attachment.
351 \fattachment}
352 EOF
353 test_expect_equal_file EXPECTED OUTPUT
354
355 test_begin_subtest "--format=text --part=8, plain text part"
356 notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
357 cat <<EOF >EXPECTED
358 \fpart{ ID: 8, Content-type: text/plain
359 And this message is signed.
360
361 -Carl
362 \fpart}
363 EOF
364 test_expect_equal_file EXPECTED OUTPUT
365
366 test_begin_subtest "--format=text --part=9, pgp signature (unverified)"
367 notmuch show --format=text --part=9 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
368 cat <<EOF >EXPECTED
369 \fpart{ ID: 9, Content-type: application/pgp-signature
370 Non-text part: application/pgp-signature
371 \fpart}
372 EOF
373 test_expect_equal_file EXPECTED OUTPUT
374
375 test_begin_subtest "--format=text --part=8, no part, expect error"
376 test_expect_success "notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
377
378 test_begin_subtest "--format=json --part=0, full message"
379 notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
380 cat <<EOF >EXPECTED
381 {"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": [
382 {"id": 1, "content-type": "multipart/signed", "content": [
383 {"id": 2, "content-type": "multipart/mixed", "content": [
384 {"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", "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": [
385 {"id": 4, "content-type": "multipart/alternative", "content": [
386 {"id": 5, "content-type": "text/html", "content-length": 71},
387 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}, 
388 {"id": 7, "content-type": "text/plain", "content-disposition": "attachment", "filename": "attachment", "content": "This is a text attachment.\n"},
389 {"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}, 
390 {"id": 9, "content-type": "application/pgp-signature", "content-length": 197}]}]}
391 EOF
392 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
393
394 test_begin_subtest "--format=json --part=1, message body"
395 notmuch show --format=json --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
396 cat <<EOF >EXPECTED
397 {"id": 1, "content-type": "multipart/signed", "content": [
398 {"id": 2, "content-type": "multipart/mixed", "content": [
399 {"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", "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": [
400 {"id": 4, "content-type": "multipart/alternative", "content": [
401 {"id": 5, "content-type": "text/html", "content-length": 71},
402 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}, 
403 {"id": 7, "content-type": "text/plain", "content-disposition": "attachment", "filename": "attachment", "content": "This is a text attachment.\n"},
404 {"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}, 
405 {"id": 9, "content-type": "application/pgp-signature", "content-length": 197}]}
406 EOF
407 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
408
409 test_begin_subtest "--format=json --part=2, multipart/mixed"
410 notmuch show --format=json --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
411 cat <<EOF >EXPECTED
412 {"id": 2, "content-type": "multipart/mixed", "content": [
413 {"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", "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": [
414 {"id": 4, "content-type": "multipart/alternative", "content": [
415 {"id": 5, "content-type": "text/html", "content-length": 71},
416 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}, 
417 {"id": 7, "content-type": "text/plain", "content-disposition": "attachment", "filename": "attachment", "content": "This is a text attachment.\n"},
418 {"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}]}
419 EOF
420 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
421
422 test_begin_subtest "--format=json --part=3, rfc822 part"
423 notmuch show --format=json --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
424 cat <<EOF >EXPECTED
425 {"id": 3, "content-type": "message/rfc822", "content-disposition": "inline", "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": [
426 {"id": 4, "content-type": "multipart/alternative", "content": [
427 {"id": 5, "content-type": "text/html", "content-length": 71},
428 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]}
429 EOF
430 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
431
432 test_begin_subtest "--format=json --part=4, rfc822's multipart/alternative"
433 notmuch show --format=json --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
434 cat <<EOF >EXPECTED
435 {"id": 4, "content-type": "multipart/alternative", "content": [
436 {"id": 5, "content-type": "text/html", "content-length": 71},
437 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}]}
438 EOF
439 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
440
441 test_begin_subtest "--format=json --part=5, rfc822's html part"
442 notmuch show --format=json --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
443 cat <<EOF >EXPECTED
444 {"id": 5, "content-type": "text/html", "content-length": 71}
445 EOF
446 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
447
448 test_begin_subtest "--format=json --part=6, rfc822's text part"
449 notmuch show --format=json --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
450 cat <<EOF >EXPECTED
451 {"id": 6, "content-type": "text/plain", "content": "This is an embedded message, with a multipart/alternative part.\n"}
452 EOF
453 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
454
455 test_begin_subtest "--format=json --part=7, inline attachment"
456 notmuch show --format=json --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
457 cat <<EOF >EXPECTED
458 {"id": 7,
459  "content-type": "text/plain",
460  "filename": "attachment",
461  "content": "This is a text attachment.\n",
462  "content-disposition": "attachment"}
463 EOF
464 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
465
466 test_begin_subtest "--format=json --part=8, plain text part"
467 notmuch show --format=json --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
468 cat <<EOF >EXPECTED
469 {"id": 8, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}
470 EOF
471 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
472
473 test_begin_subtest "--format=json --part=9, pgp signature (unverified)"
474 notmuch show --format=json --part=9 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
475 cat <<EOF >EXPECTED
476 {"id": 9, "content-type": "application/pgp-signature", "content-length": 197}
477 EOF
478 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
479
480 test_begin_subtest "--format=json --part=10, no part, expect error"
481 test_expect_success "notmuch show --format=json --part=10 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
482
483 test_begin_subtest "--format=raw"
484 notmuch show --format=raw 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
485 test_expect_equal_file "${MAIL_DIR}"/multipart  OUTPUT
486
487 test_begin_subtest "--format=raw --part=0, full message"
488 notmuch show --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
489 test_expect_equal_file "${MAIL_DIR}"/multipart OUTPUT
490
491 test_begin_subtest "--format=raw --part=1, message body"
492 test_subtest_broken_gmime_2
493 notmuch show --format=raw --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
494 test_expect_equal_file multipart_body OUTPUT
495
496 test_begin_subtest "--format=raw --part=2, multipart/mixed"
497 notmuch show --format=raw --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
498 cat <<EOF >EXPECTED
499 Content-Type: multipart/mixed; boundary="=-=-="
500
501 --=-=-=
502 Content-Type: message/rfc822
503 Content-Disposition: inline
504
505 From: Carl Worth <cworth@cworth.org>
506 To: cworth@cworth.org
507 Subject: html message
508 Date: Fri, 05 Jan 2001 15:42:57 +0000
509 User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu)
510 Message-ID: <87liy5ap01.fsf@yoom.home.cworth.org>
511 MIME-Version: 1.0
512 Content-Type: multipart/alternative; boundary="==-=-=="
513
514 --==-=-==
515 Content-Type: text/html
516
517 <p>This is an embedded message, with a multipart/alternative part.</p>
518
519 --==-=-==
520 Content-Type: text/plain
521
522 This is an embedded message, with a multipart/alternative part.
523
524 --==-=-==--
525
526 --=-=-=
527 Content-Disposition: attachment; filename=attachment
528
529 This is a text attachment.
530
531 --=-=-=
532
533 And this message is signed.
534
535 -Carl
536
537 --=-=-=--
538 EOF
539 test_expect_equal_file EXPECTED OUTPUT
540
541 test_begin_subtest "--format=raw --part=3, rfc822 part"
542 notmuch show --format=raw --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
543 test_expect_equal_file embedded_message OUTPUT
544
545 test_begin_subtest "--format=raw --part=4, rfc822's multipart"
546 test_subtest_broken_gmime_2
547 notmuch show --format=raw --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
548 test_expect_equal_file embedded_message_body OUTPUT
549
550 test_begin_subtest "--format=raw --part=5, rfc822's html part"
551 notmuch show --format=raw --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
552 cat <<EOF >EXPECTED
553 <p>This is an embedded message, with a multipart/alternative part.</p>
554 EOF
555 test_expect_equal_file EXPECTED OUTPUT
556
557 test_begin_subtest "--format=raw --part=6, rfc822's text part"
558 notmuch show --format=raw --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
559 cat <<EOF >EXPECTED
560 This is an embedded message, with a multipart/alternative part.
561 EOF
562 test_expect_equal_file EXPECTED OUTPUT
563
564 test_begin_subtest "--format=raw --part=7, inline attachment"
565 notmuch show --format=raw --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
566 cat <<EOF >EXPECTED
567 This is a text attachment.
568 EOF
569 test_expect_equal_file EXPECTED OUTPUT
570
571 test_begin_subtest "--format=raw --part=8, plain text part"
572 notmuch show --format=raw --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
573 cat <<EOF >EXPECTED
574 And this message is signed.
575
576 -Carl
577 EOF
578 test_expect_equal_file EXPECTED OUTPUT
579
580 test_begin_subtest "--format=raw --part=9, pgp signature (unverified)"
581 notmuch show --format=raw --part=9 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
582 # output should *not* include newline
583 echo >>OUTPUT
584 cat <<EOF >EXPECTED
585 -----BEGIN PGP SIGNATURE-----
586 Version: GnuPG v1.4.11 (GNU/Linux)
587
588 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
589 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
590 =zkga
591 -----END PGP SIGNATURE-----
592 EOF
593 test_expect_equal_file EXPECTED OUTPUT
594
595 test_begin_subtest "--format=raw --part=10, no part, expect error"
596 test_expect_success "notmuch show --format=raw --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
597
598 test_begin_subtest "--format=mbox"
599 notmuch show --format=mbox 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
600 printf "From cworth@cworth.org Fri Jan  5 15:43:57 2001\n" >EXPECTED
601 cat "${MAIL_DIR}"/multipart >>EXPECTED
602 # mbox output is expected to include a blank line
603 echo >>EXPECTED
604 test_expect_equal_file EXPECTED OUTPUT
605
606 test_begin_subtest "--format=mbox --part=1, incompatible, expect error"
607 test_expect_success "! notmuch show --format=mbox --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
608
609 test_begin_subtest "'notmuch reply' to a multipart message"
610 notmuch reply 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
611 cat <<EOF >EXPECTED
612 From: Notmuch Test Suite <test_suite@notmuchmail.org>
613 Subject: Re: Multipart message
614 To: Carl Worth <cworth@cworth.org>, cworth@cworth.org
615 In-Reply-To: <87liy5ap00.fsf@yoom.home.cworth.org>
616 References: <87liy5ap00.fsf@yoom.home.cworth.org>
617
618 On Fri, 05 Jan 2001 15:43:57 +0000, Carl Worth <cworth@cworth.org> wrote:
619 > From: Carl Worth <cworth@cworth.org>
620 > To: cworth@cworth.org
621 > Subject: html message
622 > Date: Fri, 05 Jan 2001 15:42:57 +0000
623 >
624 Non-text part: text/html
625 > This is an embedded message, with a multipart/alternative part.
626 > This is a text attachment.
627 > And this message is signed.
628
629 > -Carl
630 EOF
631 test_expect_equal_file EXPECTED OUTPUT
632
633 test_begin_subtest "'notmuch reply' to a multipart message with json format"
634 notmuch reply --format=json 'id:87liy5ap00.fsf@yoom.home.cworth.org' | notmuch_json_show_sanitize >OUTPUT
635 notmuch_json_show_sanitize <<EOF >EXPECTED
636 {"reply-headers": {"Subject": "Re: Multipart message",
637  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
638  "To": "Carl Worth <cworth@cworth.org>, cworth@cworth.org",
639  "In-reply-to": "<87liy5ap00.fsf@yoom.home.cworth.org>",
640  "References": "<87liy5ap00.fsf@yoom.home.cworth.org>"},
641  "original": {"id": "XXXXX",
642  "match": false,
643  "excluded": false,
644  "filename": ["YYYYY"],
645  "timestamp": 978709437,
646  "date_relative": "2001-01-05",
647  "tags": ["attachment","inbox","signed","unread"],
648  "headers": {"Subject": "Multipart message",
649  "From": "Carl Worth <cworth@cworth.org>",
650  "To": "cworth@cworth.org",
651  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
652  "body": [{"id": 1,
653  "content-type": "multipart/signed",
654  "content": [{"id": 2,
655  "content-type": "multipart/mixed",
656  "content": [{"id": 3,
657  "content-type": "message/rfc822",
658  "content-disposition": "inline",
659  "content": [{"headers": {"Subject": "html message",
660  "From": "Carl Worth <cworth@cworth.org>",
661  "To": "cworth@cworth.org",
662  "Date": "Fri, 05 Jan 2001 15:42:57 +0000"},
663  "body": [{"id": 4,
664  "content-type": "multipart/alternative",
665  "content": [{"id": 5,
666  "content-type": "text/html",
667  "content-length": 71},
668  {"id": 6,
669  "content-type": "text/plain",
670  "content": "This is an embedded message, with a multipart/alternative part.\n"}]}]}]},
671  {"id": 7,
672  "content-type": "text/plain",
673  "content-disposition": "attachment",
674  "filename": "attachment",
675  "content": "This is a text attachment.\n"},
676  {"id": 8,
677  "content-type": "text/plain",
678  "content": "And this message is signed.\n\n-Carl\n"}]},
679  {"id": 9,
680  "content-type": "application/pgp-signature",
681  "content-length": 197}]}]}}
682 EOF
683 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)"
684
685 test_begin_subtest "'notmuch show --part' does not corrupt a part with CRLF pair"
686 notmuch show --format=raw --part=3 id:base64-part-with-crlf > crlf.out
687 echo -n -e "\xEF\x0D\x0A" > crlf.expected
688 test_expect_equal_file crlf.out crlf.expected
689
690
691 # The ISO-8859-1 encoding of U+00BD is a single byte: octal 275
692 # (Portability note: Dollar-Single ($'...', ANSI C-style escape sequences)
693 # quoting works on bash, ksh, zsh, *BSD sh but not on dash, ash nor busybox sh)
694 readonly u_00bd_latin1=$'\275'
695
696 # The Unicode fraction symbol 1/2 is U+00BD and is encoded
697 # in UTF-8 as two bytes: octal 302 275
698 readonly u_00bd_utf8=$'\302\275'
699
700 cat <<EOF > ${MAIL_DIR}/include-html
701 From: A <a@example.com>
702 To: B <b@example.com>
703 Subject: html message
704 Date: Sat, 01 January 2000 00:00:00 +0000
705 Message-ID: <htmlmessage>
706 MIME-Version: 1.0
707 Content-Type: multipart/alternative; boundary="==-=="
708
709 --==-==
710 Content-Type: text/html; charset=UTF-8
711
712 <p>0.5 equals ${u_00bd_utf8}</p>
713
714 --==-==
715 Content-Type: text/html; charset=ISO-8859-1
716
717 <p>0.5 equals ${u_00bd_latin1}</p>
718
719 --==-==
720 Content-Type: text/plain; charset=UTF-8
721
722 0.5 equals ${u_00bd_utf8}
723
724 --==-==--
725 EOF
726
727 notmuch new > /dev/null
728
729 cat_expected_head ()
730 {
731         cat <<EOF
732 [[[{"id": "htmlmessage", "match":true, "excluded": false, "date_relative":"2000-01-01",
733    "timestamp": 946684800,
734    "filename": ["${MAIL_DIR}/include-html"],
735    "tags": ["inbox", "unread"],
736    "headers": { "Date": "Sat, 01 Jan 2000 00:00:00 +0000", "From": "A <a@example.com>",
737                 "Subject": "html message", "To": "B <b@example.com>"},
738    "body": [{
739      "content-type": "multipart/alternative", "id": 1,
740 EOF
741 }
742
743 cat_expected_head > EXPECTED.nohtml
744 cat <<EOF >> EXPECTED.nohtml
745 "content": [
746   { "id": 2, "content-charset": "UTF-8", "content-length": 21, "content-type": "text/html"},
747   { "id": 3, "content-charset": "ISO-8859-1", "content-length": 20, "content-type": "text/html"},
748   { "id": 4, "content-type": "text/plain", "content": "0.5 equals \\u00bd\\n"}
749 ]}]},[]]]]
750 EOF
751
752 # Both the UTF-8 and ISO-8859-1 part should have U+00BD
753 cat_expected_head > EXPECTED.withhtml
754 cat <<EOF >> EXPECTED.withhtml
755 "content": [
756   { "id": 2, "content-type": "text/html", "content": "<p>0.5 equals \\u00bd</p>\\n"},
757   { "id": 3, "content-type": "text/html", "content": "<p>0.5 equals \\u00bd</p>\\n"},
758   { "id": 4, "content-type": "text/plain", "content": "0.5 equals \\u00bd\\n"}
759 ]}]},[]]]]
760 EOF
761
762 test_begin_subtest "html parts excluded by default"
763 notmuch show --format=json id:htmlmessage > OUTPUT
764 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED.nohtml)"
765
766 test_begin_subtest "html parts included"
767 notmuch show --format=json --include-html id:htmlmessage > OUTPUT
768 test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED.withhtml)"
769
770 test_begin_subtest "indexes mime-type #1"
771 output=$(notmuch search mimetype:application/unique_identifier | notmuch_search_sanitize)
772 test_expect_equal "$output" "thread:XXX   2014-01-12 [1/1] Todd; odd content types (inbox unread)"
773
774 test_begin_subtest "indexes mime-type #2"
775 output=$(notmuch search mimetype:text/some_other_identifier | notmuch_search_sanitize)
776 test_expect_equal "$output" "thread:XXX   2014-01-12 [1/1] Todd; odd content types (inbox unread)"
777
778 test_begin_subtest "indexes mime-type #3"
779 output=$(notmuch search from:todd and mimetype:multipart/alternative | notmuch_search_sanitize)
780 test_expect_equal "$output" "thread:XXX   2014-01-12 [1/1] Todd; odd content types (inbox unread)"
781
782 test_begin_subtest "case of Content-Disposition doesn't matter for indexing"
783 cat <<EOF > ${MAIL_DIR}/content-disposition
784 Return-path: <david@tethera.net>
785 Envelope-to: david@tethera.net
786 Delivery-date: Sun, 04 Oct 2015 09:16:03 -0300
787 Received: from gitolite.debian.net ([87.98.215.224])
788         by yantan.tethera.net with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128)
789         (Exim 4.80)
790         (envelope-from <david@tethera.net>)
791         id 1ZiiCx-0007iz-RK
792         for david@tethera.net; Sun, 04 Oct 2015 09:16:03 -0300
793 Received: from remotemail by gitolite.debian.net with local (Exim 4.80)
794         (envelope-from <david@tethera.net>)
795         id 1ZiiC8-0002Rz-Uf; Sun, 04 Oct 2015 12:15:12 +0000
796 Received: (nullmailer pid 28621 invoked by uid 1000); Sun, 04 Oct 2015
797  12:14:53 -0000
798 From: David Bremner <david@tethera.net>
799 To: David Bremner <david@tethera.net>
800 Subject: test attachment
801 User-Agent: Notmuch/0.20.2+93~g33c8777 (http://notmuchmail.org) Emacs/24.5.1
802  (x86_64-pc-linux-gnu)
803 Date: Sun, 04 Oct 2015 09:14:53 -0300
804 Message-ID: <87io6m96f6.fsf@zancas.localnet>
805 MIME-Version: 1.0
806 Content-Type: multipart/mixed; boundary="=-=-="
807
808 --=-=-=
809 Content-Type: text/plain
810 Content-Disposition: ATTACHMENT; filename=hello.txt
811 Content-Description: this is a very exciting file
812
813 hello
814
815 --=-=-=
816 Content-Type: text/plain
817
818
819 world
820
821 --=-=-=--
822
823 EOF
824 NOTMUCH_NEW
825
826 cat <<EOF > EXPECTED
827 attachment
828 inbox
829 unread
830 EOF
831
832 notmuch search --output=tags id:87io6m96f6.fsf@zancas.localnet > OUTPUT
833 test_expect_equal_file EXPECTED OUTPUT
834 test_done