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