]> git.notmuchmail.org Git - notmuch/blob - test/multipart
Merge commit '0.6.1'
[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 notmuch new > /dev/null
92
93 test_begin_subtest "--format=text --part=0, full message"
94 notmuch show --format=text --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
95 cat <<EOF >EXPECTED
96 \fmessage{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 filename:${MAIL_DIR}/multipart
97 \fheader{
98 Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed unread)
99 Subject: Multipart message
100 From: Carl Worth <cworth@cworth.org>
101 To: cworth@cworth.org
102 Date: Tue, 05 Jan 2001 15:43:57 -0000
103 \fheader}
104 \fbody{
105 \fpart{ ID: 1, Content-type: multipart/signed
106 \fpart{ ID: 2, Content-type: multipart/mixed
107 \fpart{ ID: 3, Content-type: message/rfc822
108 \fpart{ ID: 4, Content-type: text/html
109 Non-text part: text/html
110 \fpart}
111 \fpart}
112 \fattachment{ ID: 5, Filename: attachment, Content-type: text/plain
113 This is a text attachment.
114 \fattachment}
115 \fpart{ ID: 6, Content-type: text/plain
116 And this message is signed.
117
118 -Carl
119 \fpart}
120 \fpart}
121 \fpart{ ID: 7, Content-type: application/pgp-signature
122 Non-text part: application/pgp-signature
123 \fpart}
124 \fpart}
125 \fbody}
126 \fmessage}
127 EOF
128 test_expect_equal_file OUTPUT EXPECTED
129
130 test_begin_subtest "--format=text --part=0, full message"
131 notmuch show --format=text --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
132 cat <<EOF >EXPECTED
133 \fmessage{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 filename:${MAIL_DIR}/multipart
134 \fheader{
135 Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed unread)
136 Subject: Multipart message
137 From: Carl Worth <cworth@cworth.org>
138 To: cworth@cworth.org
139 Date: Tue, 05 Jan 2001 15:43:57 -0000
140 \fheader}
141 \fbody{
142 \fpart{ ID: 1, Content-type: multipart/signed
143 \fpart{ ID: 2, Content-type: multipart/mixed
144 \fpart{ ID: 3, Content-type: message/rfc822
145 \fpart{ ID: 4, Content-type: text/html
146 Non-text part: text/html
147 \fpart}
148 \fpart}
149 \fattachment{ ID: 5, Filename: attachment, Content-type: text/plain
150 This is a text attachment.
151 \fattachment}
152 \fpart{ ID: 6, Content-type: text/plain
153 And this message is signed.
154
155 -Carl
156 \fpart}
157 \fpart}
158 \fpart{ ID: 7, Content-type: application/pgp-signature
159 Non-text part: application/pgp-signature
160 \fpart}
161 \fpart}
162 \fbody}
163 \fmessage}
164 EOF
165 test_expect_equal_file OUTPUT EXPECTED
166
167 test_begin_subtest "--format=text --part=2, multipart/mixed"
168 notmuch show --format=text --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
169 cat <<EOF >EXPECTED
170 \fpart{ ID: 2, Content-type: multipart/mixed
171 \fpart{ ID: 3, Content-type: message/rfc822
172 \fpart{ ID: 4, Content-type: text/html
173 Non-text part: text/html
174 \fpart}
175 \fpart}
176 \fattachment{ ID: 5, Filename: attachment, Content-type: text/plain
177 This is a text attachment.
178 \fattachment}
179 \fpart{ ID: 6, Content-type: text/plain
180 And this message is signed.
181
182 -Carl
183 \fpart}
184 \fpart}
185 EOF
186 test_expect_equal_file OUTPUT EXPECTED
187
188 test_begin_subtest "--format=text --part=3, rfc822 multipart"
189 notmuch show --format=text --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
190 cat <<EOF >EXPECTED
191 \fpart{ ID: 3, Content-type: message/rfc822
192 \fpart{ ID: 4, Content-type: text/html
193 Non-text part: text/html
194 \fpart}
195 \fpart}
196 EOF
197 test_expect_equal_file OUTPUT EXPECTED
198
199 test_begin_subtest "--format=text --part=4, html part"
200 notmuch show --format=text --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
201 cat <<EOF >EXPECTED
202 \fpart{ ID: 4, Content-type: text/html
203 Non-text part: text/html
204 \fpart}
205 EOF
206 test_expect_equal_file OUTPUT EXPECTED
207
208 test_begin_subtest "--format=text --part=5, inline attachment"
209 notmuch show --format=text --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
210 cat <<EOF >EXPECTED
211 \fattachment{ ID: 5, Filename: attachment, Content-type: text/plain
212 This is a text attachment.
213 \fattachment}
214 EOF
215 test_expect_equal_file OUTPUT EXPECTED
216
217 test_begin_subtest "--format=text --part=6, plain text part"
218 notmuch show --format=text --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
219 cat <<EOF >EXPECTED
220 \fpart{ ID: 6, Content-type: text/plain
221 And this message is signed.
222
223 -Carl
224 \fpart}
225 EOF
226 test_expect_equal_file OUTPUT EXPECTED
227
228 test_begin_subtest "--format=text --part=7, pgp signature (unverified)"
229 notmuch show --format=text --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
230 cat <<EOF >EXPECTED
231 \fpart{ ID: 7, Content-type: application/pgp-signature
232 Non-text part: application/pgp-signature
233 \fpart}
234 EOF
235 test_expect_equal_file OUTPUT EXPECTED
236
237 test_expect_success \
238     "--format=text --part=8, no part, expect error" \
239     "notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
240
241 test_begin_subtest "--format=json --part=0, full message"
242 output=$(notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org')
243 test_expect_equal "$output" \
244 '{"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"}]}]}'
245
246 test_begin_subtest "--format=json --part=1, message body"
247 output=$(notmuch show --format=json --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org')
248 test_expect_equal "$output" \
249 '{"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"}]}'
250
251 test_begin_subtest "--format=json --part=2, multipart/mixed"
252 output=$(notmuch show --format=json --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org')
253 test_expect_equal "$output" \
254 '{"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"}]}'
255 test_expect_equal_file OUTPUT EXPECTED
256
257 test_begin_subtest "--format=json --part=3, rfc822 multipart"
258 output=$(notmuch show --format=json --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org')
259 test_expect_equal "$output" \
260 '{"id": 3, "content-type": "message/rfc822", "content": [{"id": 4, "content-type": "text/html"}]}'
261 test_expect_equal_file OUTPUT EXPECTED
262
263 test_begin_subtest "--format=json --part=4, html part"
264 output=$(notmuch show --format=json --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org')
265 test_expect_equal "$output" \
266 '{"id": 4, "content-type": "text/html"}'
267
268 test_begin_subtest "--format=json --part=5, inline attachment"
269 output=$(notmuch show --format=json --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org')
270 test_expect_equal "$output" \
271 '{"id": 5, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}'
272
273 test_begin_subtest "--format=json --part=6, plain text part"
274 output=$(notmuch show --format=json --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org')
275 test_expect_equal "$output" \
276 '{"id": 6, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}'
277
278 test_begin_subtest "--format=json --part=7, pgp signature (unverified)"
279 output=$(notmuch show --format=json --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org')
280 test_expect_equal "$output" \
281 '{"id": 7, "content-type": "application/pgp-signature"}'
282
283 test_expect_success \
284     "--format=json --part=8, no part, expect error" \
285     "notmuch show --format=json --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
286
287 test_begin_subtest "--format=raw"
288 notmuch show --format=raw 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
289 test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart
290
291 test_begin_subtest "--format=raw --part=0, full message"
292 notmuch show --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
293 test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart
294
295 test_begin_subtest "--format=raw --part=1, message body"
296 notmuch show --format=raw --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
297 # output should *not* include newline
298 echo >>OUTPUT
299 cat <<EOF >EXPECTED
300 <p>This is an embedded message, with a single html part.</p>
301 This is a text attachment.
302 And this message is signed.
303
304 -Carl
305 -----BEGIN PGP SIGNATURE-----
306 Version: GnuPG v1.4.11 (GNU/Linux)
307
308 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
309 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
310 =zkga
311 -----END PGP SIGNATURE-----
312 EOF
313 test_expect_equal_file OUTPUT EXPECTED
314
315 test_begin_subtest "--format=raw --part=2, multipart/mixed"
316 notmuch show --format=raw --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
317 cat <<EOF >EXPECTED
318 <p>This is an embedded message, with a single html part.</p>
319 This is a text attachment.
320 And this message is signed.
321
322 -Carl
323 EOF
324 test_expect_equal_file OUTPUT EXPECTED
325
326 test_begin_subtest "--format=raw --part=3, rfc822 multipart"
327 notmuch show --format=raw --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
328 cat <<EOF >EXPECTED
329 <p>This is an embedded message, with a single html part.</p>
330 EOF
331 test_expect_equal_file OUTPUT EXPECTED
332
333 test_begin_subtest "--format=raw --part=4, html part"
334 notmuch show --format=raw --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
335 cat <<EOF >EXPECTED
336 <p>This is an embedded message, with a single html part.</p>
337 EOF
338 test_expect_equal_file OUTPUT EXPECTED
339
340 test_begin_subtest "--format=raw --part=5, inline attachment"
341 notmuch show --format=raw --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
342 cat <<EOF >EXPECTED
343 This is a text attachment.
344 EOF
345 test_expect_equal_file OUTPUT EXPECTED
346
347 test_begin_subtest "--format=raw --part=6, plain text part"
348 notmuch show --format=raw --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
349 cat <<EOF >EXPECTED
350 And this message is signed.
351
352 -Carl
353 EOF
354 test_expect_equal_file OUTPUT EXPECTED
355
356 test_begin_subtest "--format=raw --part=7, pgp signature (unverified)"
357 notmuch show --format=raw --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
358 # output should *not* include newline
359 echo >>OUTPUT
360 cat <<EOF >EXPECTED
361 -----BEGIN PGP SIGNATURE-----
362 Version: GnuPG v1.4.11 (GNU/Linux)
363
364 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
365 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
366 =zkga
367 -----END PGP SIGNATURE-----
368 EOF
369 test_expect_equal_file OUTPUT EXPECTED
370
371 test_expect_success \
372     "--format=raw --part=8, no part, expect error" \
373     "notmuch show --format=raw --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
374
375 test_begin_subtest "--format=mbox"
376 notmuch show --format=mbox 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
377 printf "From cworth@cworth.org Fri Jan  5 15:43:57 2001\n" >EXPECTED
378 cat "${MAIL_DIR}"/multipart >>EXPECTED
379 # mbox output is expected to include a blank line
380 echo >>EXPECTED
381 test_expect_equal_file OUTPUT EXPECTED
382
383 test_expect_success \
384     "--format=mbox --part=1, incompatible, expect error" \
385     "! notmuch show --format=mbox --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
386
387 test_begin_subtest "'notmuch reply' to a multipart message"
388 notmuch reply 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
389 cat <<EOF >EXPECTED
390 From: Notmuch Test Suite <test_suite@notmuchmail.org>
391 Subject: Re: Multipart message
392 To: Carl Worth <cworth@cworth.org>, cworth@cworth.org
393 In-Reply-To: <87liy5ap00.fsf@yoom.home.cworth.org>
394 References: <87liy5ap00.fsf@yoom.home.cworth.org>
395
396 On Tue, 05 Jan 2001 15:43:57 -0000, Carl Worth <cworth@cworth.org> wrote:
397 Non-text part: multipart/signed
398 Non-text part: multipart/mixed
399 Non-text part: message/rfc822
400 Non-text part: text/html
401 > This is a text attachment.
402 > And this message is signed.
403
404 > -Carl
405 Non-text part: application/pgp-signature
406 EOF
407 test_expect_equal_file OUTPUT EXPECTED
408
409 test_begin_subtest "'notmuch show --part' does not corrupt a part with CRLF pair"
410 notmuch show --format=raw --part=3 id:base64-part-with-crlf > crlf.out
411 echo -n -e "\xEF\x0D\x0A" > crlf.expected
412 test_expect_equal_file crlf.out crlf.expected
413
414 test_done