#!/bin/sh ###################################################### # # Test encoding headers according to RFC 2047 # ###################################################### set -e if test -z "${MH_OBJ_DIR}"; then srcdir=`dirname "$0"`/../.. MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR fi . "${MH_OBJ_DIR}/test/common.sh" setup_test testname="${MH_TEST_DIR}/$$" # # We're going to hardcode UTF-8 for this test. # LC_ALL=en_US.UTF-8; export LC_ALL # # Basic test of encoding a short subject # cat > "${testname}.basic.actual" < To: Somebody Subject: This is ä test This is a test EOF cat > "${testname}.basic.expected" < To: Somebody Subject: =?UTF-8?Q?This_is_=C3=A4_test?= MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" This is a test EOF mhbuild "${testname}.basic.actual" check "${testname}.basic.actual" "${testname}.basic.expected" 'keep first' # # Make sure we can undo the encoding # run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test' rm -f "${testname}.basic.actual" # # Basic test of encoding a short subject, but with base64 # cat > "${testname}.basic.actual" < To: Somebody Subject: This is ä test This is a test EOF cat > "${testname}.basic.expected" < To: Somebody Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0ZXN0?= MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" This is a test EOF mhbuild -headerencoding base64 "${testname}.basic.actual" check "${testname}.basic.actual" "${testname}.basic.expected" 'keep first' run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test' rm -f "${testname}.basic.actual" # # Have a subject that will pick base64 as the shorter encoding # cat > "${testname}.autopick.actual" < To: Somebody Subject: This is ä tëst© This is a test EOF cat > "${testname}.autopick.expected" < To: Somebody Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdMKp?= MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" This is a test EOF mhbuild "${testname}.autopick.actual" check "${testname}.autopick.actual" "${testname}.autopick.expected" 'keep first' run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.autopick.actual"' 'This is ä tëst©' rm -f "${testname}.basic.autopick" # # Tests using longer subject lines. # cat > "${testname}.longsubject1.actual" < To: Somebody Subject: 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? This is a test of a very long subject line. EOF cat > "${testname}.longsubject1.expected" < To: Somebody Subject: =?UTF-8?Q?This_is_=C3=A4_t=C3=ABst_of_a_rather_long_s=C3=BCbject_?= =?UTF-8?Q?line;_will_it_overflow_the_line_length=3F__I_sure_hope_?= =?UTF-8?Q?th=C3=A4t_=3D's_and_"'s_are_encoded_properly.__Will_the?= =?UTF-8?Q?y_be=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" This is a test of a very long subject line. EOF mhbuild "${testname}.longsubject1.actual" check "${testname}.longsubject1.actual" "${testname}.longsubject1.expected" 'keep first' 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?" rm -f "${testname}.longsubject1.actual" # # Test a longer line with base64 encoding # cat > "${testname}.longsubject2.actual" < To: Somebody Subject: 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? This is a test of a very long subject line using base64. EOF cat > "${testname}.longsubject2.expected" < To: Somebody Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdCDDuGYgw6QgcsOkdGjDq3IgbMO4bmcg?= =?UTF-8?B?c8O8YmrDq2N0IGxpbmU7IHdpbGwgaXQgw7h2w6tyZmzDuHcgdGhl?= =?UTF-8?B?IGxpbmUgbGVuZ3RoPyAgSSBzdXJlIGhvcGUgdGjDpHQgPSdzIGFu?= =?UTF-8?B?ZCAiJ3MgYXJlIGVuY29kZWQgcHJvcGVybHkuICBXaWxsIHRoZXkg?= =?UTF-8?B?YmU/?= MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" This is a test of a very long subject line using base64. EOF mhbuild "${testname}.longsubject2.actual" check "${testname}.longsubject2.actual" "${testname}.longsubject2.expected" 'keep first' 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?" exit ${failed:-0}