2 ######################################################
4 # Test encoding headers according to RFC 2047
6 ######################################################
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir
=`dirname "$0"`/..
/..
12 MH_OBJ_DIR
=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
15 .
"${MH_OBJ_DIR}/test/common.sh"
19 check_exit
'-eq 1' mhbuild
-h
21 testname
="${MH_TEST_DIR}/$$"
22 backupname
="${MH_TEST_DIR}/`mhparam sbackup`$$"
25 # We're going to hardcode UTF-8 for this test.
27 require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8
30 # Basic test of encoding a short subject
32 cat > "${testname}.basic.actual" <<EOF
33 From: Mr Foo Bar <foobar@example.com>
34 To: Somebody <somebody@example.com>
35 Subject: This is ä test
40 cat > "${testname}.basic.expected" <<EOF
41 From: Mr Foo Bar <foobar@example.com>
42 To: Somebody <somebody@example.com>
43 Subject: =?UTF-8?Q?This_is_=C3=A4_test?=
45 Content-Type: text/plain; charset="us-ascii"
50 run_prog mhbuild
"${testname}.basic.actual"
52 check
"${testname}.basic.actual" "${testname}.basic.expected" 'keep first'
55 # Make sure we can undo the encoding
58 run_test
'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test'
60 rm -f "${testname}.basic.actual"
63 # Basic test of encoding a short subject, but with base64
65 cat > "${testname}.basic.actual" <<EOF
66 From: Mr Foo Bar <foobar@example.com>
67 To: Somebody <somebody@example.com>
68 Subject: This is ä test
73 cat > "${testname}.basic.expected" <<EOF
74 From: Mr Foo Bar <foobar@example.com>
75 To: Somebody <somebody@example.com>
76 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0ZXN0?=
78 Content-Type: text/plain; charset="us-ascii"
83 run_prog mhbuild
-headerencoding base64
"${testname}.basic.actual"
85 check
"${testname}.basic.actual" "${testname}.basic.expected" 'keep first'
87 run_test
'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test'
89 rm -f "${testname}.basic.actual" "${backupname}.basic.actual.orig"
92 # Have a subject that will pick base64 as the shorter encoding
95 cat > "${testname}.autopick.actual" <<EOF
96 From: Mr Foo Bar <foobar@example.com>
97 To: Somebody <somebody@example.com>
98 Subject: This is ä tëst©
103 cat > "${testname}.autopick.expected" <<EOF
104 From: Mr Foo Bar <foobar@example.com>
105 To: Somebody <somebody@example.com>
106 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdMKp?=
108 Content-Type: text/plain; charset="us-ascii"
113 run_prog mhbuild
"${testname}.autopick.actual"
115 check
"${testname}.autopick.actual" "${testname}.autopick.expected" 'keep first'
117 run_test
'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.autopick.actual"' 'This is ä tëst©'
119 rm -f "${testname}.autopick.actual" "${backupname}.autopick.actual.orig"
122 # Tests using longer subject lines.
125 cat > "${testname}.longsubject1.actual" <<EOF
126 From: Mr Foo Bar <foobar@example.com>
127 To: Somebody <somebody@example.com>
128 Subject: This is ä tëst of a rather long sübject line; will it overflow
129 the line length? I sure hope thät ='s and _'s are encoded properly. Will
132 This is a test of a very long subject line.
135 cat > "${testname}.longsubject1.expected" <<EOF
136 From: Mr Foo Bar <foobar@example.com>
137 To: Somebody <somebody@example.com>
138 Subject: =?UTF-8?Q?This_is_=C3=A4_t=C3=ABst_of_a_rather_long_s=C3=BCbject_?=
139 =?UTF-8?Q?line;_will_it_overflow_the_line_length=3F__I_sure_hope_?=
140 =?UTF-8?Q?th=C3=A4t_=3D's_and_=5F's_are_encoded_properly.__Will_t?=
141 =?UTF-8?Q?hey_be=3F?=
143 Content-Type: text/plain; charset="us-ascii"
145 This is a test of a very long subject line.
148 run_prog mhbuild
"${testname}.longsubject1.actual"
150 check
"${testname}.longsubject1.actual" "${testname}.longsubject1.expected" 'keep first'
152 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?"
154 rm -f "${testname}.longsubject1.actual" "${backupname}.longsubject1.actual.orig"
157 # Test a longer line with base64 encoding
160 cat > "${testname}.longsubject2.actual" <<EOF
161 From: Mr Foo Bar <foobar@example.com>
162 To: Somebody <somebody@example.com>
163 Subject: This is ä tëst øf ä räthër løng sübjëct line; will it øvërfløw
164 the line length? I sure hope thät ='s and "'s are encoded properly. Will
167 This is a test of a very long subject line using base64.
170 cat > "${testname}.longsubject2.expected" <<EOF
171 From: Mr Foo Bar <foobar@example.com>
172 To: Somebody <somebody@example.com>
173 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdCDDuGYgw6QgcsOkdGjDq3IgbMO4bmcg?=
174 =?UTF-8?B?c8O8YmrDq2N0IGxpbmU7IHdpbGwgaXQgw7h2w6tyZmzDuHcgdGhl?=
175 =?UTF-8?B?IGxpbmUgbGVuZ3RoPyAgSSBzdXJlIGhvcGUgdGjDpHQgPSdzIGFu?=
176 =?UTF-8?B?ZCAiJ3MgYXJlIGVuY29kZWQgcHJvcGVybHkuICBXaWxsIHRoZXkg?=
179 Content-Type: text/plain; charset="us-ascii"
181 This is a test of a very long subject line using base64.
184 run_prog mhbuild
"${testname}.longsubject2.actual"
186 check
"${testname}.longsubject2.actual" "${testname}.longsubject2.expected" 'keep first'
188 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?"
190 rm -f "${testname}.longsubject2.actual" "${backupname}.longsubject2.actual.orig"
193 # Another long test, but make sure multibyte characters are not split across
194 # RFC-2047 tokens (prohibited by the standard). Test both quoted-printable
198 cat > "${testname}.longsubject3.actual" <<EOF
199 From: Mr Foo Bar <foobar@example.com>
200 To: Somebody <somebody@example.com>
201 Subject: This is a test of a big UTF-8 multibyte character (😉); will
202 this work properly, or will it get truncated? 😨! Hopefully not
204 This is another long test.
207 cat > "${testname}.longsubject3.expected" <<EOF
208 From: Mr Foo Bar <foobar@example.com>
209 To: Somebody <somebody@example.com>
210 Subject: =?UTF-8?Q?This_is_a_test_of_a_big_UTF-8_multibyte_character_(?=
211 =?UTF-8?Q?=F0=9F=98=89);_will_this_work_properly,_or_will_it_get_?=
212 =?UTF-8?Q?truncated=3F_=F0=9F=98=A8!_Hopefully_not?=
214 Content-Type: text/plain; charset="us-ascii"
216 This is another long test.
219 run_prog mhbuild
"${testname}.longsubject3.actual"
221 check
"${testname}.longsubject3.actual" "${testname}.longsubject3.expected" 'keep first'
223 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"
225 rm -f "${testname}.longsubject3.actual" "${backupname}.longsubject3.actual.orig"
227 cat > "${testname}.longsubject4.actual" <<EOF
228 From: Mr Foo Bar <foobar@example.com>
229 To: Somebody <somebody@example.com>
230 Subject: This is ä tëst øf å big ÜTF-8 (😉) mültibyte character; will
231 this wørk prøperly, ør will it get trµnᴬted? 😨! Hopefully nøt
233 This is another long test.
236 cat > "${testname}.longsubject4.expected" <<EOF
237 From: Mr Foo Bar <foobar@example.com>
238 To: Somebody <somebody@example.com>
239 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdCDDuGYgw6UgYmlnIMOcVEYtOCAo?=
240 =?UTF-8?B?8J+YiSkgbcO8bHRpYnl0ZSBjaGFyYWN0ZXI7IHdpbGwgdGhpcyB3?=
241 =?UTF-8?B?w7hyayBwcsO4cGVybHksIMO4ciB3aWxsIGl0IGdldCB0csK1bg==?=
242 =?UTF-8?B?4bSsdGVkPyDwn5ioISBIb3BlZnVsbHkgbsO4dA==?=
244 Content-Type: text/plain; charset="us-ascii"
246 This is another long test.
249 run_prog mhbuild
"${testname}.longsubject4.actual"
251 check
"${testname}.longsubject4.actual" "${testname}.longsubject4.expected" 'keep first'
253 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"
255 rm -f "${testname}.longsubject4.actual" "${backupname}.longsubject4.actual.orig"
258 # Test out some basic email address encoding
261 cat > "${testname}.basicemail1.actual" <<EOF
262 From: Mr Foo Bär <foobar@example.com>
263 To: Somebody <somebody@example.com>
264 Subject: Impørtant stuff
266 This is important information
269 cat > "${testname}.basicemail1.expected" <<EOF
270 From: =?UTF-8?Q?Mr_Foo_B=C3=A4r?= <foobar@example.com>
271 To: Somebody <somebody@example.com>
272 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
274 Content-Type: text/plain; charset="us-ascii"
276 This is important information
279 run_prog mhbuild
"${testname}.basicemail1.actual"
281 check
"${testname}.basicemail1.actual" "${testname}.basicemail1.expected" 'keep first'
283 run_test
'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail1.actual"' "Mr Foo Bär <foobar@example.com>"
284 run_test
'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail1.actual"' "Mr Foo Bär"
286 rm -f "${testname}.basicemail1.actual" "${backupname}.basicemail1.actual.orig"
288 cat > "${testname}.basicemail2.actual" <<EOF
289 From: foobar@example.com (Mr Foo Bär)
290 To: Somebody <somebody@example.com>
291 Subject: Impørtant stuff
293 This is important information
296 cat > "${testname}.basicemail2.expected" <<EOF
297 From: foobar@example.com (=?UTF-8?Q?Mr_Foo_B=C3=A4r?=)
298 To: Somebody <somebody@example.com>
299 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
301 Content-Type: text/plain; charset="us-ascii"
303 This is important information
306 run_prog mhbuild
"${testname}.basicemail2.actual"
308 check
"${testname}.basicemail2.actual" "${testname}.basicemail2.expected" 'keep first'
310 run_test
'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail2.actual"' "foobar@example.com (Mr Foo Bär)"
311 run_test
'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail2.actual"' "Mr Foo Bär"
313 rm -f "${testname}.basicemail2.actual" "${backupname}.basicemail2.actual.orig"
316 # Make sure the base64 encoder is tested as well
319 cat > "${testname}.basicemail3.actual" <<EOF
320 From: Mr Føø Bär <foobar@example.com>
321 To: Somebody <somebody@example.com>
322 Subject: Impørtant stuff
324 This is important information
327 cat > "${testname}.basicemail3.expected" <<EOF
328 From: =?UTF-8?B?TXIgRsO4w7ggQsOkcg==?= <foobar@example.com>
329 To: Somebody <somebody@example.com>
330 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
332 Content-Type: text/plain; charset="us-ascii"
334 This is important information
337 run_prog mhbuild
"${testname}.basicemail3.actual"
339 check
"${testname}.basicemail3.actual" "${testname}.basicemail3.expected" 'keep first'
341 run_test
'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail3.actual"' "Mr Føø Bär <foobar@example.com>"
342 run_test
'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail3.actual"' "Mr Føø Bär"
344 rm -f "${testname}.basicemail3.actual" "${backupname}.basicemail3.actual.orig"
346 cat > "${testname}.basicemail4.actual" <<EOF
347 From: foobar@example.com (Mr Føø Bär)
348 To: Somebody <somebody@example.com>
349 Subject: Impørtant stuff
351 This is important information
354 cat > "${testname}.basicemail4.expected" <<EOF
355 From: foobar@example.com (=?UTF-8?B?TXIgRsO4w7ggQsOkcg==?=)
356 To: Somebody <somebody@example.com>
357 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
359 Content-Type: text/plain; charset="us-ascii"
361 This is important information
364 run_prog mhbuild
"${testname}.basicemail4.actual"
366 check
"${testname}.basicemail4.actual" "${testname}.basicemail4.expected" 'keep first'
368 run_test
'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail4.actual"' "foobar@example.com (Mr Føø Bär)"
369 run_test
'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail4.actual"' "Mr Føø Bär"
371 rm -f "${testname}.basicemail4.actual" "${backupname}.basicemail4.actual.orig"
374 # A more complicated header; it includes groups, addresses that require
375 # quoted-printable and base64, and unencoded email.
378 cat > "${testname}.complexemail1.actual" <<EOF
379 From: "Mr Føø Bar" <foobar@example.com>
380 To: "Mr F. One" <foo1@example.com>, "Mr F. Twø" <foo2@example.com>,
381 foo list: Føø Thrëë <foo3@example.com>, Foo Four <foo4@example.com>,
382 Foo Fivë <foo5@example.com>; Føø Sîx <foo6@example.com>,
383 "Mr F. Seven" <foo7@example.com>
384 cc: "The Distingµishëd F. Sëvën" <foo7@example.com>
385 Subject: Very long list
387 This is a lot of people on this email!
390 cat > "${testname}.complexemail1.expected" <<EOF
391 From: =?UTF-8?B?TXIgRsO4w7ggQmFy?= <foobar@example.com>
392 To: "Mr F. One" <foo1@example.com>,
393 =?UTF-8?Q?Mr_F=2E_Tw=C3=B8?= <foo2@example.com>,
394 foo list: =?UTF-8?Q?F=C3=B8=C3=B8_Thr=C3=AB=C3=AB?= <foo3@example.com>,
395 Foo Four <foo4@example.com>,
396 =?UTF-8?Q?Foo_Fiv=C3=AB?= <foo5@example.com>;,
397 =?UTF-8?Q?F=C3=B8=C3=B8_S=C3=AEx?= <foo6@example.com>,
398 "Mr F. Seven" <foo7@example.com>
399 cc: =?UTF-8?B?VGhlIERpc3RpbmfCtWlzaMOrZCBGLiBTw6t2w6tu?= <foo7@example.com>
400 Subject: Very long list
402 Content-Type: text/plain; charset="us-ascii"
404 This is a lot of people on this email!
407 run_prog mhbuild
"${testname}.complexemail1.actual"
409 check
"${testname}.complexemail1.actual" "${testname}.complexemail1.expected" 'keep first'
411 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>"
412 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>"
414 rm -f "${testname}.complexemail1.actual" "${backupname}.complexemail1.actual.orig"