]> diplodocus.org Git - nmh/blob - test/mhbuild/test-header-encode
Make it so we always return the chosen mechanism, even if we aren't
[nmh] / test / mhbuild / test-header-encode
1 #!/bin/sh
2 ######################################################
3 #
4 # Test encoding headers according to RFC 2047
5 #
6 ######################################################
7
8 set -e
9
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirname "$0"`/../..
12 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
13 fi
14
15 . "${MH_OBJ_DIR}/test/common.sh"
16
17 setup_test
18 testname="${MH_TEST_DIR}/$$"
19 backupname="${MH_TEST_DIR}/`mhparam sbackup`$$"
20
21 #
22 # We're going to hardcode UTF-8 for this test.
23 #
24 require_locale en_US.utf-8 en_US.utf8
25 LC_ALL=en_US.UTF-8; export LC_ALL
26
27 #
28 # Basic test of encoding a short subject
29 #
30 cat > "${testname}.basic.actual" <<EOF
31 From: Mr Foo Bar <foobar@example.com>
32 To: Somebody <somebody@example.com>
33 Subject: This is ä test
34
35 This is a test
36 EOF
37
38 cat > "${testname}.basic.expected" <<EOF
39 From: Mr Foo Bar <foobar@example.com>
40 To: Somebody <somebody@example.com>
41 Subject: =?UTF-8?Q?This_is_=C3=A4_test?=
42 MIME-Version: 1.0
43 Content-Type: text/plain; charset="us-ascii"
44
45 This is a test
46 EOF
47
48 run_prog mhbuild "${testname}.basic.actual"
49
50 check "${testname}.basic.actual" "${testname}.basic.expected" 'keep first'
51
52 #
53 # Make sure we can undo the encoding
54 #
55
56 run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test'
57
58 rm -f "${testname}.basic.actual"
59
60 #
61 # Basic test of encoding a short subject, but with base64
62 #
63 cat > "${testname}.basic.actual" <<EOF
64 From: Mr Foo Bar <foobar@example.com>
65 To: Somebody <somebody@example.com>
66 Subject: This is ä test
67
68 This is a test
69 EOF
70
71 cat > "${testname}.basic.expected" <<EOF
72 From: Mr Foo Bar <foobar@example.com>
73 To: Somebody <somebody@example.com>
74 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0ZXN0?=
75 MIME-Version: 1.0
76 Content-Type: text/plain; charset="us-ascii"
77
78 This is a test
79 EOF
80
81 run_prog mhbuild -headerencoding base64 "${testname}.basic.actual"
82
83 check "${testname}.basic.actual" "${testname}.basic.expected" 'keep first'
84
85 run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test'
86
87 rm -f "${testname}.basic.actual" "${backupname}.basic.actual.orig"
88
89 #
90 # Have a subject that will pick base64 as the shorter encoding
91 #
92
93 cat > "${testname}.autopick.actual" <<EOF
94 From: Mr Foo Bar <foobar@example.com>
95 To: Somebody <somebody@example.com>
96 Subject: This is ä tëst©
97
98 This is a test
99 EOF
100
101 cat > "${testname}.autopick.expected" <<EOF
102 From: Mr Foo Bar <foobar@example.com>
103 To: Somebody <somebody@example.com>
104 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdMKp?=
105 MIME-Version: 1.0
106 Content-Type: text/plain; charset="us-ascii"
107
108 This is a test
109 EOF
110
111 run_prog mhbuild "${testname}.autopick.actual"
112
113 check "${testname}.autopick.actual" "${testname}.autopick.expected" 'keep first'
114
115 run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.autopick.actual"' 'This is ä tëst©'
116
117 rm -f "${testname}.autopick.actual" "${backupname}.autopick.actual.orig"
118
119 #
120 # Tests using longer subject lines.
121 #
122
123 cat > "${testname}.longsubject1.actual" <<EOF
124 From: Mr Foo Bar <foobar@example.com>
125 To: Somebody <somebody@example.com>
126 Subject: This is ä tëst of a rather long sübject line; will it overflow
127 the line length? I sure hope thät ='s and _'s are encoded properly. Will
128 they be?
129
130 This is a test of a very long subject line.
131 EOF
132
133 cat > "${testname}.longsubject1.expected" <<EOF
134 From: Mr Foo Bar <foobar@example.com>
135 To: Somebody <somebody@example.com>
136 Subject: =?UTF-8?Q?This_is_=C3=A4_t=C3=ABst_of_a_rather_long_s=C3=BCbject_?=
137 =?UTF-8?Q?line;_will_it_overflow_the_line_length=3F__I_sure_hope_?=
138 =?UTF-8?Q?th=C3=A4t_=3D's_and_=5F's_are_encoded_properly.__Will_t?=
139 =?UTF-8?Q?hey_be=3F?=
140 MIME-Version: 1.0
141 Content-Type: text/plain; charset="us-ascii"
142
143 This is a test of a very long subject line.
144 EOF
145
146 run_prog mhbuild "${testname}.longsubject1.actual"
147
148 check "${testname}.longsubject1.actual" "${testname}.longsubject1.expected" 'keep first'
149
150 run_test 'eval fmttest -outsize max -format "%(putlit(decode(trim{subject})))" -message -file "${testname}.longsubject1.actual"' "This is ä tëst of a rather long sübject line; will it overflow the line length? I sure hope thät ='s and _'s are encoded properly. Will they be?"
151
152 rm -f "${testname}.longsubject1.actual" "${backupname}.longsubject1.actual.orig"
153
154 #
155 # Test a longer line with base64 encoding
156 #
157
158 cat > "${testname}.longsubject2.actual" <<EOF
159 From: Mr Foo Bar <foobar@example.com>
160 To: Somebody <somebody@example.com>
161 Subject: This is ä tëst øf ä räthër løng sübjëct line; will it øvërfløw
162 the line length? I sure hope thät ='s and "'s are encoded properly. Will
163 they be?
164
165 This is a test of a very long subject line using base64.
166 EOF
167
168 cat > "${testname}.longsubject2.expected" <<EOF
169 From: Mr Foo Bar <foobar@example.com>
170 To: Somebody <somebody@example.com>
171 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdCDDuGYgw6QgcsOkdGjDq3IgbMO4bmcg?=
172 =?UTF-8?B?c8O8YmrDq2N0IGxpbmU7IHdpbGwgaXQgw7h2w6tyZmzDuHcgdGhl?=
173 =?UTF-8?B?IGxpbmUgbGVuZ3RoPyAgSSBzdXJlIGhvcGUgdGjDpHQgPSdzIGFu?=
174 =?UTF-8?B?ZCAiJ3MgYXJlIGVuY29kZWQgcHJvcGVybHkuICBXaWxsIHRoZXkg?=
175 =?UTF-8?B?YmU/?=
176 MIME-Version: 1.0
177 Content-Type: text/plain; charset="us-ascii"
178
179 This is a test of a very long subject line using base64.
180 EOF
181
182 run_prog mhbuild "${testname}.longsubject2.actual"
183
184 check "${testname}.longsubject2.actual" "${testname}.longsubject2.expected" 'keep first'
185
186 run_test 'eval fmttest -outsize max -format "%(putlit(decode(trim{subject})))" -message -file "${testname}.longsubject2.actual"' "This is ä tëst øf ä räthër løng sübjëct line; will it øvërfløw the line length? I sure hope thät ='s and \"'s are encoded properly. Will they be?"
187
188 rm -f "${testname}.longsubject2.actual" "${backupname}.longsubject2.actual.orig"
189
190 #
191 # Another long test, but make sure multibyte characters are not split across
192 # RFC-2047 tokens (prohibited by the standard). Test both quoted-printable
193 # and base64
194 #
195
196 cat > "${testname}.longsubject3.actual" <<EOF
197 From: Mr Foo Bar <foobar@example.com>
198 To: Somebody <somebody@example.com>
199 Subject: This is a test of a big UTF-8 multibyte character (😉); will
200 this work properly, or will it get truncated? 😨! Hopefully not
201
202 This is another long test.
203 EOF
204
205 cat > "${testname}.longsubject3.expected" <<EOF
206 From: Mr Foo Bar <foobar@example.com>
207 To: Somebody <somebody@example.com>
208 Subject: =?UTF-8?Q?This_is_a_test_of_a_big_UTF-8_multibyte_character_(?=
209 =?UTF-8?Q?=F0=9F=98=89);_will_this_work_properly,_or_will_it_get_?=
210 =?UTF-8?Q?truncated=3F_=F0=9F=98=A8!_Hopefully_not?=
211 MIME-Version: 1.0
212 Content-Type: text/plain; charset="us-ascii"
213
214 This is another long test.
215 EOF
216
217 run_prog mhbuild "${testname}.longsubject3.actual"
218
219 check "${testname}.longsubject3.actual" "${testname}.longsubject3.expected" 'keep first'
220
221 run_test 'eval fmttest -outsize max -format "%(putlit(decode(trim{subject})))" -message -file "${testname}.longsubject3.actual"' "This is a test of a big UTF-8 multibyte character (😉); will this work properly, or will it get truncated? 😨! Hopefully not"
222
223 rm -f "${testname}.longsubject3.actual" "${backupname}.longsubject3.actual.orig"
224
225 cat > "${testname}.longsubject4.actual" <<EOF
226 From: Mr Foo Bar <foobar@example.com>
227 To: Somebody <somebody@example.com>
228 Subject: This is ä tëst øf å big ÜTF-8 (😉) mültibyte character; will
229 this wørk prøperly, ør will it get trµnᴬted? 😨! Hopefully nøt
230
231 This is another long test.
232 EOF
233
234 cat > "${testname}.longsubject4.expected" <<EOF
235 From: Mr Foo Bar <foobar@example.com>
236 To: Somebody <somebody@example.com>
237 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdCDDuGYgw6UgYmlnIMOcVEYtOCAo?=
238 =?UTF-8?B?8J+YiSkgbcO8bHRpYnl0ZSBjaGFyYWN0ZXI7IHdpbGwgdGhpcyB3?=
239 =?UTF-8?B?w7hyayBwcsO4cGVybHksIMO4ciB3aWxsIGl0IGdldCB0csK1bg==?=
240 =?UTF-8?B?4bSsdGVkPyDwn5ioISBIb3BlZnVsbHkgbsO4dA==?=
241 MIME-Version: 1.0
242 Content-Type: text/plain; charset="us-ascii"
243
244 This is another long test.
245 EOF
246
247 run_prog mhbuild "${testname}.longsubject4.actual"
248
249 check "${testname}.longsubject4.actual" "${testname}.longsubject4.expected" 'keep first'
250
251 run_test 'eval fmttest -outsize max -format "%(putlit(decode(trim{subject})))" -message -file "${testname}.longsubject4.actual"' "This is ä tëst øf å big ÜTF-8 (😉) mültibyte character; will this wørk prøperly, ør will it get trµnᴬted? 😨! Hopefully nøt"
252
253 rm -f "${testname}.longsubject4.actual" "${backupname}.longsubject4.actual.orig"
254
255 #
256 # Test out some basic email address encoding
257 #
258
259 cat > "${testname}.basicemail1.actual" <<EOF
260 From: Mr Foo Bär <foobar@example.com>
261 To: Somebody <somebody@example.com>
262 Subject: Impørtant stuff
263
264 This is important information
265 EOF
266
267 cat > "${testname}.basicemail1.expected" <<EOF
268 From: =?UTF-8?Q?Mr_Foo_B=C3=A4r?= <foobar@example.com>
269 To: Somebody <somebody@example.com>
270 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
271 MIME-Version: 1.0
272 Content-Type: text/plain; charset="us-ascii"
273
274 This is important information
275 EOF
276
277 run_prog mhbuild "${testname}.basicemail1.actual"
278
279 check "${testname}.basicemail1.actual" "${testname}.basicemail1.expected" 'keep first'
280
281 run_test 'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail1.actual"' "Mr Foo Bär <foobar@example.com>"
282 run_test 'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail1.actual"' "Mr Foo Bär"
283
284 rm -f "${testname}.basicemail1.actual" "${backupname}.basicemail1.actual.orig"
285
286 cat > "${testname}.basicemail2.actual" <<EOF
287 From: foobar@example.com (Mr Foo Bär)
288 To: Somebody <somebody@example.com>
289 Subject: Impørtant stuff
290
291 This is important information
292 EOF
293
294 cat > "${testname}.basicemail2.expected" <<EOF
295 From: foobar@example.com (=?UTF-8?Q?Mr_Foo_B=C3=A4r?=)
296 To: Somebody <somebody@example.com>
297 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
298 MIME-Version: 1.0
299 Content-Type: text/plain; charset="us-ascii"
300
301 This is important information
302 EOF
303
304 run_prog mhbuild "${testname}.basicemail2.actual"
305
306 check "${testname}.basicemail2.actual" "${testname}.basicemail2.expected" 'keep first'
307
308 run_test 'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail2.actual"' "foobar@example.com (Mr Foo Bär)"
309 run_test 'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail2.actual"' "Mr Foo Bär"
310
311 rm -f "${testname}.basicemail2.actual" "${backupname}.basicemail2.actual.orig"
312
313 #
314 # Make sure the base64 encoder is tested as well
315 #
316
317 cat > "${testname}.basicemail3.actual" <<EOF
318 From: Mr Føø Bär <foobar@example.com>
319 To: Somebody <somebody@example.com>
320 Subject: Impørtant stuff
321
322 This is important information
323 EOF
324
325 cat > "${testname}.basicemail3.expected" <<EOF
326 From: =?UTF-8?B?TXIgRsO4w7ggQsOkcg==?= <foobar@example.com>
327 To: Somebody <somebody@example.com>
328 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
329 MIME-Version: 1.0
330 Content-Type: text/plain; charset="us-ascii"
331
332 This is important information
333 EOF
334
335 run_prog mhbuild "${testname}.basicemail3.actual"
336
337 check "${testname}.basicemail3.actual" "${testname}.basicemail3.expected" 'keep first'
338
339 run_test 'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail3.actual"' "Mr Føø Bär <foobar@example.com>"
340 run_test 'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail3.actual"' "Mr Føø Bär"
341
342 rm -f "${testname}.basicemail3.actual" "${backupname}.basicemail3.actual.orig"
343
344 cat > "${testname}.basicemail4.actual" <<EOF
345 From: foobar@example.com (Mr Føø Bär)
346 To: Somebody <somebody@example.com>
347 Subject: Impørtant stuff
348
349 This is important information
350 EOF
351
352 cat > "${testname}.basicemail4.expected" <<EOF
353 From: foobar@example.com (=?UTF-8?B?TXIgRsO4w7ggQsOkcg==?=)
354 To: Somebody <somebody@example.com>
355 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
356 MIME-Version: 1.0
357 Content-Type: text/plain; charset="us-ascii"
358
359 This is important information
360 EOF
361
362 run_prog mhbuild "${testname}.basicemail4.actual"
363
364 check "${testname}.basicemail4.actual" "${testname}.basicemail4.expected" 'keep first'
365
366 run_test 'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail4.actual"' "foobar@example.com (Mr Føø Bär)"
367 run_test 'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail4.actual"' "Mr Føø Bär"
368
369 rm -f "${testname}.basicemail4.actual" "${backupname}.basicemail4.actual.orig"
370
371 #
372 # A more complicated header; it includes groups, addresses that require
373 # quoted-printable and base64, and unencoded email.
374 #
375
376 cat > "${testname}.complexemail1.actual" <<EOF
377 From: "Mr Føø Bar" <foobar@example.com>
378 To: "Mr F. One" <foo1@example.com>, "Mr F. Twø" <foo2@example.com>,
379 foo list: Føø Thrëë <foo3@example.com>, Foo Four <foo4@example.com>,
380 Foo Fivë <foo5@example.com>; Føø Sîx <foo6@example.com>,
381 "Mr F. Seven" <foo7@example.com>
382 cc: "The Distingµishëd F. Sëvën" <foo7@example.com>
383 Subject: Very long list
384
385 This is a lot of people on this email!
386 EOF
387
388 cat > "${testname}.complexemail1.expected" <<EOF
389 From: =?UTF-8?B?TXIgRsO4w7ggQmFy?= <foobar@example.com>
390 To: "Mr F. One" <foo1@example.com>,
391 =?UTF-8?Q?Mr_F=2E_Tw=C3=B8?= <foo2@example.com>,
392 foo list: =?UTF-8?Q?F=C3=B8=C3=B8_Thr=C3=AB=C3=AB?= <foo3@example.com>,
393 Foo Four <foo4@example.com>,
394 =?UTF-8?Q?Foo_Fiv=C3=AB?= <foo5@example.com>;,
395 =?UTF-8?Q?F=C3=B8=C3=B8_S=C3=AEx?= <foo6@example.com>,
396 "Mr F. Seven" <foo7@example.com>
397 cc: =?UTF-8?B?VGhlIERpc3RpbmfCtWlzaMOrZCBGLiBTw6t2w6tu?= <foo7@example.com>
398 Subject: Very long list
399 MIME-Version: 1.0
400 Content-Type: text/plain; charset="us-ascii"
401
402 This is a lot of people on this email!
403 EOF
404
405 run_prog mhbuild "${testname}.complexemail1.actual"
406
407 check "${testname}.complexemail1.actual" "${testname}.complexemail1.expected" 'keep first'
408
409 run_test 'eval fmttest -outsize max -format "%(decode{to})" -message -file "${testname}.complexemail1.actual"' "\"Mr F. One\" <foo1@example.com>, Mr F. Twø <foo2@example.com>, foo list: Føø Thrëë <foo3@example.com>, Foo Four <foo4@example.com>, Foo Fivë <foo5@example.com>;, Føø Sîx <foo6@example.com>, \"Mr F. Seven\" <foo7@example.com>"
410 run_test 'eval fmttest -outsize max -format "%(decode{cc})" -message -file "${testname}.complexemail1.actual"' "The Distingµishëd F. Sëvën <foo7@example.com>"
411
412 rm -f "${testname}.complexemail1.actual" "${backupname}.complexemail1.actual.orig"
413
414 exit ${failed:-0}