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