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