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