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