c80507875443071c9998f1540e3c8afe69d66795
[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 output=$(notmuch show --format=text --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org')
96 test_expect_equal "$output" \
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, Content-type: text/plain
114 Attachment: attachment (text/plain)
115 This is a text attachment.
116 \fattachment}
117 \fpart{ ID: 6, Content-type: text/plain
118 And this message is signed.
119
120 -Carl
121 \fpart}
122 \fpart}
123 \fpart{ ID: 7, Content-type: application/pgp-signature
124 Non-text part: application/pgp-signature
125 \fpart}
126 \fpart}
127 \fbody}
128 \fmessage}"
129
130 test_begin_subtest "--format=text --part=1, message body"
131 output=$(notmuch show --format=text --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org')
132 test_expect_equal "$output" \
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, Content-type: text/plain
141 Attachment: attachment (text/plain)
142 This is a text attachment.
143 \fattachment}
144 \fpart{ ID: 6, Content-type: text/plain
145 And this message is signed.
146
147 -Carl
148 \fpart}
149 \fpart}
150 \fpart{ ID: 7, Content-type: application/pgp-signature
151 Non-text part: application/pgp-signature
152 \fpart}
153 \fpart}"
154
155 test_begin_subtest "--format=text --part=2, multipart/mixed"
156 output=$(notmuch show --format=text --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org')
157 test_expect_equal "$output" \
158 "\fpart{ ID: 2, Content-type: multipart/mixed
159 \fpart{ ID: 3, Content-type: message/rfc822
160 \fpart{ ID: 4, Content-type: text/html
161 Non-text part: text/html
162 \fpart}
163 \fpart}
164 \fattachment{ ID: 5, Content-type: text/plain
165 Attachment: attachment (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
175 test_begin_subtest "--format=text --part=3, rfc822 multipart"
176 output=$(notmuch show --format=text --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org')
177 test_expect_equal "$output" \
178 "\fpart{ ID: 3, Content-type: message/rfc822
179 \fpart{ ID: 4, Content-type: text/html
180 Non-text part: text/html
181 \fpart}
182 \fpart}"
183
184 test_begin_subtest "--format=text --part=4, html part"
185 output=$(notmuch show --format=text --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org')
186 test_expect_equal "$output" \
187 "\fpart{ ID: 4, Content-type: text/html
188 Non-text part: text/html
189 \fpart}"
190
191 test_begin_subtest "--format=text --part=5, inline attachement"
192 output=$(notmuch show --format=text --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org')
193 test_expect_equal "$output" \
194 "\fattachment{ ID: 5, Content-type: text/plain
195 Attachment: attachment (text/plain)
196 This is a text attachment.
197 \fattachment}"
198
199 test_begin_subtest "--format=text --part=6, plain text part"
200 output=$(notmuch show --format=text --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org')
201 test_expect_equal "$output" \
202 "\fpart{ ID: 6, Content-type: text/plain
203 And this message is signed.
204
205 -Carl
206 \fpart}"
207
208 test_begin_subtest "--format=text --part=7, pgp signature (unverified)"
209 output=$(notmuch show --format=text --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org')
210 test_expect_equal "$output" \
211 "\fpart{ ID: 7, Content-type: application/pgp-signature
212 Non-text part: application/pgp-signature
213 \fpart}"
214
215 test_expect_success \
216     "--format=text --part=8, no part, expect error" \
217     "notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
218
219 test_begin_subtest "--format=json --part=0, full message"
220 output=$(notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org')
221 test_expect_equal "$output" \
222 '{"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"}]}]}'
223
224 test_begin_subtest "--format=json --part=1, message body"
225 output=$(notmuch show --format=json --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org')
226 test_expect_equal "$output" \
227 '{"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"}]}'
228
229 test_begin_subtest "--format=json --part=2, multipart/mixed"
230 output=$(notmuch show --format=json --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org')
231 test_expect_equal "$output" \
232 '{"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"}]}'
233
234 test_begin_subtest "--format=json --part=3, rfc822 multipart"
235 output=$(notmuch show --format=json --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org')
236 test_expect_equal "$output" \
237 '{"id": 3, "content-type": "message/rfc822", "content": [{"id": 4, "content-type": "text/html"}]}'
238
239 test_begin_subtest "--format=json --part=4, html part"
240 output=$(notmuch show --format=json --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org')
241 test_expect_equal "$output" \
242 '{"id": 4, "content-type": "text/html"}'
243
244 test_begin_subtest "--format=json --part=5, inline attachment"
245 output=$(notmuch show --format=json --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org')
246 test_expect_equal "$output" \
247 '{"id": 5, "content-type": "text/plain", "filename": "attachment", "content": "This is a text attachment.\n"}'
248
249 test_begin_subtest "--format=json --part=6, plain text part"
250 output=$(notmuch show --format=json --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org')
251 test_expect_equal "$output" \
252 '{"id": 6, "content-type": "text/plain", "content": "And this message is signed.\n\n-Carl\n"}'
253
254 test_begin_subtest "--format=json --part=7, pgp signature (unverified)"
255 output=$(notmuch show --format=json --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org')
256 test_expect_equal "$output" \
257 '{"id": 7, "content-type": "application/pgp-signature"}'
258
259 test_expect_success \
260     "--format=json --part=8, no part, expect error" \
261     "notmuch show --format=json --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
262
263 test_begin_subtest "--format=raw"
264 output=$(notmuch show --format=raw 'id:87liy5ap00.fsf@yoom.home.cworth.org')
265 test_expect_equal "$output" "$(cat "${MAIL_DIR}"/multipart)"
266
267 test_begin_subtest "--format=raw --part=0, full message"
268 output=$(notmuch show --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org')
269 test_expect_equal "$output" "$(cat "${MAIL_DIR}"/multipart)"
270
271 test_begin_subtest "--format=raw --part=1, message body"
272 output=$(notmuch show --format=raw --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org')
273 test_expect_equal "$output" \
274 '<p>This is an embedded message, with a single html part.</p>
275 This is a text attachment.
276 And this message is signed.
277
278 -Carl
279 -----BEGIN PGP SIGNATURE-----
280 Version: GnuPG v1.4.11 (GNU/Linux)
281
282 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
283 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
284 =zkga
285 -----END PGP SIGNATURE-----'
286
287 test_begin_subtest "--format=raw --part=2, multipart/mixed"
288 output=$(notmuch show --format=raw --part=2 'id:87liy5ap00.fsf@yoom.home.cworth.org')
289 test_expect_equal "$output" \
290 '<p>This is an embedded message, with a single html part.</p>
291 This is a text attachment.
292 And this message is signed.
293
294 -Carl'
295
296 test_begin_subtest "--format=raw --part=3, rfc822 multipart"
297 output=$(notmuch show --format=raw --part=3 'id:87liy5ap00.fsf@yoom.home.cworth.org')
298 test_expect_equal "$output" \
299 '<p>This is an embedded message, with a single html part.</p>'
300
301 test_begin_subtest "--format=raw --part=4, html part"
302 output=$(notmuch show --format=raw --part=4 'id:87liy5ap00.fsf@yoom.home.cworth.org')
303 test_expect_equal "$output" \
304 '<p>This is an embedded message, with a single html part.</p>'
305
306 test_begin_subtest "--format=raw --part=5, inline attachment"
307 output=$(notmuch show --format=raw --part=5 'id:87liy5ap00.fsf@yoom.home.cworth.org')
308 test_expect_equal "$output" \
309 'This is a text attachment.'
310
311 test_begin_subtest "--format=raw --part=6, plain text part"
312 output=$(notmuch show --format=raw --part=6 'id:87liy5ap00.fsf@yoom.home.cworth.org')
313 test_expect_equal "$output" \
314 'And this message is signed.
315
316 -Carl'
317
318 test_begin_subtest "--format=raw --part=7, pgp signature (unverified)"
319 output=$(notmuch show --format=raw --part=7 'id:87liy5ap00.fsf@yoom.home.cworth.org')
320 test_expect_equal "$output" \
321 '-----BEGIN PGP SIGNATURE-----
322 Version: GnuPG v1.4.11 (GNU/Linux)
323
324 iEYEARECAAYFAk3SA/gACgkQ6JDdNq8qSWj0sACghqVJEQJUs3yV8zbTzhgnSIcD
325 W6cAmQE4dcYrx/LPLtYLZm1jsGauE5hE
326 =zkga
327 -----END PGP SIGNATURE-----'
328
329 test_expect_success \
330     "--format=raw --part=8, no part, expect error" \
331     "notmuch show --format=raw --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
332
333 test_begin_subtest "--format=mbox"
334 output=$(notmuch show --format=mbox 'id:87liy5ap00.fsf@yoom.home.cworth.org')
335 test_expect_equal "$output" "$(printf "From cworth@cworth.org Fri Jan  5 15:43:57 2001\n"; cat "${MAIL_DIR}"/multipart)"
336
337 test_expect_success \
338     "--format=mbox --part=1, incompatible, expect error" \
339     "! notmuch show --format=mbox --part=1 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
340
341 test_begin_subtest "'notmuch reply' to a multipart message"
342 output=$(notmuch reply 'id:87liy5ap00.fsf@yoom.home.cworth.org')
343 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
344 Subject: Re: Multipart message
345 To: Carl Worth <cworth@cworth.org>, cworth@cworth.org
346 In-Reply-To: <87liy5ap00.fsf@yoom.home.cworth.org>
347 References: <87liy5ap00.fsf@yoom.home.cworth.org>
348
349 On Tue, 05 Jan 2001 15:43:57 -0000, Carl Worth <cworth@cworth.org> wrote:
350 Non-text part: multipart/signed
351 Non-text part: multipart/mixed
352 Non-text part: message/rfc822
353 Non-text part: text/html
354 > This is a text attachment.
355 > And this message is signed.
356
357 > -Carl
358 Non-text part: application/pgp-signature"
359
360 test_begin_subtest "'notmuch show --part' does not corrupt a part with CRLF pair"
361 notmuch show --format=raw --part=3 id:base64-part-with-crlf > crlf.out
362 echo -n -e "\xEF\x0D\x0A" > crlf.expected
363 test_expect_equal_file crlf.out crlf.expected
364
365 test_done