]> diplodocus.org Git - nmh/blob - test/mhbuild/test-ext-params
Don't `else' after return. Simplify control flow.
[nmh] / test / mhbuild / test-ext-params
1 #!/bin/sh
2 ######################################################
3 #
4 # Test the creation of RFC 2231 encoded parameters
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 # Try out a draft with some 8-bit encoded parameters
25 #
26
27 cat > "$draft" <<EOF
28 To: Mr Test <mrtest@example.com>
29 cc:
30 Fcc: +outbox
31 ------
32 This is a test message
33 #image/jpeg {attachment; filename="tïny.jpg"} ${srcdir}/test/mhbuild/tiny.jpg
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: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
44
45 ------- =_aaaaaaaaaa0
46 Content-Type: text/plain; charset="us-ascii"
47
48 This is a test message
49
50 ------- =_aaaaaaaaaa0
51 Content-Type: image/jpeg
52 Content-Disposition: attachment; filename*=UTF-8''t%C3%AFny.jpg
53 Content-Transfer-Encoding: base64
54
55 /9g=
56
57 ------- =_aaaaaaaaaa0--
58 EOF
59
60 check "$draft" "$expected"
61
62 #
63 # Try out a draft with some long parameters
64 #
65
66 cat > "$draft" <<EOF
67 To: Mr Test <mrtest@example.com>
68 cc:
69 Fcc: +outbox
70 ------
71 This is a test message
72 #image/jpeg {attachment; filename="This is an example of a rather long filename that is longer than would fit on a normal line.jpg"} \
73 ${srcdir}/test/mhbuild/tiny.jpg
74 EOF
75
76 run_prog mhbuild "$draft"
77
78 cat > "$expected" <<EOF
79 To: Mr Test <mrtest@example.com>
80 cc:
81 Fcc: +outbox
82 MIME-Version: 1.0
83 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
84
85 ------- =_aaaaaaaaaa0
86 Content-Type: text/plain; charset="us-ascii"
87
88 This is a test message
89
90 ------- =_aaaaaaaaaa0
91 Content-Type: image/jpeg
92 Content-Disposition: attachment;
93 filename*0="This is an example of a rather long filename that is lo";
94 filename*1="nger than would fit on a normal line.jpg"
95 Content-Transfer-Encoding: base64
96
97 /9g=
98
99 ------- =_aaaaaaaaaa0--
100 EOF
101
102 check "$draft" "$expected"
103
104 #
105 # Try out attach with a filename with 8-bit characters
106 #
107
108 cp "${srcdir}/test/mhbuild/tiny.jpg" "$MH_TEST_DIR/tïny.jpg"
109
110 cat > "$draft" <<EOF
111 To: Mr Test <mrtest@example.com>
112 cc:
113 Fcc: +outbox
114 Attach: $MH_TEST_DIR/tïny.jpg
115 ------
116 This is a test message
117 EOF
118
119 run_prog mhbuild "$draft"
120
121 cat > "$expected" <<EOF
122 To: Mr Test <mrtest@example.com>
123 cc:
124 Fcc: +outbox
125 MIME-Version: 1.0
126 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
127
128 ------- =_aaaaaaaaaa0
129 Content-Type: text/plain; charset="us-ascii"
130
131 This is a test message
132
133 ------- =_aaaaaaaaaa0
134 Content-Type: image/jpeg; name*=UTF-8''t%C3%AFny.jpg
135 Content-Description: =?UTF-8?B?dMOvbnkuanBn?=
136 Content-Disposition: attachment; filename*=UTF-8''t%C3%AFny.jpg
137 Content-Transfer-Encoding: base64
138
139 /9g=
140
141 ------- =_aaaaaaaaaa0--
142 EOF
143
144 check "$draft" "$expected"
145
146 #
147 # Alternate version; specify a disposion, but not an explicit filename
148 #
149
150 cat > "$draft" <<EOF
151 To: Mr Test <mrtest@example.com>
152 cc:
153 Fcc: +outbox
154 ------
155 This is a test message
156 #image/jpeg {attachment} $MH_TEST_DIR/tïny.jpg
157 EOF
158
159 run_prog mhbuild "$draft"
160
161 cat > "$expected" <<EOF
162 To: Mr Test <mrtest@example.com>
163 cc:
164 Fcc: +outbox
165 MIME-Version: 1.0
166 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
167
168 ------- =_aaaaaaaaaa0
169 Content-Type: text/plain; charset="us-ascii"
170
171 This is a test message
172
173 ------- =_aaaaaaaaaa0
174 Content-Type: image/jpeg
175 Content-Disposition: attachment; filename*=UTF-8''t%C3%AFny.jpg
176 Content-Transfer-Encoding: base64
177
178 /9g=
179
180 ------- =_aaaaaaaaaa0--
181 EOF
182
183 check "$draft" "$expected"
184
185 #
186 # Test to make sure things fail if we try to put 8-bit characters when the
187 # locale is US-ASCII
188 #
189
190 cat > "$draft" <<EOF
191 To: Mr Test <mrtest@example.com>
192 cc:
193 Fcc: +outbox
194 ------
195 This is a test message
196 #image/jpeg {attachment} $MH_TEST_DIR/tïny.jpg
197 EOF
198
199 old_locale="$LC_ALL"
200 LC_ALL=C; export LC_ALL
201
202 set +e
203 run_test 'eval mhbuild "$draft" 2>&1' 'mhbuild: 8-bit characters in parameter "filename", but local character set is US-ASCII'
204 set -e
205
206 LC_ALL="$old_locale"; export LC_ALL
207
208 rm -f "$MH_TEST_DIR/tïny.jpg"
209
210 #
211 # Test out message/external-body decoding
212 #
213
214 cat > "$draft" <<EOF
215 To: Mr Test <mrtest@example.com>
216 cc:
217 Fcc: +outbox
218 ------
219 This is a test message
220 #@application/octet-stream [Test of a long URL] {attachment; \
221 filename=test.tar.gz} access-type=url; url="http://www.example.com/this/is/an/example/of/a/very/long/url/that-should-be-wrapped/name.tar.gz"
222 EOF
223
224 run_prog mhbuild "$draft"
225
226 cat > "$expected" <<EOF
227 To: Mr Test <mrtest@example.com>
228 cc:
229 Fcc: +outbox
230 MIME-Version: 1.0
231 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
232
233 ------- =_aaaaaaaaaa0
234 Content-Type: text/plain; charset="us-ascii"
235
236 This is a test message
237
238 ------- =_aaaaaaaaaa0
239 Content-Type: message/external-body; access-type="url";
240 url*0="http://www.example.com/this/is/an/example/of/a/very/long/url";
241 url*1="/that-should-be-wrapped/name.tar.gz"
242
243 Content-Type: application/octet-stream
244 Content-Description: Test of a long URL
245 Content-Disposition: attachment; filename="test.tar.gz"
246
247 ------- =_aaaaaaaaaa0--
248 EOF
249
250 check "$draft" "$expected"
251
252 [ ${failed:=0} -eq 0 ] && rm -f ${backup}
253
254 exit ${failed:-0}