]>
diplodocus.org Git - nmh/blob - test/mhbuild/test-header-encode
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"
18 testname
= " ${MH_TEST_DIR} /$$"
19 backupname
= " ${MH_TEST_DIR} /`mhparam sbackup`$$"
22 # We're going to hardcode UTF-8 for this test.
25 LC_ALL
= en_US.UTF
-8 ; export LC_ALL
28 # Basic test of encoding a short subject
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
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?=
43 Content-Type: text/plain; charset="us-ascii"
48 run_prog mhbuild
" ${testname} .basic.actual"
50 check
" ${testname} .basic.actual" " ${testname} .basic.expected" 'keep first'
53 # Make sure we can undo the encoding
56 run_test
'eval fmttest -outsize max -format "%(decode{subject})" -message -file " ${testname} .basic.actual"' 'This is ä test'
58 rm -f " ${testname} .basic.actual"
61 # Basic test of encoding a short subject, but with base64
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
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?=
76 Content-Type: text/plain; charset="us-ascii"
81 run_prog mhbuild
-headerencoding base64
" ${testname} .basic.actual"
83 check
" ${testname} .basic.actual" " ${testname} .basic.expected" 'keep first'
85 run_test
'eval fmttest -outsize max -format "%(decode{subject})" -message -file " ${testname} .basic.actual"' 'This is ä test'
87 rm -f " ${testname} .basic.actual" " ${backupname} .basic.actual.orig"
90 # Have a subject that will pick base64 as the shorter encoding
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©
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?=
106 Content-Type: text/plain; charset="us-ascii"
111 run_prog mhbuild
" ${testname} .autopick.actual"
113 check
" ${testname} .autopick.actual" " ${testname} .autopick.expected" 'keep first'
115 run_test
'eval fmttest -outsize max -format "%(decode{subject})" -message -file " ${testname} .autopick.actual"' 'This is ä tëst©'
117 rm -f " ${testname} .autopick.actual" " ${backupname} .autopick.actual.orig"
120 # Tests using longer subject lines.
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
130 This is a test of a very long subject line.
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?=
141 Content-Type: text/plain; charset="us-ascii"
143 This is a test of a very long subject line.
146 run_prog mhbuild
" ${testname} .longsubject1.actual"
148 check
" ${testname} .longsubject1.actual" " ${testname} .longsubject1.expected" 'keep first'
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?"
152 rm -f " ${testname} .longsubject1.actual" " ${backupname} .longsubject1.actual.orig"
155 # Test a longer line with base64 encoding
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
165 This is a test of a very long subject line using base64.
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?=
177 Content-Type: text/plain; charset="us-ascii"
179 This is a test of a very long subject line using base64.
182 run_prog mhbuild
" ${testname} .longsubject2.actual"
184 check
" ${testname} .longsubject2.actual" " ${testname} .longsubject2.expected" 'keep first'
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?"
188 rm -f " ${testname} .longsubject2.actual" " ${backupname} .longsubject2.actual.orig"
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
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
202 This is another long test.
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?=
212 Content-Type: text/plain; charset="us-ascii"
214 This is another long test.
217 run_prog mhbuild
" ${testname} .longsubject3.actual"
219 check
" ${testname} .longsubject3.actual" " ${testname} .longsubject3.expected" 'keep first'
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"
223 rm -f " ${testname} .longsubject3.actual" " ${backupname} .longsubject3.actual.orig"
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
231 This is another long test.
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==?=
242 Content-Type: text/plain; charset="us-ascii"
244 This is another long test.
247 run_prog mhbuild
" ${testname} .longsubject4.actual"
249 check
" ${testname} .longsubject4.actual" " ${testname} .longsubject4.expected" 'keep first'
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"
253 rm -f " ${testname} .longsubject4.actual" " ${backupname} .longsubject4.actual.orig"
256 # Test out some basic email address encoding
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
264 This is important information
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?=
272 Content-Type: text/plain; charset="us-ascii"
274 This is important information
277 run_prog mhbuild
" ${testname} .basicemail1.actual"
279 check
" ${testname} .basicemail1.actual" " ${testname} .basicemail1.expected" 'keep first'
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"
284 rm -f " ${testname} .basicemail1.actual" " ${backupname} .basicemail1.actual.orig"
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
291 This is important information
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?=
299 Content-Type: text/plain; charset="us-ascii"
301 This is important information
304 run_prog mhbuild
" ${testname} .basicemail2.actual"
306 check
" ${testname} .basicemail2.actual" " ${testname} .basicemail2.expected" 'keep first'
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"
311 rm -f " ${testname} .basicemail2.actual" " ${backupname} .basicemail2.actual.orig"
314 # Make sure the base64 encoder is tested as well
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
322 This is important information
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?=
330 Content-Type: text/plain; charset="us-ascii"
332 This is important information
335 run_prog mhbuild
" ${testname} .basicemail3.actual"
337 check
" ${testname} .basicemail3.actual" " ${testname} .basicemail3.expected" 'keep first'
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"
342 rm -f " ${testname} .basicemail3.actual" " ${backupname} .basicemail3.actual.orig"
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
349 This is important information
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?=
357 Content-Type: text/plain; charset="us-ascii"
359 This is important information
362 run_prog mhbuild
" ${testname} .basicemail4.actual"
364 check
" ${testname} .basicemail4.actual" " ${testname} .basicemail4.expected" 'keep first'
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"
369 rm -f " ${testname} .basicemail4.actual" " ${backupname} .basicemail4.actual.orig"
372 # A more complicated header; it includes groups, addresses that require
373 # quoted-printable and base64, and unencoded email.
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
385 This is a lot of people on this email!
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
400 Content-Type: text/plain; charset="us-ascii"
402 This is a lot of people on this email!
405 run_prog mhbuild
" ${testname} .complexemail1.actual"
407 check
" ${testname} .complexemail1.actual" " ${testname} .complexemail1.expected" 'keep first'
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>"
412 rm -f " ${testname} .complexemail1.actual" " ${backupname} .complexemail1.actual.orig"