]> diplodocus.org Git - nmh/blob - test/mhbuild/test-attach
forw.man, mh-mime.man: Add missing commas in `SEE ALSO' list.
[nmh] / test / mhbuild / test-attach
1 #!/bin/sh
2 ######################################################
3 #
4 # Test the use of the Nmh-Attach: header
5 #
6 ######################################################
7
8 if test -z "${MH_OBJ_DIR}"; then
9 srcdir=`dirname "$0"`/../..
10 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
11 fi
12
13 . "$MH_OBJ_DIR/test/common.sh"
14
15 setup_test
16
17 require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8
18
19 draft="$MH_TEST_DIR/$$.draft"
20 backup="${MH_TEST_DIR}/`mhparam sbackup`$$.draft.orig"
21 expected="$MH_TEST_DIR/$$.expected"
22
23 #
24 # Test out a simple draft, one part.
25 #
26
27 cat > "$draft" <<EOF
28 To: Mr Test <mrtest@example.com>
29 cc:
30 Fcc: +outbox
31 Nmh-Attach: ${srcdir}/test/mhbuild/tiny.jpg
32 ------
33 EOF
34
35 run_prog mhbuild "$draft"
36
37 cat > "$expected" <<EOF
38 To: Mr Test <mrtest@example.com>
39 cc:
40 Fcc: +outbox
41 MIME-Version: 1.0
42 Content-Type: image/jpeg; name="tiny.jpg"
43 Content-Description: tiny.jpg
44 Content-Disposition: attachment; filename="tiny.jpg"
45 Content-Transfer-Encoding: base64
46
47 /9g=
48 EOF
49
50 check "$draft" "$expected"
51
52 #
53 # Check out more common case, one (or more) attachments
54 # along with message text.
55 #
56
57 cat > "$draft" <<EOF
58 To: Mr Test <mrtest@example.com>
59 cc:
60 Fcc: +outbox
61 Nmh-Attach: ${srcdir}/test/mhbuild/tiny.jpg
62 Nmh-Attach: ${srcdir}/test/mhbuild/nulls
63 ------
64 This is a test
65 EOF
66
67 run_prog mhbuild "$draft"
68
69 cat > "$expected" <<EOF
70 To: Mr Test <mrtest@example.com>
71 cc:
72 Fcc: +outbox
73 MIME-Version: 1.0
74 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
75
76 ------- =_aaaaaaaaaa0
77 Content-Type: text/plain; charset="us-ascii"
78
79 This is a test
80
81 ------- =_aaaaaaaaaa0
82 Content-Type: image/jpeg; name="tiny.jpg"
83 Content-Description: tiny.jpg
84 Content-Disposition: attachment; filename="tiny.jpg"
85 Content-Transfer-Encoding: base64
86
87 /9g=
88
89 ------- =_aaaaaaaaaa0
90 Content-Type: application/octet-stream; name="nulls"
91 Content-Description: nulls
92 Content-Disposition: attachment; filename="nulls"
93 Content-Transfer-Encoding: base64
94
95 AAAAAAAAAAAAAAAAAAAA
96
97 ------- =_aaaaaaaaaa0--
98 EOF
99
100 check "$draft" "$expected"
101
102 #
103 # An empty Attach header
104 #
105
106 cat > "$draft" <<EOF
107 To: Mr Test <mrtest@example.com>
108 cc:
109 Fcc: +outbox
110 Nmh-Attach:
111 ------
112 This is a test of an empty attach header.
113 EOF
114
115 run_prog mhbuild "$draft"
116
117 cat > "$expected" <<EOF
118 To: Mr Test <mrtest@example.com>
119 cc:
120 Fcc: +outbox
121 MIME-Version: 1.0
122 Content-Type: text/plain; charset="us-ascii"
123
124 This is a test of an empty attach header.
125 EOF
126
127 check "$draft" "$expected"
128
129 #
130 # Check a completely empty message
131 #
132
133 cat > "$draft" <<EOF
134 To: Mr Test <mrtest@example.com>
135 cc:
136 Fcc: +outbox
137 Subject: Test of an empty body
138 EOF
139
140 run_prog mhbuild "$draft"
141
142 cat > "$expected" <<EOF
143 To: Mr Test <mrtest@example.com>
144 cc:
145 Fcc: +outbox
146 Subject: Test of an empty body
147 MIME-Version: 1.0
148 Content-Type: text/plain
149 EOF
150
151 #
152 # Check an md5'd attachment
153 #
154
155 cat > "$draft" <<EOF
156 To: Mr Test <mrtest@example.com>
157 cc:
158 Fcc: +outbox
159 Subject: Test of digested part
160
161 #text/plain; name="textplain" [ - ] ${srcdir}/test/mhbuild/textplain
162
163 EOF
164
165 mhbuild -check "$draft"
166
167 cat > "$expected" <<EOF
168 To: Mr Test <mrtest@example.com>
169 cc:
170 Fcc: +outbox
171 Subject: Test of digested part
172 MIME-Version: 1.0
173 Content-Type: text/plain; name="textplain"; charset="us-ascii"
174 Content-Description: -
175 Content-MD5: x3hNJn10cGowZv+ILUkycw==
176 Content-Transfer-Encoding: quoted-printable
177
178 This is a text/plain part.
179 EOF
180
181 check "$draft" "$expected"
182
183 #
184 # Make sure we fail if we run into a MIME-Version header
185 #
186
187 cat > "$draft" <<EOF
188 To: Mr Test <mrtest@example.com>
189 cc:
190 Fcc: +outbox
191 Subject: Test of an already-MIMEified message
192 MIME-Version: 1.0
193 Content-Type: text/plain; charset="us-ascii"
194
195 This is a preformatted MIME content test.
196 EOF
197
198 set +e
199 run_test 'eval mhbuild "$draft"' "mhbuild: draft shouldn't contain MIME-Version: field"
200 set -e
201
202 #
203 # Run it again using -auto
204 #
205
206 run_prog mhbuild -auto "$draft"
207
208 cat > "$expected" <<EOF
209 To: Mr Test <mrtest@example.com>
210 cc:
211 Fcc: +outbox
212 Subject: Test of an already-MIMEified message
213 MIME-Version: 1.0
214 Content-Type: text/plain; charset="us-ascii"
215
216 This is a preformatted MIME content test.
217 EOF
218
219 check "$draft" "$expected"
220
221 #
222 # Make sure -dist does nothing but encode headers
223 #
224
225 cat > "$draft" <<EOF
226 To: Señor Test <mrtest@example.com>
227 cc:
228 Fcc: +outbox
229 Subject: An empty dist test
230 EOF
231
232 run_prog mhbuild -dist "$draft"
233
234 cat > "$expected" <<EOF
235 To: =?UTF-8?Q?Se=C3=B1or_Test?= <mrtest@example.com>
236 cc:
237 Fcc: +outbox
238 Subject: An empty dist test
239 EOF
240
241 check "$draft" "$expected"
242
243 #
244 # Two parts, one attachment; make sure mixing of multiparts at different
245 # levels works. This also tests Attach: instead of Nmh-Attach:.
246 #
247
248 cat > "$draft" <<EOF
249 To: Mr Test <mrtest@example.com>
250 cc:
251 Fcc: +outbox
252 Subject: A more complete multipart test
253 Attach: ${srcdir}/test/mhbuild/tiny.jpg
254 --------
255 #begin alternative
256 #<text/plain
257 This is some tëxt.
258 #<text/html
259 <html>
260 <body>
261 This is some HTML tëxt.
262 </body>
263 </html>
264 #end
265 EOF
266
267 run_prog mhbuild "$draft"
268
269 cat > "$expected" <<EOF
270 To: Mr Test <mrtest@example.com>
271 cc:
272 Fcc: +outbox
273 Subject: A more complete multipart test
274 MIME-Version: 1.0
275 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
276 Content-Transfer-Encoding: 8bit
277
278 ------- =_aaaaaaaaaa0
279 Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa1"
280 Content-Transfer-Encoding: 8bit
281
282 ------- =_aaaaaaaaaa1
283 Content-Type: text/plain; charset="UTF-8"
284 Content-Transfer-Encoding: 8bit
285
286 This is some tëxt.
287
288 ------- =_aaaaaaaaaa1
289 Content-Type: text/html; charset="UTF-8"
290 Content-Transfer-Encoding: 8bit
291
292 <html>
293 <body>
294 This is some HTML tëxt.
295 </body>
296 </html>
297
298 ------- =_aaaaaaaaaa1--
299
300 ------- =_aaaaaaaaaa0
301 Content-Type: image/jpeg; name="tiny.jpg"
302 Content-Description: tiny.jpg
303 Content-Disposition: attachment; filename="tiny.jpg"
304 Content-Transfer-Encoding: base64
305
306 /9g=
307
308 ------- =_aaaaaaaaaa0--
309 EOF
310
311 check "$draft" "$expected"
312
313 #
314 # One attachment, text/plain containing some binary characters,
315 # include NUL bytes.
316 #
317
318 cat > "$draft" <<EOF
319 To: Mr Test <mrtest@example.com>
320 cc:
321 Fcc: +outbox
322 Subject: Testing some binary chars
323 --------
324 This is some tëxt.
325 #text/plain; name="somebinary" [ - ] {attachment} ${srcdir}/test/mhbuild/somebinary
326 EOF
327
328 run_prog mhbuild "$draft"
329
330 cat > "$expected" <<EOF
331 To: Mr Test <mrtest@example.com>
332 cc:
333 Fcc: +outbox
334 Subject: Testing some binary chars
335 MIME-Version: 1.0
336 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
337 Content-Transfer-Encoding: 8bit
338
339 ------- =_aaaaaaaaaa0
340 Content-Type: text/plain; charset="UTF-8"
341 Content-Transfer-Encoding: 8bit
342
343 This is some tëxt.
344
345 ------- =_aaaaaaaaaa0
346 Content-Type: text/plain; name="somebinary"; charset="us-ascii"
347 Content-Description: -
348 Content-Disposition: attachment; filename="somebinary"
349 Content-Transfer-Encoding: quoted-printable
350
351
352 =46rom here on, this is only =
353
354 a test, though it contains =13ome
355 =00odd=00 bytes.
356
357 ------- =_aaaaaaaaaa0--
358 EOF
359
360 check "$draft" "$expected"
361
362 # check that blank line is inserted between header and content
363
364 cat > "$MH_TEST_DIR/Mail/oneline" <<EOF
365 There needs to be a blank line before this content line.
366 EOF
367
368 cat > "$draft" <<EOF
369 To: Mr Test <mrtest@example.com>
370 cc:
371 Fcc: +outbox
372 Subject: test blank line between header and content
373 --------
374 #text/plain {inline} $MH_TEST_DIR/Mail/oneline
375 #application/octet-stream {inline} $MH_TEST_DIR/Mail/oneline
376 EOF
377
378 run_prog mhbuild "$draft"
379
380 cat > "$expected" <<EOF
381 To: Mr Test <mrtest@example.com>
382 cc:
383 Fcc: +outbox
384 Subject: test blank line between header and content
385 MIME-Version: 1.0
386 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
387
388 ------- =_aaaaaaaaaa0
389 Content-Type: text/plain; charset="us-ascii"
390 Content-Disposition: inline; filename="oneline"
391
392 There needs to be a blank line before this content line.
393
394 ------- =_aaaaaaaaaa0
395 Content-Type: application/octet-stream
396 Content-Disposition: inline; filename="oneline"
397
398 There needs to be a blank line before this content line.
399
400 ------- =_aaaaaaaaaa0--
401 EOF
402
403 check "$draft" "$expected"
404
405
406 [ ${failed:=0} -eq 0 ] && rm -f ${backup}
407
408 exit ${failed:-0}