]> diplodocus.org Git - nmh/blob - test/mhbuild/test-attach
Fix base64 to handle text parts properly; currently this breaks mhfixmsg,
[nmh] / test / mhbuild / test-attach
1 #!/bin/sh
2 ######################################################
3 #
4 # Test the use of the 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 LC_ALL=en_US.UTF-8; export LC_ALL
18
19 draft="$MH_TEST_DIR/$$.draft"
20 expected="$MH_TEST_DIR/$$.expected"
21
22 #
23 # Test out a simple draft, one part.
24 #
25
26 cat > "$draft" <<EOF
27 To: Mr Test <mrtest@example.com>
28 cc:
29 Fcc: +outbox
30 Attach: ${srcdir}/test/mhbuild/tiny.jpg
31 ------
32 EOF
33
34 run_prog mhbuild "$draft"
35
36 cat > "$expected" <<EOF
37 To: Mr Test <mrtest@example.com>
38 cc:
39 Fcc: +outbox
40 MIME-Version: 1.0
41 Content-Type: image/jpeg; name="tiny.jpg"
42 Content-Description: tiny.jpg
43 Content-Disposition: attachment; filename="tiny.jpg"
44 Content-Transfer-Encoding: base64
45
46 /9g=
47 EOF
48
49 check "$draft" "$expected"
50
51 #
52 # Check out more common case, one (or more) attachments
53 # along with message text.
54 #
55
56 cat > "$draft" <<EOF
57 To: Mr Test <mrtest@example.com>
58 cc:
59 Fcc: +outbox
60 Attach: ${srcdir}/test/mhbuild/tiny.jpg
61 ------
62 This is a test
63 EOF
64
65 run_prog mhbuild "$draft"
66
67 cat > "$expected" <<EOF
68 To: Mr Test <mrtest@example.com>
69 cc:
70 Fcc: +outbox
71 MIME-Version: 1.0
72 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
73
74 ------- =_aaaaaaaaaa0
75 Content-Type: text/plain; charset="us-ascii"
76
77 This is a test
78
79 ------- =_aaaaaaaaaa0
80 Content-Type: image/jpeg; name="tiny.jpg"
81 Content-Description: tiny.jpg
82 Content-Disposition: attachment; filename="tiny.jpg"
83 Content-Transfer-Encoding: base64
84
85 /9g=
86
87 ------- =_aaaaaaaaaa0--
88 EOF
89
90 check "$draft" "$expected"
91
92 #
93 # An empty Attach header
94 #
95
96 cat > "$draft" <<EOF
97 To: Mr Test <mrtest@example.com>
98 cc:
99 Fcc: +outbox
100 Attach:
101 ------
102 This is a test of an empty attach header.
103 EOF
104
105 run_prog mhbuild "$draft"
106
107 cat > "$expected" <<EOF
108 To: Mr Test <mrtest@example.com>
109 cc:
110 Fcc: +outbox
111 MIME-Version: 1.0
112 Content-Type: text/plain; charset="us-ascii"
113
114 This is a test of an empty attach header.
115 EOF
116
117 check "$draft" "$expected"
118
119 #
120 # Check a completely empty message
121 #
122
123 cat > "$draft" <<EOF
124 To: Mr Test <mrtest@example.com>
125 cc:
126 Fcc: +outbox
127 Subject: Test of an empty body
128 EOF
129
130 run_prog mhbuild "$draft"
131
132 cat > "$expected" <<EOF
133 To: Mr Test <mrtest@example.com>
134 cc:
135 Fcc: +outbox
136 Subject: Test of an empty body
137 MIME-Version: 1.0
138 Content-Type: text/plain
139 EOF
140
141 check "$draft" "$expected"
142
143 #
144 # Make sure we fail if we run into a MIME-Version header
145 #
146
147 cat > "$draft" <<EOF
148 To: Mr Test <mrtest@example.com>
149 cc:
150 Fcc: +outbox
151 Subject: Test of an already-MIMEified message
152 MIME-Version: 1.0
153 Content-Type: text/plain; charset="us-ascii"
154
155 This is a preformatted MIME content test.
156 EOF
157
158 set +e
159 run_test 'eval mhbuild "$draft"' "mhbuild: draft shouldn't contain MIME-Version: field"
160 set -e
161
162 #
163 # Run it again using -auto
164 #
165
166 run_prog mhbuild -auto "$draft"
167
168 cat > "$expected" <<EOF
169 To: Mr Test <mrtest@example.com>
170 cc:
171 Fcc: +outbox
172 Subject: Test of an already-MIMEified message
173 MIME-Version: 1.0
174 Content-Type: text/plain; charset="us-ascii"
175
176 This is a preformatted MIME content test.
177 EOF
178
179 check "$draft" "$expected"
180
181 #
182 # Make sure -dist does nothing but encode headers
183 #
184
185 cat > "$draft" <<EOF
186 To: Señor Test <mrtest@example.com>
187 cc:
188 Fcc: +outbox
189 Subject: An empty dist test
190 EOF
191
192 run_prog mhbuild -dist "$draft"
193
194 cat > "$expected" <<EOF
195 To: =?UTF-8?Q?Se=C3=B1or_Test?= <mrtest@example.com>
196 cc:
197 Fcc: +outbox
198 Subject: An empty dist test
199 EOF
200
201 check "$draft" "$expected"
202
203 #
204 # Two parts, one attachment; make sure mixing of multiparts at different
205 # levels works
206 #
207
208 cat > "$draft" <<EOF
209 To: Mr Test <mrtest@example.com>
210 cc:
211 Fcc: +outbox
212 Subject: A more complete multipart test
213 Attach: ${srcdir}/test/mhbuild/tiny.jpg
214 --------
215 #begin alternative
216 #<text/plain
217 This is some tëxt.
218 #<text/html
219 <html>
220 <body>
221 This is some HTML tëxt.
222 </body>
223 </html>
224 #end
225 EOF
226
227 run_prog mhbuild "$draft"
228
229 cat > "$expected" <<EOF
230 To: Mr Test <mrtest@example.com>
231 cc:
232 Fcc: +outbox
233 Subject: A more complete multipart test
234 MIME-Version: 1.0
235 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
236
237 ------- =_aaaaaaaaaa0
238 Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa1"
239
240 ------- =_aaaaaaaaaa1
241 Content-Type: text/plain; charset="UTF-8"
242 Content-Transfer-Encoding: quoted-printable
243
244 This is some t=C3=ABxt.
245
246 ------- =_aaaaaaaaaa1
247 Content-Type: text/html; charset="UTF-8"
248 Content-Transfer-Encoding: quoted-printable
249
250 <html>
251 <body>
252 This is some HTML t=C3=ABxt.
253 </body>
254 </html>
255
256 ------- =_aaaaaaaaaa1--
257
258 ------- =_aaaaaaaaaa0
259 Content-Type: image/jpeg; name="tiny.jpg"
260 Content-Description: tiny.jpg
261 Content-Disposition: attachment; filename="tiny.jpg"
262 Content-Transfer-Encoding: base64
263
264 /9g=
265
266 ------- =_aaaaaaaaaa0--
267 EOF
268
269 check "$draft" "$expected"
270
271 exit ${failed:-0}