]> diplodocus.org Git - nmh/blob - test/mhbuild/test-attach
Merge branch 'extended-params'
[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 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 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 Attach: ${srcdir}/test/mhbuild/tiny.jpg
62 ------
63 This is a test
64 EOF
65
66 run_prog mhbuild "$draft"
67
68 cat > "$expected" <<EOF
69 To: Mr Test <mrtest@example.com>
70 cc:
71 Fcc: +outbox
72 MIME-Version: 1.0
73 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
74
75 ------- =_aaaaaaaaaa0
76 Content-Type: text/plain; charset="us-ascii"
77
78 This is a test
79
80 ------- =_aaaaaaaaaa0
81 Content-Type: image/jpeg; name="tiny.jpg"
82 Content-Description: tiny.jpg
83 Content-Disposition: attachment; filename="tiny.jpg"
84 Content-Transfer-Encoding: base64
85
86 /9g=
87
88 ------- =_aaaaaaaaaa0--
89 EOF
90
91 check "$draft" "$expected"
92
93 #
94 # An empty Attach header
95 #
96
97 cat > "$draft" <<EOF
98 To: Mr Test <mrtest@example.com>
99 cc:
100 Fcc: +outbox
101 Attach:
102 ------
103 This is a test of an empty attach header.
104 EOF
105
106 run_prog mhbuild "$draft"
107
108 cat > "$expected" <<EOF
109 To: Mr Test <mrtest@example.com>
110 cc:
111 Fcc: +outbox
112 MIME-Version: 1.0
113 Content-Type: text/plain; charset="us-ascii"
114
115 This is a test of an empty attach header.
116 EOF
117
118 check "$draft" "$expected"
119
120 #
121 # Check a completely empty message
122 #
123
124 cat > "$draft" <<EOF
125 To: Mr Test <mrtest@example.com>
126 cc:
127 Fcc: +outbox
128 Subject: Test of an empty body
129 EOF
130
131 run_prog mhbuild "$draft"
132
133 cat > "$expected" <<EOF
134 To: Mr Test <mrtest@example.com>
135 cc:
136 Fcc: +outbox
137 Subject: Test of an empty body
138 MIME-Version: 1.0
139 Content-Type: text/plain
140 EOF
141
142 check "$draft" "$expected"
143
144 #
145 # Make sure we fail if we run into a MIME-Version header
146 #
147
148 cat > "$draft" <<EOF
149 To: Mr Test <mrtest@example.com>
150 cc:
151 Fcc: +outbox
152 Subject: Test of an already-MIMEified message
153 MIME-Version: 1.0
154 Content-Type: text/plain; charset="us-ascii"
155
156 This is a preformatted MIME content test.
157 EOF
158
159 set +e
160 run_test 'eval mhbuild "$draft"' "mhbuild: draft shouldn't contain MIME-Version: field"
161 set -e
162
163 #
164 # Run it again using -auto
165 #
166
167 run_prog mhbuild -auto "$draft"
168
169 cat > "$expected" <<EOF
170 To: Mr Test <mrtest@example.com>
171 cc:
172 Fcc: +outbox
173 Subject: Test of an already-MIMEified message
174 MIME-Version: 1.0
175 Content-Type: text/plain; charset="us-ascii"
176
177 This is a preformatted MIME content test.
178 EOF
179
180 check "$draft" "$expected"
181
182 #
183 # Make sure -dist does nothing but encode headers
184 #
185
186 cat > "$draft" <<EOF
187 To: Señor Test <mrtest@example.com>
188 cc:
189 Fcc: +outbox
190 Subject: An empty dist test
191 EOF
192
193 run_prog mhbuild -dist "$draft"
194
195 cat > "$expected" <<EOF
196 To: =?UTF-8?Q?Se=C3=B1or_Test?= <mrtest@example.com>
197 cc:
198 Fcc: +outbox
199 Subject: An empty dist test
200 EOF
201
202 check "$draft" "$expected"
203
204 #
205 # Two parts, one attachment; make sure mixing of multiparts at different
206 # levels works
207 #
208
209 cat > "$draft" <<EOF
210 To: Mr Test <mrtest@example.com>
211 cc:
212 Fcc: +outbox
213 Subject: A more complete multipart test
214 Attach: ${srcdir}/test/mhbuild/tiny.jpg
215 --------
216 #begin alternative
217 #<text/plain
218 This is some tëxt.
219 #<text/html
220 <html>
221 <body>
222 This is some HTML tëxt.
223 </body>
224 </html>
225 #end
226 EOF
227
228 run_prog mhbuild "$draft"
229
230 cat > "$expected" <<EOF
231 To: Mr Test <mrtest@example.com>
232 cc:
233 Fcc: +outbox
234 Subject: A more complete multipart test
235 MIME-Version: 1.0
236 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
237 Content-Transfer-Encoding: 8bit
238
239 ------- =_aaaaaaaaaa0
240 Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa1"
241 Content-Transfer-Encoding: 8bit
242
243 ------- =_aaaaaaaaaa1
244 Content-Type: text/plain; charset="UTF-8"
245 Content-Transfer-Encoding: 8bit
246
247 This is some tëxt.
248
249 ------- =_aaaaaaaaaa1
250 Content-Type: text/html; charset="UTF-8"
251 Content-Transfer-Encoding: 8bit
252
253 <html>
254 <body>
255 This is some HTML tëxt.
256 </body>
257 </html>
258
259 ------- =_aaaaaaaaaa1--
260
261 ------- =_aaaaaaaaaa0
262 Content-Type: image/jpeg; name="tiny.jpg"
263 Content-Description: tiny.jpg
264 Content-Disposition: attachment; filename="tiny.jpg"
265 Content-Transfer-Encoding: base64
266
267 /9g=
268
269 ------- =_aaaaaaaaaa0--
270 EOF
271
272 check "$draft" "$expected"
273
274 [ ${failed:=0} -eq 0 ] && rm -f ${backup}
275
276 exit ${failed:-0}