]> diplodocus.org Git - nmh/blob - test/mhbuild/test-utf8-body
Replace getcpy() with mh_xstrdup() where the string isn't NULL.
[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 #
45 sed -e 's/^Date:.*/Date:/' -e 's/; charset="[^;]*//' \
46 "`mhpath cur`" > "${testname}.actual"
47
48 check "${testname}.actual" "$1"
49 }
50
51
52 # check that 7-bit body isn't encoded
53 start_test "7-bit body isn't encoded"
54 cat > "${MH_TEST_DIR}/attachment.txt" <<EOF
55 this is an attachment
56 EOF
57
58 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
59 From: Mr Nobody <nobody@example.com>
60 To: Somebody <somebody@example.com>
61 Subject: Test
62 Attach: $MH_TEST_DIR/attachment.txt
63
64 This is a test.
65 EOF
66
67 cat > "${testname}.expected" <<EOF
68 From: Mr Nobody <nobody@example.com>
69 To: Somebody <somebody@example.com>
70 Subject: Test
71 MIME-Version: 1.0
72 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
73 Date:
74
75 ------- =_aaaaaaaaaa0
76 Content-Type: text/plain
77
78 This is a test.
79
80 ------- =_aaaaaaaaaa0
81 Content-Type: text/plain; name="attachment.txt"
82 Content-Description: attachment.txt
83 Content-Disposition: attachment; filename="attachment.txt"
84
85 this is an attachment
86
87 ------- =_aaaaaaaaaa0--
88 EOF
89
90 test_attachment "${testname}.expected"
91
92
93 # check that 8-bit body is encoded as quoted-printable text/plain,
94 # even with an attachment
95 start_test '8-bit body is encoded as quoted-printable text/plain'
96 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
97 From: Mr Nobody <nobody@example.com>
98 To: Somebody <somebody@example.com>
99 Subject: Test
100 Attach: $MH_TEST_DIR/attachment.txt
101
102 ¡Ay, caramba!
103 EOF
104
105 cat > "${testname}.expected" <<EOF
106 From: Mr Nobody <nobody@example.com>
107 To: Somebody <somebody@example.com>
108 Subject: Test
109 MIME-Version: 1.0
110 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
111 Content-Transfer-Encoding: 8bit
112 Date:
113
114 ------- =_aaaaaaaaaa0
115 Content-Type: text/plain
116 Content-Transfer-Encoding: 8bit
117
118 ¡Ay, caramba!
119
120 ------- =_aaaaaaaaaa0
121 Content-Type: text/plain; name="attachment.txt"
122 Content-Description: attachment.txt
123 Content-Disposition: attachment; filename="attachment.txt"
124
125 this is an attachment
126
127 ------- =_aaaaaaaaaa0--
128 EOF
129
130 test_attachment "${testname}.expected"
131
132
133 # check that 8-bit attachment gets C-T-E
134 start_test '8-bit attachment gets C-T-E'
135 rm -f "${MH_TEST_DIR}/attachment.txt"
136 cat > "${MH_TEST_DIR}/attachment.txt" <<EOF
137 8-bit attachment, ¡Ay, caramba!
138 EOF
139
140 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
141 From: Mr Nobody <nobody@example.com>
142 To: Somebody <somebody@example.com>
143 Subject: Test
144 Attach: $MH_TEST_DIR/attachment.txt
145 EOF
146
147 cat > "${testname}.expected" <<EOF
148 From: Mr Nobody <nobody@example.com>
149 To: Somebody <somebody@example.com>
150 Subject: Test
151 MIME-Version: 1.0
152 Content-Type: text/plain; name="attachment.txt"
153 Content-Description: attachment.txt
154 Content-Disposition: attachment; filename="attachment.txt"
155 Content-Transfer-Encoding: 8bit
156 Date:
157
158 8-bit attachment, ¡Ay, caramba!
159 EOF
160
161 test_attachment "${testname}.expected"
162
163
164 # check 8-bit body but make sure that the locale is set to C, which
165 # should cause mhbuild to fail
166 start_test '8-bit body with C locale'
167 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
168 From: Mr Nobody <nobody@example.com>
169 To: Somebody <somebody@example.com>
170 Subject: Test
171 Attach: $MH_TEST_DIR/attachment.txt
172
173 ¡Ay, caramba!
174 EOF
175
176 LC_ALL="C"; export LC_ALL
177
178 set +e
179 run_prog send -draft -mts sendmail/pipe > "$actual" 2>&1
180 set -e
181
182 cat > "$expected" <<EOF
183 mhbuild: Text content contains 8 bit characters, but character set is US-ASCII
184 ${MH_INST_DIR}${bindir}/mhbuild: exit 1
185 EOF
186
187 check "$expected" "$actual"
188
189
190 rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt"
191
192 finish_test
193 exit ${failed:-0}
194
195 # emacs hackage to ensure that it writes the inverted exclamation
196 # point as UTF-8 multibyte character \xC2\xA1 instead of just \xA1.
197 # Local Variables:
198 # coding: utf-8
199 # End: