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