]> diplodocus.org Git - nmh/blob - test/mhbuild/test-utf8-body
Enabled check for 8-bit content in all text parts, not just those
[nmh] / test / mhbuild / test-utf8-body
1 #!/bin/sh
2 ######################################################
3 #
4 # Test UTF-8 body along with an attachment
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 testname="${MH_TEST_DIR}/$$"
19 expected="$MH_TEST_DIR/$$.expected"
20 actual="$MH_TEST_DIR/$$.actual"
21
22 require_locale en_US.utf-8 en_US.utf8
23 LC_ALL=en_US.UTF-8; export LC_ALL
24
25 #### Rely on sendmail/pipe below to override default mts.
26 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
27 cp "${MHMTSCONF}" "$mts_fakesendmail"
28 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
29 MHMTSCONF="$mts_fakesendmail"
30
31 # argument: expected output
32 test_attachment ()
33 {
34 run_prog send -draft -mts sendmail/pipe
35
36 # fakesendmail drops the message and any cc's into this mbox.
37 mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
38 inc -silent -file "$mbox"
39 rm -f "$mbox" "$mbox.map"
40
41 #
42 # It's hard to calculate the exact Date: header post is going to
43 # use, so we'll just use sed to remove the actual date so we can easily
44 # compare it against our "correct" output. And same for charset.
45 #
46 sed -e 's/^Date:.*/Date:/' -e 's/; charset="[^;]*//' \
47 "`mhpath cur`" > "${testname}.actual"
48
49 check "${testname}.actual" "$1"
50 }
51
52
53 # check that 7-bit body isn't encoded
54 start_test "7-bit body isn't encoded"
55 cat > "${MH_TEST_DIR}/attachment.txt" <<EOF
56 this is an attachment
57 EOF
58
59 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
60 From: Mr Nobody <nobody@example.com>
61 To: Somebody <somebody@example.com>
62 Subject: Test
63 Attach: $MH_TEST_DIR/attachment.txt
64
65 This is a test.
66 EOF
67
68 cat > "${testname}.expected" <<EOF
69 From: Mr Nobody <nobody@example.com>
70 To: Somebody <somebody@example.com>
71 Subject: Test
72 MIME-Version: 1.0
73 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
74 Date:
75
76 ------- =_aaaaaaaaaa0
77 Content-Type: text/plain
78
79 This is a test.
80
81 ------- =_aaaaaaaaaa0
82 Content-Type: text/plain; name="attachment.txt"
83 Content-Description: attachment.txt
84 Content-Disposition: attachment; filename="attachment.txt"
85
86 this is an attachment
87
88 ------- =_aaaaaaaaaa0--
89 EOF
90
91 test_attachment "${testname}.expected"
92
93
94 # check that 8-bit body is encoded as quoted-printable text/plain,
95 # even with an attachment
96 start_test '8-bit body is encoded as quoted-printable text/plain'
97 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
98 From: Mr Nobody <nobody@example.com>
99 To: Somebody <somebody@example.com>
100 Subject: Test
101 Attach: $MH_TEST_DIR/attachment.txt
102
103 ¡Ay, caramba!
104 EOF
105
106 cat > "${testname}.expected" <<EOF
107 From: Mr Nobody <nobody@example.com>
108 To: Somebody <somebody@example.com>
109 Subject: Test
110 MIME-Version: 1.0
111 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
112 Content-Transfer-Encoding: 8bit
113 Date:
114
115 ------- =_aaaaaaaaaa0
116 Content-Type: text/plain
117 Content-Transfer-Encoding: 8bit
118
119 ¡Ay, caramba!
120
121 ------- =_aaaaaaaaaa0
122 Content-Type: text/plain; name="attachment.txt"
123 Content-Description: attachment.txt
124 Content-Disposition: attachment; filename="attachment.txt"
125
126 this is an attachment
127
128 ------- =_aaaaaaaaaa0--
129 EOF
130
131 test_attachment "${testname}.expected"
132
133
134 # check that 8-bit attachment gets C-T-E
135 start_test '8-bit attachment gets C-T-E'
136 rm -f "${MH_TEST_DIR}/attachment.txt"
137 cat > "${MH_TEST_DIR}/attachment.txt" <<EOF
138 8-bit attachment, ¡Ay, caramba!
139 EOF
140
141 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
142 From: Mr Nobody <nobody@example.com>
143 To: Somebody <somebody@example.com>
144 Subject: Test
145 Attach: $MH_TEST_DIR/attachment.txt
146 EOF
147
148 cat > "${testname}.expected" <<EOF
149 From: Mr Nobody <nobody@example.com>
150 To: Somebody <somebody@example.com>
151 Subject: Test
152 MIME-Version: 1.0
153 Content-Type: text/plain; name="attachment.txt"
154 Content-Description: attachment.txt
155 Content-Disposition: attachment; filename="attachment.txt"
156 Content-Transfer-Encoding: 8bit
157 Date:
158
159 8-bit attachment, ¡Ay, caramba!
160 EOF
161
162 test_attachment "${testname}.expected"
163
164
165 # check 8-bit body but make sure that the locale is set to C, which
166 # should cause mhbuild to fail
167 start_test '8-bit body with C locale'
168 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
169 From: Mr Nobody <nobody@example.com>
170 To: Somebody <somebody@example.com>
171 Subject: Test
172 Attach: $MH_TEST_DIR/attachment.txt
173
174 ¡Ay, caramba!
175 EOF
176
177 LC_ALL="C"; export LC_ALL
178
179 set +e
180 run_prog send -draft -mts sendmail/pipe > "$actual" 2>&1
181 set -e
182
183 cat > "$expected" <<EOF
184 mhbuild: Text content contains 8 bit characters, but character set is US-ASCII
185 ${MH_INST_DIR}${bindir}/mhbuild: exit 1
186 EOF
187
188 check "$expected" "$actual"
189
190
191 rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt"
192
193 finish_test
194 exit ${failed:-0}
195
196 # emacs hackage to ensure that it writes the inverted exclamation
197 # point as UTF-8 multibyte character \xC2\xA1 instead of just \xA1.
198 # Local Variables:
199 # coding: utf-8
200 # End: