]> diplodocus.org Git - nmh/blob - test/mhbuild/test-utf8-body
h/prototypes.h: Remove duplicate prototype for pwd().
[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 en_US.utf-8 en_US.utf8
23
24 #### Rely on sendmail/pipe below to override default mts.
25 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
26 cp "${MHMTSCONF}" "$mts_fakesendmail"
27 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
28 MHMTSCONF="$mts_fakesendmail"
29
30 # argument: expected output
31 test_attachment ()
32 {
33 run_prog send -draft -mts sendmail/pipe
34
35 # fakesendmail drops the message and any cc's into this mbox.
36 mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
37 inc -silent -file "$mbox"
38 rm -f "$mbox" "$mbox.map"
39
40 #
41 # It's hard to calculate the exact Date: header post is going to
42 # use, so we'll just use sed to remove the actual date so we can easily
43 # compare it against our "correct" output. And same for charset,
44 # because mime_type() can rely on file(1) --mime-encoding.
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 Nmh-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 Nmh-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 Nmh-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 Nmh-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 # previous test, but with locale profile entry
192 start_test '8-bit body with C locale with locale profile entry'
193
194 printf 'locale: en_US.UTF-8\n' >> "${MH}"
195
196 cat > "${testname}.expected" <<EOF
197 From: Mr Nobody <nobody@example.com>
198 To: Somebody <somebody@example.com>
199 Subject: Test
200 MIME-Version: 1.0
201 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
202 Content-Transfer-Encoding: 8bit
203 Date:
204
205 ------- =_aaaaaaaaaa0
206 Content-Type: text/plain
207 Content-Transfer-Encoding: 8bit
208
209 ¡Ay, caramba!
210
211 ------- =_aaaaaaaaaa0
212 Content-Type: text/plain; name="attachment.txt"
213 Content-Description: attachment.txt
214 Content-Disposition: attachment; filename="attachment.txt"
215 Content-Transfer-Encoding: 8bit
216
217 8-bit attachment, ¡Ay, caramba!
218
219 ------- =_aaaaaaaaaa0--
220 EOF
221
222 test_attachment "${testname}.expected"
223
224
225 rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt"
226
227 finish_test
228 exit ${failed:-0}
229
230 # emacs hackage to ensure that it writes the inverted exclamation
231 # point as UTF-8 multibyte character \xC2\xA1 instead of just \xA1.
232 # Local Variables:
233 # coding: utf-8
234 # End: