]> diplodocus.org Git - nmh/blob - test/mhbuild/test-utf8-body
Return an appropriate error if the input characters are 8-bit, but the
[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 LC_ALL=en_US.UTF-8; export LC_ALL
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 # check that 7-bit body isn't encoded
52 cat > "${MH_TEST_DIR}/attachment.txt" <<EOF
53 this is an attachment
54 EOF
55
56 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
57 From: Mr Nobody <nobody@example.com>
58 To: Somebody <somebody@example.com>
59 Subject: Test
60 Attach: $MH_TEST_DIR/attachment.txt
61
62 This is a test.
63 EOF
64
65 cat > "${testname}.expected" <<EOF
66 From: Mr Nobody <nobody@example.com>
67 To: Somebody <somebody@example.com>
68 Subject: Test
69 MIME-Version: 1.0
70 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
71 Date:
72
73 ------- =_aaaaaaaaaa0
74 Content-Type: text/plain
75
76 This is a test.
77
78 ------- =_aaaaaaaaaa0
79 Content-Type: text/plain; name="attachment.txt"
80 Content-Description: attachment.txt
81 Content-Disposition: attachment; filename="attachment.txt"
82
83 this is an attachment
84
85 ------- =_aaaaaaaaaa0--
86 EOF
87
88 test_attachment "${testname}.expected"
89
90 # check that 8-bit body is encoded as quoted-printable text/plain,
91 # even with an attachment
92
93 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
94 From: Mr Nobody <nobody@example.com>
95 To: Somebody <somebody@example.com>
96 Subject: Test
97 Attach: $MH_TEST_DIR/attachment.txt
98
99 ¡Ay, caramba!
100 EOF
101
102 cat > "${testname}.expected" <<EOF
103 From: Mr Nobody <nobody@example.com>
104 To: Somebody <somebody@example.com>
105 Subject: Test
106 MIME-Version: 1.0
107 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
108 Content-Transfer-Encoding: 8bit
109 Date:
110
111 ------- =_aaaaaaaaaa0
112 Content-Type: text/plain
113 Content-Transfer-Encoding: 8bit
114
115 ¡Ay, caramba!
116
117 ------- =_aaaaaaaaaa0
118 Content-Type: text/plain; name="attachment.txt"
119 Content-Description: attachment.txt
120 Content-Disposition: attachment; filename="attachment.txt"
121
122 this is an attachment
123
124 ------- =_aaaaaaaaaa0--
125 EOF
126
127 test_attachment "${testname}.expected"
128
129 # Repeat the previous test, but make sure that the locale is set to C, which
130 # should cause mhbuild to fail
131
132 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
133 From: Mr Nobody <nobody@example.com>
134 To: Somebody <somebody@example.com>
135 Subject: Test
136 Attach: $MH_TEST_DIR/attachment.txt
137
138 ¡Ay, caramba!
139 EOF
140
141 LC_ALL="C"; export LC_ALL
142
143 set +e
144 run_prog send -draft -mts sendmail/pipe > "$actual" 2>&1
145 set -e
146
147 cat > "$expected" <<EOF
148 mhbuild: Text content contains 8 bit characters, but character set is US-ASCII
149 ${MH_INST_DIR}${bindir}/mhbuild: exit 1
150 EOF
151
152 check "$expected" "$actual"
153
154 rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt"
155
156 exit ${failed:-0}
157
158 # emacs hackage to ensure that it writes the inverted exclamation
159 # point as UTF-8 multibyte character \xC2\xA1 instead of just \xA1.
160 # Local Variables:
161 # coding: utf-8
162 # End: