| 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_locales |
| 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" |
| 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 <[email protected]> |
| 61 |
To: Somebody <[email protected]> |
| 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 <[email protected]> |
| 70 |
To: Somebody <[email protected]> |
| 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 <[email protected]> |
| 99 |
To: Somebody <[email protected]> |
| 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 <[email protected]> |
| 108 |
To: Somebody <[email protected]> |
| 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 <[email protected]> |
| 143 |
To: Somebody <[email protected]> |
| 144 |
Subject: Test |
| 145 |
Nmh-Attach: $MH_TEST_DIR/attachment.txt |
| 146 |
EOF |
| 147 |
|
| 148 |
cat > "${testname}.expected" <<EOF |
| 149 |
From: Mr Nobody <[email protected]> |
| 150 |
To: Somebody <[email protected]> |
| 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 <[email protected]> |
| 170 |
To: Somebody <[email protected]> |
| 171 |
Subject: Test |
| 172 |
Nmh-Attach: $MH_TEST_DIR/attachment.txt |
| 173 |
|
| 174 |
¡Ay, caramba! |
| 175 |
EOF |
| 176 |
|
| 177 |
found_locale=$LC_ALL # Set by require_locale(). |
| 178 |
LC_ALL="C"; export LC_ALL |
| 179 |
|
| 180 |
set +e |
| 181 |
run_prog send -draft -mts sendmail/pipe > "$actual" 2>&1 |
| 182 |
set -e |
| 183 |
|
| 184 |
cat > "$expected" <<EOF |
| 185 |
mhbuild: Text content contains 8 bit characters, but character set is US-ASCII |
| 186 |
${MH_INST_DIR}${bindir}/mhbuild: exited 1 |
| 187 |
EOF |
| 188 |
|
| 189 |
check "$expected" "$actual" |
| 190 |
|
| 191 |
|
| 192 |
# previous test, but with locale profile entry |
| 193 |
start_test '8-bit body with C locale with locale profile entry' |
| 194 |
|
| 195 |
printf 'locale: %s\n' "$found_locale" >>"${MH}" |
| 196 |
|
| 197 |
cat > "${testname}.expected" <<EOF |
| 198 |
From: Mr Nobody <[email protected]> |
| 199 |
To: Somebody <[email protected]> |
| 200 |
Subject: Test |
| 201 |
MIME-Version: 1.0 |
| 202 |
Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" |
| 203 |
Content-Transfer-Encoding: 8bit |
| 204 |
Date: |
| 205 |
|
| 206 |
------- =_aaaaaaaaaa0 |
| 207 |
Content-Type: text/plain |
| 208 |
Content-Transfer-Encoding: 8bit |
| 209 |
|
| 210 |
¡Ay, caramba! |
| 211 |
|
| 212 |
------- =_aaaaaaaaaa0 |
| 213 |
Content-Type: text/plain; name="attachment.txt" |
| 214 |
Content-Description: attachment.txt |
| 215 |
Content-Disposition: attachment; filename="attachment.txt" |
| 216 |
Content-Transfer-Encoding: 8bit |
| 217 |
|
| 218 |
8-bit attachment, ¡Ay, caramba! |
| 219 |
|
| 220 |
------- =_aaaaaaaaaa0-- |
| 221 |
EOF |
| 222 |
|
| 223 |
test_attachment "${testname}.expected" |
| 224 |
|
| 225 |
|
| 226 |
rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt" |
| 227 |
|
| 228 |
finish_test |
| 229 |
exit ${failed:-0} |
| 230 |
|
| 231 |
# emacs hackage to ensure that it writes the inverted exclamation |
| 232 |
# point as UTF-8 multibyte character \xC2\xA1 instead of just \xA1. |
| 233 |
# Local Variables: |
| 234 |
# coding: utf-8 |
| 235 |
# End: |