]> diplodocus.org Git - nmh/blob - test/mhshow/test-charset
test-charset: Divulge mhshow output if iconv_open(3) doesn't gripe.
[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 library used on FreeBSD/NetBSD
30 #### doesn'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 #### RFC 2231 defines the extended value syntax:
85 #### extended-initial-value := [charset] "'" [language] "'"
86 #### extended-other-values
87 #### used below, where language is blank.
88
89 start_test 'Encoded parameter value'
90 msgfile=`mhpath new`
91 msgnum=`basename $msgfile`
92 #### Use a charset to exercise the iconv code, if it's available,
93 #### in get_param_value(). The Content-Type charset is UTF-8, encoded
94 #### to exercise iconv.
95 cat > $msgfile <<EOF
96 From: foo@example.edu
97 To: bar@example.edu
98 Subject: test
99 MIME-Version: 1.0
100 Content-Type: text/plain; charset*=ISO-2022-KR''%1b%24%29%43%55%54%46%2d%38
101 Content-Transfer-Encoding: quoted-printable
102 Content-Description: bogus quoted-printable data
103 Date: Sun, 18 Dec 2005 00:52:39 +0100
104
105 4 =C3=B7 2 =3D 2
106 EOF
107
108 cat > $expected <<EOF
109 [ Message inbox:12 ]
110 Date: Sun, 18 Dec 2005 00:52:39 +0100
111 To: bar@example.edu
112 From: foo@example.edu
113 Subject: test
114
115 MIME-Version: 1.0
116 Content-Description: bogus quoted-printable data
117
118 [ part - text/plain - bogus quoted-printable data 11B ]
119 4 รท 2 = 2
120 EOF
121
122 if test "$ICONV_ENABLED" -eq 1; then
123 run_prog mhshow $msgnum > $actual 2>&1
124 check "$expected" "$actual" : encoded parameter value
125 fi
126
127
128 start_test 'replacement character in parameter value'
129 #### The output of this test doesn't show it, but it covers the
130 #### noiconv: portion of get_param_value().
131 cat > $msgfile <<'EOF'
132 Subject: invalid parameter value charset
133 MIME-Version: 1.0
134 Content-Type: text/plain; charset*=invalid''%0Dus-ascii
135 EOF
136
137 cat > $expected <<EOF
138 [ Message inbox:12 ]
139 Subject: invalid parameter value charset
140
141 MIME-Version: 1.0
142
143 [ part - text/plain - 0B ]
144 EOF
145
146 run_prog mhshow $msgnum > $actual 2>&1
147 if [ $iconv_elides_question_marks -eq 1 ]; then
148 check "$expected" "$actual"
149 elif grep "Can't convert .*us-ascii to UTF-8" "$actual" >/dev/null; then
150 :
151 else
152 echo 'iconv complaint not found'
153 sed -n l "$actual"
154 failed=1
155 fi
156
157 finish_test
158 exit $failed