]>
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.
24 require_locale en_US.UTF
-8 en_US.UTF8 en_US.utf
-8 en_US.utf8
27 # Basic test of encoding a short subject
29 cat > " ${testname} .basic.actual" <<EOF
30 From: Mr Foo Bar <foobar@example.com>
31 To: Somebody <somebody@example.com>
32 Subject: This is ä test
37 cat > " ${testname} .basic.expected" <<EOF
38 From: Mr Foo Bar <foobar@example.com>
39 To: Somebody <somebody@example.com>
40 Subject: =?UTF-8?Q?This_is_=C3=A4_test?=
42 Content-Type: text/plain; charset="us-ascii"
47 run_prog mhbuild
" ${testname} .basic.actual"
49 check
" ${testname} .basic.actual" " ${testname} .basic.expected" 'keep first'
52 # Make sure we can undo the encoding
55 run_test
'eval fmttest -outsize max -format "%(decode{subject})" -message -file " ${testname} .basic.actual"' 'This is ä test'
57 rm -f " ${testname} .basic.actual"
60 # Basic test of encoding a short subject, but with base64
62 cat > " ${testname} .basic.actual" <<EOF
63 From: Mr Foo Bar <foobar@example.com>
64 To: Somebody <somebody@example.com>
65 Subject: This is ä test
70 cat > " ${testname} .basic.expected" <<EOF
71 From: Mr Foo Bar <foobar@example.com>
72 To: Somebody <somebody@example.com>
73 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0ZXN0?=
75 Content-Type: text/plain; charset="us-ascii"
80 run_prog mhbuild
-headerencoding base64
" ${testname} .basic.actual"
82 check
" ${testname} .basic.actual" " ${testname} .basic.expected" 'keep first'
84 run_test
'eval fmttest -outsize max -format "%(decode{subject})" -message -file " ${testname} .basic.actual"' 'This is ä test'
86 rm -f " ${testname} .basic.actual" " ${backupname} .basic.actual.orig"
89 # Have a subject that will pick base64 as the shorter encoding
92 cat > " ${testname} .autopick.actual" <<EOF
93 From: Mr Foo Bar <foobar@example.com>
94 To: Somebody <somebody@example.com>
95 Subject: This is ä tëst©
100 cat > " ${testname} .autopick.expected" <<EOF
101 From: Mr Foo Bar <foobar@example.com>
102 To: Somebody <somebody@example.com>
103 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdMKp?=
105 Content-Type: text/plain; charset="us-ascii"
110 run_prog mhbuild
" ${testname} .autopick.actual"
112 check
" ${testname} .autopick.actual" " ${testname} .autopick.expected" 'keep first'
114 run_test
'eval fmttest -outsize max -format "%(decode{subject})" -message -file " ${testname} .autopick.actual"' 'This is ä tëst©'
116 rm -f " ${testname} .autopick.actual" " ${backupname} .autopick.actual.orig"
119 # Tests using longer subject lines.
122 cat > " ${testname} .longsubject1.actual" <<EOF
123 From: Mr Foo Bar <foobar@example.com>
124 To: Somebody <somebody@example.com>
125 Subject: This is ä tëst of a rather long sübject line; will it overflow
126 the line length? I sure hope thät ='s and _'s are encoded properly. Will
129 This is a test of a very long subject line.
132 cat > " ${testname} .longsubject1.expected" <<EOF
133 From: Mr Foo Bar <foobar@example.com>
134 To: Somebody <somebody@example.com>
135 Subject: =?UTF-8?Q?This_is_=C3=A4_t=C3=ABst_of_a_rather_long_s=C3=BCbject_?=
136 =?UTF-8?Q?line;_will_it_overflow_the_line_length=3F__I_sure_hope_?=
137 =?UTF-8?Q?th=C3=A4t_=3D's_and_=5F's_are_encoded_properly.__Will_t?=
138 =?UTF-8?Q?hey_be=3F?=
140 Content-Type: text/plain; charset="us-ascii"
142 This is a test of a very long subject line.
145 run_prog mhbuild
" ${testname} .longsubject1.actual"
147 check
" ${testname} .longsubject1.actual" " ${testname} .longsubject1.expected" 'keep first'
149 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 rm -f " ${testname} .longsubject1.actual" " ${backupname} .longsubject1.actual.orig"
154 # Test a longer line with base64 encoding
157 cat > " ${testname} .longsubject2.actual" <<EOF
158 From: Mr Foo Bar <foobar@example.com>
159 To: Somebody <somebody@example.com>
160 Subject: This is ä tëst øf ä räthër løng sübjëct line; will it øvërfløw
161 the line length? I sure hope thät ='s and "'s are encoded properly. Will
164 This is a test of a very long subject line using base64.
167 cat > " ${testname} .longsubject2.expected" <<EOF
168 From: Mr Foo Bar <foobar@example.com>
169 To: Somebody <somebody@example.com>
170 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdCDDuGYgw6QgcsOkdGjDq3IgbMO4bmcg?=
171 =?UTF-8?B?c8O8YmrDq2N0IGxpbmU7IHdpbGwgaXQgw7h2w6tyZmzDuHcgdGhl?=
172 =?UTF-8?B?IGxpbmUgbGVuZ3RoPyAgSSBzdXJlIGhvcGUgdGjDpHQgPSdzIGFu?=
173 =?UTF-8?B?ZCAiJ3MgYXJlIGVuY29kZWQgcHJvcGVybHkuICBXaWxsIHRoZXkg?=
176 Content-Type: text/plain; charset="us-ascii"
178 This is a test of a very long subject line using base64.
181 run_prog mhbuild
" ${testname} .longsubject2.actual"
183 check
" ${testname} .longsubject2.actual" " ${testname} .longsubject2.expected" 'keep first'
185 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 rm -f " ${testname} .longsubject2.actual" " ${backupname} .longsubject2.actual.orig"
190 # Another long test, but make sure multibyte characters are not split across
191 # RFC-2047 tokens (prohibited by the standard). Test both quoted-printable
195 cat > " ${testname} .longsubject3.actual" <<EOF
196 From: Mr Foo Bar <foobar@example.com>
197 To: Somebody <somebody@example.com>
198 Subject: This is a test of a big UTF-8 multibyte character (😉); will
199 this work properly, or will it get truncated? 😨! Hopefully not
201 This is another long test.
204 cat > " ${testname} .longsubject3.expected" <<EOF
205 From: Mr Foo Bar <foobar@example.com>
206 To: Somebody <somebody@example.com>
207 Subject: =?UTF-8?Q?This_is_a_test_of_a_big_UTF-8_multibyte_character_(?=
208 =?UTF-8?Q?=F0=9F=98=89);_will_this_work_properly,_or_will_it_get_?=
209 =?UTF-8?Q?truncated=3F_=F0=9F=98=A8!_Hopefully_not?=
211 Content-Type: text/plain; charset="us-ascii"
213 This is another long test.
216 run_prog mhbuild
" ${testname} .longsubject3.actual"
218 check
" ${testname} .longsubject3.actual" " ${testname} .longsubject3.expected" 'keep first'
220 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 rm -f " ${testname} .longsubject3.actual" " ${backupname} .longsubject3.actual.orig"
224 cat > " ${testname} .longsubject4.actual" <<EOF
225 From: Mr Foo Bar <foobar@example.com>
226 To: Somebody <somebody@example.com>
227 Subject: This is ä tëst øf å big ÜTF-8 (😉) mültibyte character; will
228 this wørk prøperly, ør will it get trµnᴬted? 😨! Hopefully nøt
230 This is another long test.
233 cat > " ${testname} .longsubject4.expected" <<EOF
234 From: Mr Foo Bar <foobar@example.com>
235 To: Somebody <somebody@example.com>
236 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdCDDuGYgw6UgYmlnIMOcVEYtOCAo?=
237 =?UTF-8?B?8J+YiSkgbcO8bHRpYnl0ZSBjaGFyYWN0ZXI7IHdpbGwgdGhpcyB3?=
238 =?UTF-8?B?w7hyayBwcsO4cGVybHksIMO4ciB3aWxsIGl0IGdldCB0csK1bg==?=
239 =?UTF-8?B?4bSsdGVkPyDwn5ioISBIb3BlZnVsbHkgbsO4dA==?=
241 Content-Type: text/plain; charset="us-ascii"
243 This is another long test.
246 run_prog mhbuild
" ${testname} .longsubject4.actual"
248 check
" ${testname} .longsubject4.actual" " ${testname} .longsubject4.expected" 'keep first'
250 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 rm -f " ${testname} .longsubject4.actual" " ${backupname} .longsubject4.actual.orig"
255 # Test out some basic email address encoding
258 cat > " ${testname} .basicemail1.actual" <<EOF
259 From: Mr Foo Bär <foobar@example.com>
260 To: Somebody <somebody@example.com>
261 Subject: Impørtant stuff
263 This is important information
266 cat > " ${testname} .basicemail1.expected" <<EOF
267 From: =?UTF-8?Q?Mr_Foo_B=C3=A4r?= <foobar@example.com>
268 To: Somebody <somebody@example.com>
269 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
271 Content-Type: text/plain; charset="us-ascii"
273 This is important information
276 run_prog mhbuild
" ${testname} .basicemail1.actual"
278 check
" ${testname} .basicemail1.actual" " ${testname} .basicemail1.expected" 'keep first'
280 run_test
'eval fmttest -outsize max -format "%(decode{from})" -message -file " ${testname} .basicemail1.actual"' "Mr Foo Bär <foobar@example.com>"
281 run_test
'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file " ${testname} .basicemail1.actual"' "Mr Foo Bär"
283 rm -f " ${testname} .basicemail1.actual" " ${backupname} .basicemail1.actual.orig"
285 cat > " ${testname} .basicemail2.actual" <<EOF
286 From: foobar@example.com (Mr Foo Bär)
287 To: Somebody <somebody@example.com>
288 Subject: Impørtant stuff
290 This is important information
293 cat > " ${testname} .basicemail2.expected" <<EOF
294 From: foobar@example.com (=?UTF-8?Q?Mr_Foo_B=C3=A4r?=)
295 To: Somebody <somebody@example.com>
296 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
298 Content-Type: text/plain; charset="us-ascii"
300 This is important information
303 run_prog mhbuild
" ${testname} .basicemail2.actual"
305 check
" ${testname} .basicemail2.actual" " ${testname} .basicemail2.expected" 'keep first'
307 run_test
'eval fmttest -outsize max -format "%(decode{from})" -message -file " ${testname} .basicemail2.actual"' "foobar@example.com (Mr Foo Bär)"
308 run_test
'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file " ${testname} .basicemail2.actual"' "Mr Foo Bär"
310 rm -f " ${testname} .basicemail2.actual" " ${backupname} .basicemail2.actual.orig"
313 # Make sure the base64 encoder is tested as well
316 cat > " ${testname} .basicemail3.actual" <<EOF
317 From: Mr Føø Bär <foobar@example.com>
318 To: Somebody <somebody@example.com>
319 Subject: Impørtant stuff
321 This is important information
324 cat > " ${testname} .basicemail3.expected" <<EOF
325 From: =?UTF-8?B?TXIgRsO4w7ggQsOkcg==?= <foobar@example.com>
326 To: Somebody <somebody@example.com>
327 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
329 Content-Type: text/plain; charset="us-ascii"
331 This is important information
334 run_prog mhbuild
" ${testname} .basicemail3.actual"
336 check
" ${testname} .basicemail3.actual" " ${testname} .basicemail3.expected" 'keep first'
338 run_test
'eval fmttest -outsize max -format "%(decode{from})" -message -file " ${testname} .basicemail3.actual"' "Mr Føø Bär <foobar@example.com>"
339 run_test
'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file " ${testname} .basicemail3.actual"' "Mr Føø Bär"
341 rm -f " ${testname} .basicemail3.actual" " ${backupname} .basicemail3.actual.orig"
343 cat > " ${testname} .basicemail4.actual" <<EOF
344 From: foobar@example.com (Mr Føø Bär)
345 To: Somebody <somebody@example.com>
346 Subject: Impørtant stuff
348 This is important information
351 cat > " ${testname} .basicemail4.expected" <<EOF
352 From: foobar@example.com (=?UTF-8?B?TXIgRsO4w7ggQsOkcg==?=)
353 To: Somebody <somebody@example.com>
354 Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?=
356 Content-Type: text/plain; charset="us-ascii"
358 This is important information
361 run_prog mhbuild
" ${testname} .basicemail4.actual"
363 check
" ${testname} .basicemail4.actual" " ${testname} .basicemail4.expected" 'keep first'
365 run_test
'eval fmttest -outsize max -format "%(decode{from})" -message -file " ${testname} .basicemail4.actual"' "foobar@example.com (Mr Føø Bär)"
366 run_test
'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file " ${testname} .basicemail4.actual"' "Mr Føø Bär"
368 rm -f " ${testname} .basicemail4.actual" " ${backupname} .basicemail4.actual.orig"
371 # A more complicated header; it includes groups, addresses that require
372 # quoted-printable and base64, and unencoded email.
375 cat > " ${testname} .complexemail1.actual" <<EOF
376 From: "Mr Føø Bar" <foobar@example.com>
377 To: "Mr F. One" <foo1@example.com>, "Mr F. Twø" <foo2@example.com>,
378 foo list: Føø Thrëë <foo3@example.com>, Foo Four <foo4@example.com>,
379 Foo Fivë <foo5@example.com>; Føø Sîx <foo6@example.com>,
380 "Mr F. Seven" <foo7@example.com>
381 cc: "The Distingµishëd F. Sëvën" <foo7@example.com>
382 Subject: Very long list
384 This is a lot of people on this email!
387 cat > " ${testname} .complexemail1.expected" <<EOF
388 From: =?UTF-8?B?TXIgRsO4w7ggQmFy?= <foobar@example.com>
389 To: "Mr F. One" <foo1@example.com>,
390 =?UTF-8?Q?Mr_F=2E_Tw=C3=B8?= <foo2@example.com>,
391 foo list: =?UTF-8?Q?F=C3=B8=C3=B8_Thr=C3=AB=C3=AB?= <foo3@example.com>,
392 Foo Four <foo4@example.com>,
393 =?UTF-8?Q?Foo_Fiv=C3=AB?= <foo5@example.com>;,
394 =?UTF-8?Q?F=C3=B8=C3=B8_S=C3=AEx?= <foo6@example.com>,
395 "Mr F. Seven" <foo7@example.com>
396 cc: =?UTF-8?B?VGhlIERpc3RpbmfCtWlzaMOrZCBGLiBTw6t2w6tu?= <foo7@example.com>
397 Subject: Very long list
399 Content-Type: text/plain; charset="us-ascii"
401 This is a lot of people on this email!
404 run_prog mhbuild
" ${testname} .complexemail1.actual"
406 check
" ${testname} .complexemail1.actual" " ${testname} .complexemail1.expected" 'keep first'
408 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>"
409 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 rm -f " ${testname} .complexemail1.actual" " ${backupname} .complexemail1.actual.orig"