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