| 1 |
#!/bin/sh |
| 2 |
###################################################### |
| 3 |
# |
| 4 |
# Test charset conversion functionality |
| 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' mhshow - |
| 20 |
|
| 21 |
require_locale $en_locales |
| 22 |
|
| 23 |
iconv_elides_question_marks=0 |
| 24 |
if test "$ICONV_ENABLED" -eq 1; then |
| 25 |
#### The GNU iconv library normalises charset names by eliding '?', along |
| 26 |
#### with some other characters. The iconv libraries used on FreeBSD/NetBSD |
| 27 |
#### and Mac OS X don't. |
| 28 |
printf x | iconv -f '?UTF-8' -t UTF-8 >/dev/null 2>&1 && |
| 29 |
iconv_elides_question_marks=1 |
| 30 |
fi |
| 31 |
|
| 32 |
expected=$MH_TEST_DIR/$$.expected |
| 33 |
actual=$MH_TEST_DIR/$$.actual |
| 34 |
|
| 35 |
echo 'mhshow-charset-windows-1252: echo "This is a test"' >> "$MH" |
| 36 |
|
| 37 |
# Write message with bogus quoted-printable data. |
| 38 |
start_test 'Write message with bogus quoted-printable data' |
| 39 |
msgfile=`mhpath new` |
| 40 |
msgnum=`basename $msgfile` |
| 41 |
cat > $msgfile <<EOF |
| 42 |
From: [email protected] |
| 43 |
To: [email protected] |
| 44 |
Subject: test |
| 45 |
MIME-Version: 1.0 |
| 46 |
Content-Type: text/plain; charset=windows-1252 |
| 47 |
Content-Transfer-Encoding: quoted-printable |
| 48 |
Content-Description: bogus quoted-printable data |
| 49 |
Date: Sun, 18 Dec 2005 00:52:39 +0100 |
| 50 |
|
| 51 |
4 =F7 2 =3D 2 |
| 52 |
EOF |
| 53 |
|
| 54 |
cat > $expected <<EOF |
| 55 |
[ Message inbox:11 ] |
| 56 |
Date: Sun, 18 Dec 2005 00:52:39 +0100 |
| 57 |
To: [email protected] |
| 58 |
From: [email protected] |
| 59 |
Subject: test |
| 60 |
|
| 61 |
MIME-Version: 1.0 |
| 62 |
Content-Description: bogus quoted-printable data |
| 63 |
|
| 64 |
[ part - text/plain - bogus quoted-printable data 11B ] |
| 65 |
This is a test |
| 66 |
EOF |
| 67 |
|
| 68 |
run_prog mhshow $msgnum > $actual 2>&1 |
| 69 |
check "$expected" "$actual" 'keep first' : bogus quoted-printable data |
| 70 |
|
| 71 |
|
| 72 |
start_test 'locale profile component' |
| 73 |
#### Used LC_ALL above, now use locale profile component instead. |
| 74 |
printf "locale: $LC_ALL\n" >> "${MH}" |
| 75 |
unset LC_ALL |
| 76 |
|
| 77 |
run_prog mhshow $msgnum > $actual 2>&1 |
| 78 |
check "$expected" "$actual" : locale profile component |
| 79 |
|
| 80 |
|
| 81 |
#### All of the remaining tests rely on iconv.a |
| 82 |
if test "$ICONV_ENABLED" -eq 0; then |
| 83 |
finish_test |
| 84 |
exit $failed |
| 85 |
fi |
| 86 |
|
| 87 |
|
| 88 |
#### RFC 2231 defines the extended value syntax: |
| 89 |
#### extended-initial-value := [charset] "'" [language] "'" |
| 90 |
#### extended-other-values |
| 91 |
#### used below, where language is blank. |
| 92 |
|
| 93 |
start_test 'Encoded parameter value' |
| 94 |
msgfile=`mhpath new` |
| 95 |
msgnum=`basename $msgfile` |
| 96 |
#### Use a charset to exercise the iconv code, if it's available, |
| 97 |
#### in get_param_value(). The Content-Type charset is UTF-8, encoded |
| 98 |
#### to exercise iconv. |
| 99 |
cat > $msgfile <<EOF |
| 100 |
From: [email protected] |
| 101 |
To: [email protected] |
| 102 |
Subject: test |
| 103 |
MIME-Version: 1.0 |
| 104 |
Content-Type: text/plain; charset*=ISO-2022-KR''%1b%24%29%43%55%54%46%2d%38 |
| 105 |
Content-Transfer-Encoding: quoted-printable |
| 106 |
Content-Description: bogus quoted-printable data |
| 107 |
Date: Sun, 18 Dec 2005 00:52:39 +0100 |
| 108 |
|
| 109 |
4 =C3=B7 2 =3D 2 |
| 110 |
EOF |
| 111 |
|
| 112 |
cat > $expected <<EOF |
| 113 |
[ Message inbox:12 ] |
| 114 |
Date: Sun, 18 Dec 2005 00:52:39 +0100 |
| 115 |
To: [email protected] |
| 116 |
From: [email protected] |
| 117 |
Subject: test |
| 118 |
|
| 119 |
MIME-Version: 1.0 |
| 120 |
Content-Description: bogus quoted-printable data |
| 121 |
|
| 122 |
[ part - text/plain - bogus quoted-printable data 11B ] |
| 123 |
4 รท 2 = 2 |
| 124 |
EOF |
| 125 |
|
| 126 |
run_prog mhshow $msgnum > $actual 2>&1 |
| 127 |
check "$expected" "$actual" : encoded parameter value |
| 128 |
|
| 129 |
|
| 130 |
#### mhshow replaces the invalid character in the charset parameter value with |
| 131 |
#### a '?'. So, a charset name of "?us-ascii" is fed to iconv. If |
| 132 |
#### $iconv_elides_question_marks, iconv will normalize that to "us-ascii". |
| 133 |
#### Otherwise, we expect iconv to fail. |
| 134 |
start_test 'replacement character in parameter value' |
| 135 |
cat > $msgfile <<'EOF' |
| 136 |
Subject: invalid parameter value charset |
| 137 |
MIME-Version: 1.0 |
| 138 |
Content-Type: text/plain; charset*=invalid''%0Dus-ascii |
| 139 |
EOF |
| 140 |
|
| 141 |
cat > $expected <<EOF |
| 142 |
[ Message inbox:12 ] |
| 143 |
Subject: invalid parameter value charset |
| 144 |
|
| 145 |
MIME-Version: 1.0 |
| 146 |
|
| 147 |
[ part - text/plain - 0B ] |
| 148 |
EOF |
| 149 |
|
| 150 |
run_prog mhshow $msgnum > $actual 2>&1 |
| 151 |
if [ $iconv_elides_question_marks -eq 1 ]; then |
| 152 |
check "$expected" "$actual" |
| 153 |
else |
| 154 |
if grep "Can't convert .*us-ascii to UTF-8" "$actual" >/dev/null; then |
| 155 |
rm -f "$expected" "$actual" |
| 156 |
else |
| 157 |
failed=1 |
| 158 |
fi |
| 159 |
fi |
| 160 |
|
| 161 |
|
| 162 |
finish_test |
| 163 |
exit $failed |