]> diplodocus.org Git - nmh/blob - test/mhbuild/test-attach
Allow a RRULE in an iCalendar request to not have an INTERVAL on its
[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
18 LC_ALL=en_US.UTF-8; export LC_ALL
19
20 draft="$MH_TEST_DIR/$$.draft"
21 backup="${MH_TEST_DIR}/`mhparam sbackup`$$.draft.orig"
22 expected="$MH_TEST_DIR/$$.expected"
23
24 #
25 # Test out a simple draft, one part.
26 #
27
28 cat > "$draft" <<EOF
29 To: Mr Test <mrtest@example.com>
30 cc:
31 Fcc: +outbox
32 Nmh-Attach: ${srcdir}/test/mhbuild/tiny.jpg
33 ------
34 EOF
35
36 run_prog mhbuild "$draft"
37
38 cat > "$expected" <<EOF
39 To: Mr Test <mrtest@example.com>
40 cc:
41 Fcc: +outbox
42 MIME-Version: 1.0
43 Content-Type: image/jpeg; name="tiny.jpg"
44 Content-Description: tiny.jpg
45 Content-Disposition: attachment; filename="tiny.jpg"
46 Content-Transfer-Encoding: base64
47
48 /9g=
49 EOF
50
51 check "$draft" "$expected"
52
53 #
54 # Check 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 #
133
134 cat > "$draft" <<EOF
135 To: Mr Test <mrtest@example.com>
136 cc:
137 Fcc: +outbox
138 Subject: Test of an empty body
139 EOF
140
141 run_prog mhbuild "$draft"
142
143 cat > "$expected" <<EOF
144 To: Mr Test <mrtest@example.com>
145 cc:
146 Fcc: +outbox
147 Subject: Test of an empty body
148 MIME-Version: 1.0
149 Content-Type: text/plain
150 EOF
151
152 #
153 # Check an md5'd attachment
154 #
155
156 cat > "$draft" <<EOF
157 To: Mr Test <mrtest@example.com>
158 cc:
159 Fcc: +outbox
160 Subject: Test of digested part
161
162 #text/plain; name="textplain" [ - ] ${srcdir}/test/mhbuild/textplain
163
164 EOF
165
166 mhbuild -check "$draft"
167
168 cat > "$expected" <<EOF
169 To: Mr Test <mrtest@example.com>
170 cc:
171 Fcc: +outbox
172 Subject: Test of digested part
173 MIME-Version: 1.0
174 Content-Type: text/plain; name="textplain"; charset="us-ascii"
175 Content-Description: -
176 Content-MD5: x3hNJn10cGowZv+ILUkycw==
177 Content-Transfer-Encoding: quoted-printable
178
179 This is a text/plain part.
180 EOF
181
182 check "$draft" "$expected"
183
184 #
185 # Make sure we fail if we run into a MIME-Version header
186 #
187
188 cat > "$draft" <<EOF
189 To: Mr Test <mrtest@example.com>
190 cc:
191 Fcc: +outbox
192 Subject: Test of an already-MIMEified message
193 MIME-Version: 1.0
194 Content-Type: text/plain; charset="us-ascii"
195
196 This is a preformatted MIME content test.
197 EOF
198
199 set +e
200 run_test 'eval mhbuild "$draft"' "mhbuild: draft shouldn't contain MIME-Version: field"
201 set -e
202
203 #
204 # Run it again using -auto
205 #
206
207 run_prog mhbuild -auto "$draft"
208
209 cat > "$expected" <<EOF
210 To: Mr Test <mrtest@example.com>
211 cc:
212 Fcc: +outbox
213 Subject: Test of an already-MIMEified message
214 MIME-Version: 1.0
215 Content-Type: text/plain; charset="us-ascii"
216
217 This is a preformatted MIME content test.
218 EOF
219
220 check "$draft" "$expected"
221
222 #
223 # Make sure -dist does nothing but encode headers
224 #
225
226 cat > "$draft" <<EOF
227 To: Señor Test <mrtest@example.com>
228 cc:
229 Fcc: +outbox
230 Subject: An empty dist test
231 EOF
232
233 run_prog mhbuild -dist "$draft"
234
235 cat > "$expected" <<EOF
236 To: =?UTF-8?Q?Se=C3=B1or_Test?= <mrtest@example.com>
237 cc:
238 Fcc: +outbox
239 Subject: An empty dist test
240 EOF
241
242 check "$draft" "$expected"
243
244 #
245 # Two parts, one attachment; make sure mixing of multiparts at different
246 # levels works. This also tests Attach: instead of Nmh-Attach:.
247 #
248
249 cat > "$draft" <<EOF
250 To: Mr Test <mrtest@example.com>
251 cc:
252 Fcc: +outbox
253 Subject: A more complete multipart test
254 Attach: ${srcdir}/test/mhbuild/tiny.jpg
255 --------
256 #begin alternative
257 #<text/plain
258 This is some tëxt.
259 #<text/html
260 <html>
261 <body>
262 This is some HTML tëxt.
263 </body>
264 </html>
265 #end
266 EOF
267
268 run_prog mhbuild "$draft"
269
270 cat > "$expected" <<EOF
271 To: Mr Test <mrtest@example.com>
272 cc:
273 Fcc: +outbox
274 Subject: A more complete multipart test
275 MIME-Version: 1.0
276 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
277 Content-Transfer-Encoding: 8bit
278
279 ------- =_aaaaaaaaaa0
280 Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa1"
281 Content-Transfer-Encoding: 8bit
282
283 ------- =_aaaaaaaaaa1
284 Content-Type: text/plain; charset="UTF-8"
285 Content-Transfer-Encoding: 8bit
286
287 This is some tëxt.
288
289 ------- =_aaaaaaaaaa1
290 Content-Type: text/html; charset="UTF-8"
291 Content-Transfer-Encoding: 8bit
292
293 <html>
294 <body>
295 This is some HTML tëxt.
296 </body>
297 </html>
298
299 ------- =_aaaaaaaaaa1--
300
301 ------- =_aaaaaaaaaa0
302 Content-Type: image/jpeg; name="tiny.jpg"
303 Content-Description: tiny.jpg
304 Content-Disposition: attachment; filename="tiny.jpg"
305 Content-Transfer-Encoding: base64
306
307 /9g=
308
309 ------- =_aaaaaaaaaa0--
310 EOF
311
312 check "$draft" "$expected"
313
314 #
315 # One attachment, text/plain containing some binary characters,
316 # include NUL bytes.
317 #
318
319 cat > "$draft" <<EOF
320 To: Mr Test <mrtest@example.com>
321 cc:
322 Fcc: +outbox
323 Subject: Testing some binary chars
324 --------
325 This is some tëxt.
326 #text/plain; name="somebinary" [ - ] {attachment} ${srcdir}/test/mhbuild/somebinary
327 EOF
328
329 run_prog mhbuild "$draft"
330
331 cat > "$expected" <<EOF
332 To: Mr Test <mrtest@example.com>
333 cc:
334 Fcc: +outbox
335 Subject: Testing some binary chars
336 MIME-Version: 1.0
337 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
338 Content-Transfer-Encoding: 8bit
339
340 ------- =_aaaaaaaaaa0
341 Content-Type: text/plain; charset="UTF-8"
342 Content-Transfer-Encoding: 8bit
343
344 This is some tëxt.
345
346 ------- =_aaaaaaaaaa0
347 Content-Type: text/plain; name="somebinary"; charset="us-ascii"
348 Content-Description: -
349 Content-Disposition: attachment; filename="somebinary"
350 Content-Transfer-Encoding: quoted-printable
351
352
353 =46rom here on, this is only =
354
355 a test, though it contains =13ome
356 =00odd=00 bytes.
357
358 ------- =_aaaaaaaaaa0--
359 EOF
360
361 check "$draft" "$expected"
362
363 [ ${failed:=0} -eq 0 ] && rm -f ${backup}
364
365 exit ${failed:-0}