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