| 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 |
|
| 19 |
check_exit '-eq 1' mhbuild -h |
| 20 |
|
| 21 |
testname="${MH_TEST_DIR}/$$" |
| 22 |
backupname="${MH_TEST_DIR}/`mhparam sbackup`$$" |
| 23 |
|
| 24 |
# |
| 25 |
# We're going to hardcode UTF-8 for this test. |
| 26 |
# |
| 27 |
require_locale $en_locales |
| 28 |
|
| 29 |
# |
| 30 |
# Basic test of encoding a short subject |
| 31 |
# |
| 32 |
cat > "${testname}.basic.actual" <<EOF |
| 33 |
From: Mr Foo Bar <[email protected]> |
| 34 |
To: Somebody <[email protected]> |
| 35 |
Subject: This is ä test |
| 36 |
|
| 37 |
This is a test |
| 38 |
EOF |
| 39 |
|
| 40 |
cat > "${testname}.basic.expected" <<EOF |
| 41 |
From: Mr Foo Bar <[email protected]> |
| 42 |
To: Somebody <[email protected]> |
| 43 |
Subject: =?UTF-8?Q?This_is_=C3=A4_test?= |
| 44 |
MIME-Version: 1.0 |
| 45 |
Content-Type: text/plain; charset="us-ascii" |
| 46 |
|
| 47 |
This is a test |
| 48 |
EOF |
| 49 |
|
| 50 |
run_prog mhbuild "${testname}.basic.actual" |
| 51 |
|
| 52 |
check "${testname}.basic.actual" "${testname}.basic.expected" 'keep first' |
| 53 |
|
| 54 |
# |
| 55 |
# Make sure we can undo the encoding |
| 56 |
# |
| 57 |
|
| 58 |
run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test' |
| 59 |
|
| 60 |
rm -f "${testname}.basic.actual" |
| 61 |
|
| 62 |
# |
| 63 |
# Basic test of encoding a short subject, but with base64 |
| 64 |
# |
| 65 |
cat > "${testname}.basic.actual" <<EOF |
| 66 |
From: Mr Foo Bar <[email protected]> |
| 67 |
To: Somebody <[email protected]> |
| 68 |
Subject: This is ä test |
| 69 |
|
| 70 |
This is a test |
| 71 |
EOF |
| 72 |
|
| 73 |
cat > "${testname}.basic.expected" <<EOF |
| 74 |
From: Mr Foo Bar <[email protected]> |
| 75 |
To: Somebody <[email protected]> |
| 76 |
Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0ZXN0?= |
| 77 |
MIME-Version: 1.0 |
| 78 |
Content-Type: text/plain; charset="us-ascii" |
| 79 |
|
| 80 |
This is a test |
| 81 |
EOF |
| 82 |
|
| 83 |
run_prog mhbuild -headerencoding base64 "${testname}.basic.actual" |
| 84 |
|
| 85 |
check "${testname}.basic.actual" "${testname}.basic.expected" 'keep first' |
| 86 |
|
| 87 |
run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test' |
| 88 |
|
| 89 |
rm -f "${testname}.basic.actual" "${backupname}.basic.actual.orig" |
| 90 |
|
| 91 |
# |
| 92 |
# Have a subject that will pick base64 as the shorter encoding |
| 93 |
# |
| 94 |
|
| 95 |
cat > "${testname}.autopick.actual" <<EOF |
| 96 |
From: Mr Foo Bar <[email protected]> |
| 97 |
To: Somebody <[email protected]> |
| 98 |
Subject: This is ä tëst© |
| 99 |
|
| 100 |
This is a test |
| 101 |
EOF |
| 102 |
|
| 103 |
cat > "${testname}.autopick.expected" <<EOF |
| 104 |
From: Mr Foo Bar <[email protected]> |
| 105 |
To: Somebody <[email protected]> |
| 106 |
Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdMKp?= |
| 107 |
MIME-Version: 1.0 |
| 108 |
Content-Type: text/plain; charset="us-ascii" |
| 109 |
|
| 110 |
This is a test |
| 111 |
EOF |
| 112 |
|
| 113 |
run_prog mhbuild "${testname}.autopick.actual" |
| 114 |
|
| 115 |
check "${testname}.autopick.actual" "${testname}.autopick.expected" 'keep first' |
| 116 |
|
| 117 |
run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.autopick.actual"' 'This is ä tëst©' |
| 118 |
|
| 119 |
rm -f "${testname}.autopick.actual" "${backupname}.autopick.actual.orig" |
| 120 |
|
| 121 |
# |
| 122 |
# Tests using longer subject lines. |
| 123 |
# |
| 124 |
|
| 125 |
cat > "${testname}.longsubject1.actual" <<EOF |
| 126 |
From: Mr Foo Bar <[email protected]> |
| 127 |
To: Somebody <[email protected]> |
| 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 |
| 130 |
they be? |
| 131 |
|
| 132 |
This is a test of a very long subject line. |
| 133 |
EOF |
| 134 |
|
| 135 |
cat > "${testname}.longsubject1.expected" <<EOF |
| 136 |
From: Mr Foo Bar <[email protected]> |
| 137 |
To: Somebody <[email protected]> |
| 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?= |
| 142 |
MIME-Version: 1.0 |
| 143 |
Content-Type: text/plain; charset="us-ascii" |
| 144 |
|
| 145 |
This is a test of a very long subject line. |
| 146 |
EOF |
| 147 |
|
| 148 |
run_prog mhbuild "${testname}.longsubject1.actual" |
| 149 |
|
| 150 |
check "${testname}.longsubject1.actual" "${testname}.longsubject1.expected" 'keep first' |
| 151 |
|
| 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?" |
| 153 |
|
| 154 |
rm -f "${testname}.longsubject1.actual" "${backupname}.longsubject1.actual.orig" |
| 155 |
|
| 156 |
# |
| 157 |
# Test a longer line with base64 encoding |
| 158 |
# |
| 159 |
|
| 160 |
cat > "${testname}.longsubject2.actual" <<EOF |
| 161 |
From: Mr Foo Bar <[email protected]> |
| 162 |
To: Somebody <[email protected]> |
| 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 |
| 165 |
they be? |
| 166 |
|
| 167 |
This is a test of a very long subject line using base64. |
| 168 |
EOF |
| 169 |
|
| 170 |
cat > "${testname}.longsubject2.expected" <<EOF |
| 171 |
From: Mr Foo Bar <[email protected]> |
| 172 |
To: Somebody <[email protected]> |
| 173 |
Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdCDDuGYgw6QgcsOkdGjDq3IgbMO4bmcg?= |
| 174 |
=?UTF-8?B?c8O8YmrDq2N0IGxpbmU7IHdpbGwgaXQgw7h2w6tyZmzDuHcgdGhl?= |
| 175 |
=?UTF-8?B?IGxpbmUgbGVuZ3RoPyAgSSBzdXJlIGhvcGUgdGjDpHQgPSdzIGFu?= |
| 176 |
=?UTF-8?B?ZCAiJ3MgYXJlIGVuY29kZWQgcHJvcGVybHkuICBXaWxsIHRoZXkg?= |
| 177 |
=?UTF-8?B?YmU/?= |
| 178 |
MIME-Version: 1.0 |
| 179 |
Content-Type: text/plain; charset="us-ascii" |
| 180 |
|
| 181 |
This is a test of a very long subject line using base64. |
| 182 |
EOF |
| 183 |
|
| 184 |
run_prog mhbuild "${testname}.longsubject2.actual" |
| 185 |
|
| 186 |
check "${testname}.longsubject2.actual" "${testname}.longsubject2.expected" 'keep first' |
| 187 |
|
| 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?" |
| 189 |
|
| 190 |
rm -f "${testname}.longsubject2.actual" "${backupname}.longsubject2.actual.orig" |
| 191 |
|
| 192 |
# |
| 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 |
| 195 |
# and base64 |
| 196 |
# |
| 197 |
|
| 198 |
cat > "${testname}.longsubject3.actual" <<EOF |
| 199 |
From: Mr Foo Bar <[email protected]> |
| 200 |
To: Somebody <[email protected]> |
| 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 |
| 203 |
|
| 204 |
This is another long test. |
| 205 |
EOF |
| 206 |
|
| 207 |
cat > "${testname}.longsubject3.expected" <<EOF |
| 208 |
From: Mr Foo Bar <[email protected]> |
| 209 |
To: Somebody <[email protected]> |
| 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?= |
| 213 |
MIME-Version: 1.0 |
| 214 |
Content-Type: text/plain; charset="us-ascii" |
| 215 |
|
| 216 |
This is another long test. |
| 217 |
EOF |
| 218 |
|
| 219 |
run_prog mhbuild "${testname}.longsubject3.actual" |
| 220 |
|
| 221 |
check "${testname}.longsubject3.actual" "${testname}.longsubject3.expected" 'keep first' |
| 222 |
|
| 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" |
| 224 |
|
| 225 |
rm -f "${testname}.longsubject3.actual" "${backupname}.longsubject3.actual.orig" |
| 226 |
|
| 227 |
cat > "${testname}.longsubject4.actual" <<EOF |
| 228 |
From: Mr Foo Bar <[email protected]> |
| 229 |
To: Somebody <[email protected]> |
| 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 |
| 232 |
|
| 233 |
This is another long test. |
| 234 |
EOF |
| 235 |
|
| 236 |
cat > "${testname}.longsubject4.expected" <<EOF |
| 237 |
From: Mr Foo Bar <[email protected]> |
| 238 |
To: Somebody <[email protected]> |
| 239 |
Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdCDDuGYgw6UgYmlnIMOcVEYtOCAo?= |
| 240 |
=?UTF-8?B?8J+YiSkgbcO8bHRpYnl0ZSBjaGFyYWN0ZXI7IHdpbGwgdGhpcyB3?= |
| 241 |
=?UTF-8?B?w7hyayBwcsO4cGVybHksIMO4ciB3aWxsIGl0IGdldCB0csK1bg==?= |
| 242 |
=?UTF-8?B?4bSsdGVkPyDwn5ioISBIb3BlZnVsbHkgbsO4dA==?= |
| 243 |
MIME-Version: 1.0 |
| 244 |
Content-Type: text/plain; charset="us-ascii" |
| 245 |
|
| 246 |
This is another long test. |
| 247 |
EOF |
| 248 |
|
| 249 |
run_prog mhbuild "${testname}.longsubject4.actual" |
| 250 |
|
| 251 |
check "${testname}.longsubject4.actual" "${testname}.longsubject4.expected" 'keep first' |
| 252 |
|
| 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" |
| 254 |
|
| 255 |
rm -f "${testname}.longsubject4.actual" "${backupname}.longsubject4.actual.orig" |
| 256 |
|
| 257 |
# |
| 258 |
# Test out some basic email address encoding |
| 259 |
# |
| 260 |
|
| 261 |
cat > "${testname}.basicemail1.actual" <<EOF |
| 262 |
From: Mr Foo Bär <[email protected]> |
| 263 |
To: Somebody <[email protected]> |
| 264 |
Subject: Impørtant stuff |
| 265 |
|
| 266 |
This is important information |
| 267 |
EOF |
| 268 |
|
| 269 |
cat > "${testname}.basicemail1.expected" <<EOF |
| 270 |
From: =?UTF-8?Q?Mr_Foo_B=C3=A4r?= <[email protected]> |
| 271 |
To: Somebody <[email protected]> |
| 272 |
Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?= |
| 273 |
MIME-Version: 1.0 |
| 274 |
Content-Type: text/plain; charset="us-ascii" |
| 275 |
|
| 276 |
This is important information |
| 277 |
EOF |
| 278 |
|
| 279 |
run_prog mhbuild "${testname}.basicemail1.actual" |
| 280 |
|
| 281 |
check "${testname}.basicemail1.actual" "${testname}.basicemail1.expected" 'keep first' |
| 282 |
|
| 283 |
run_test 'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail1.actual"' "Mr Foo Bär <[email protected]>" |
| 284 |
run_test 'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail1.actual"' "Mr Foo Bär" |
| 285 |
|
| 286 |
rm -f "${testname}.basicemail1.actual" "${backupname}.basicemail1.actual.orig" |
| 287 |
|
| 288 |
cat > "${testname}.basicemail2.actual" <<EOF |
| 289 |
From: [email protected] (Mr Foo Bär) |
| 290 |
To: Somebody <[email protected]> |
| 291 |
Subject: Impørtant stuff |
| 292 |
|
| 293 |
This is important information |
| 294 |
EOF |
| 295 |
|
| 296 |
cat > "${testname}.basicemail2.expected" <<EOF |
| 297 |
From: [email protected] (=?UTF-8?Q?Mr_Foo_B=C3=A4r?=) |
| 298 |
To: Somebody <[email protected]> |
| 299 |
Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?= |
| 300 |
MIME-Version: 1.0 |
| 301 |
Content-Type: text/plain; charset="us-ascii" |
| 302 |
|
| 303 |
This is important information |
| 304 |
EOF |
| 305 |
|
| 306 |
run_prog mhbuild "${testname}.basicemail2.actual" |
| 307 |
|
| 308 |
check "${testname}.basicemail2.actual" "${testname}.basicemail2.expected" 'keep first' |
| 309 |
|
| 310 |
run_test 'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail2.actual"' "[email protected] (Mr Foo Bär)" |
| 311 |
run_test 'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail2.actual"' "Mr Foo Bär" |
| 312 |
|
| 313 |
rm -f "${testname}.basicemail2.actual" "${backupname}.basicemail2.actual.orig" |
| 314 |
|
| 315 |
# |
| 316 |
# Make sure the base64 encoder is tested as well |
| 317 |
# |
| 318 |
|
| 319 |
cat > "${testname}.basicemail3.actual" <<EOF |
| 320 |
From: Mr Føø Bär <[email protected]> |
| 321 |
To: Somebody <[email protected]> |
| 322 |
Subject: Impørtant stuff |
| 323 |
|
| 324 |
This is important information |
| 325 |
EOF |
| 326 |
|
| 327 |
cat > "${testname}.basicemail3.expected" <<EOF |
| 328 |
From: =?UTF-8?B?TXIgRsO4w7ggQsOkcg==?= <[email protected]> |
| 329 |
To: Somebody <[email protected]> |
| 330 |
Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?= |
| 331 |
MIME-Version: 1.0 |
| 332 |
Content-Type: text/plain; charset="us-ascii" |
| 333 |
|
| 334 |
This is important information |
| 335 |
EOF |
| 336 |
|
| 337 |
run_prog mhbuild "${testname}.basicemail3.actual" |
| 338 |
|
| 339 |
check "${testname}.basicemail3.actual" "${testname}.basicemail3.expected" 'keep first' |
| 340 |
|
| 341 |
run_test 'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail3.actual"' "Mr Føø Bär <[email protected]>" |
| 342 |
run_test 'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail3.actual"' "Mr Føø Bär" |
| 343 |
|
| 344 |
rm -f "${testname}.basicemail3.actual" "${backupname}.basicemail3.actual.orig" |
| 345 |
|
| 346 |
cat > "${testname}.basicemail4.actual" <<EOF |
| 347 |
From: [email protected] (Mr Føø Bär) |
| 348 |
To: Somebody <[email protected]> |
| 349 |
Subject: Impørtant stuff |
| 350 |
|
| 351 |
This is important information |
| 352 |
EOF |
| 353 |
|
| 354 |
cat > "${testname}.basicemail4.expected" <<EOF |
| 355 |
From: [email protected] (=?UTF-8?B?TXIgRsO4w7ggQsOkcg==?=) |
| 356 |
To: Somebody <[email protected]> |
| 357 |
Subject: =?UTF-8?Q?Imp=C3=B8rtant_stuff?= |
| 358 |
MIME-Version: 1.0 |
| 359 |
Content-Type: text/plain; charset="us-ascii" |
| 360 |
|
| 361 |
This is important information |
| 362 |
EOF |
| 363 |
|
| 364 |
run_prog mhbuild "${testname}.basicemail4.actual" |
| 365 |
|
| 366 |
check "${testname}.basicemail4.actual" "${testname}.basicemail4.expected" 'keep first' |
| 367 |
|
| 368 |
run_test 'eval fmttest -outsize max -format "%(decode{from})" -message -file "${testname}.basicemail4.actual"' "[email protected] (Mr Føø Bär)" |
| 369 |
run_test 'eval fmttest -outsize max -format "%(decode(friendly{from}))" -message -file "${testname}.basicemail4.actual"' "Mr Føø Bär" |
| 370 |
|
| 371 |
rm -f "${testname}.basicemail4.actual" "${backupname}.basicemail4.actual.orig" |
| 372 |
|
| 373 |
# |
| 374 |
# A more complicated header; it includes groups, addresses that require |
| 375 |
# quoted-printable and base64, and unencoded email. |
| 376 |
# |
| 377 |
|
| 378 |
cat > "${testname}.complexemail1.actual" <<EOF |
| 379 |
From: "Mr Føø Bar" <[email protected]> |
| 380 |
To: "Mr F. One" <[email protected]>, "Mr F. Twø" <[email protected]>, |
| 381 |
foo list: Føø Thrëë <[email protected]>, Foo Four <[email protected]>, |
| 382 |
Foo Fivë <[email protected]>; Føø Sîx <[email protected]>, |
| 383 |
"Mr F. Seven" <[email protected]> |
| 384 |
cc: "The Distingµishëd F. Sëvën" <[email protected]> |
| 385 |
Subject: Very long list |
| 386 |
|
| 387 |
This is a lot of people on this email! |
| 388 |
EOF |
| 389 |
|
| 390 |
cat > "${testname}.complexemail1.expected" <<EOF |
| 391 |
From: =?UTF-8?B?TXIgRsO4w7ggQmFy?= <[email protected]> |
| 392 |
To: "Mr F. One" <[email protected]>, |
| 393 |
=?UTF-8?Q?Mr_F=2E_Tw=C3=B8?= <[email protected]>, |
| 394 |
foo list: =?UTF-8?Q?F=C3=B8=C3=B8_Thr=C3=AB=C3=AB?= <[email protected]>, |
| 395 |
Foo Four <[email protected]>, |
| 396 |
=?UTF-8?Q?Foo_Fiv=C3=AB?= <[email protected]>;, |
| 397 |
=?UTF-8?Q?F=C3=B8=C3=B8_S=C3=AEx?= <[email protected]>, |
| 398 |
"Mr F. Seven" <[email protected]> |
| 399 |
cc: =?UTF-8?B?VGhlIERpc3RpbmfCtWlzaMOrZCBGLiBTw6t2w6tu?= <[email protected]> |
| 400 |
Subject: Very long list |
| 401 |
MIME-Version: 1.0 |
| 402 |
Content-Type: text/plain; charset="us-ascii" |
| 403 |
|
| 404 |
This is a lot of people on this email! |
| 405 |
EOF |
| 406 |
|
| 407 |
run_prog mhbuild "${testname}.complexemail1.actual" |
| 408 |
|
| 409 |
check "${testname}.complexemail1.actual" "${testname}.complexemail1.expected" 'keep first' |
| 410 |
|
| 411 |
run_test 'eval fmttest -outsize max -format "%(decode{to})" -message -file "${testname}.complexemail1.actual"' "\"Mr F. One\" <[email protected]>, Mr F. Twø <[email protected]>, foo list: Føø Thrëë <[email protected]>, Foo Four <[email protected]>, Foo Fivë <[email protected]>;, Føø Sîx <[email protected]>, \"Mr F. Seven\" <[email protected]>" |
| 412 |
run_test 'eval fmttest -outsize max -format "%(decode{cc})" -message -file "${testname}.complexemail1.actual"' "The Distingµishëd F. Sëvën <[email protected]>" |
| 413 |
|
| 414 |
rm -f "${testname}.complexemail1.actual" "${backupname}.complexemail1.actual.orig" |
| 415 |
|
| 416 |
exit ${failed:-0} |