| 1 |
#!/bin/sh |
| 2 |
###################################################### |
| 3 |
# |
| 4 |
# Test the use of the Nmh-Attach: header |
| 5 |
# |
| 6 |
###################################################### |
| 7 |
|
| 8 |
if test -z "${MH_OBJ_DIR}"; then |
| 9 |
srcdir=`dirname "$0"`/../.. |
| 10 |
MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR |
| 11 |
fi |
| 12 |
|
| 13 |
. "$MH_OBJ_DIR/test/common.sh" |
| 14 |
|
| 15 |
setup_test |
| 16 |
|
| 17 |
require_locale $en_locales |
| 18 |
|
| 19 |
draft="$MH_TEST_DIR/$$.draft" |
| 20 |
backup="${MH_TEST_DIR}/`mhparam sbackup`$$.draft.orig" |
| 21 |
expected="$MH_TEST_DIR/$$.expected" |
| 22 |
|
| 23 |
# |
| 24 |
# Test out a simple draft, one part. |
| 25 |
# |
| 26 |
start_test "simple draft, one part" |
| 27 |
cat > "$draft" <<EOF |
| 28 |
To: Mr Test <[email protected]> |
| 29 |
cc: |
| 30 |
Fcc: +outbox |
| 31 |
Nmh-Attach: ${srcdir}/test/mhbuild/tiny.jpg |
| 32 |
------ |
| 33 |
EOF |
| 34 |
|
| 35 |
run_prog mhbuild "$draft" |
| 36 |
|
| 37 |
cat > "$expected" <<EOF |
| 38 |
To: Mr Test <[email protected]> |
| 39 |
cc: |
| 40 |
Fcc: +outbox |
| 41 |
MIME-Version: 1.0 |
| 42 |
Content-Type: image/jpeg; name="tiny.jpg" |
| 43 |
Content-Description: tiny.jpg |
| 44 |
Content-Disposition: attachment; filename="tiny.jpg" |
| 45 |
Content-Transfer-Encoding: base64 |
| 46 |
|
| 47 |
/9j////////Z |
| 48 |
EOF |
| 49 |
|
| 50 |
check "$draft" "$expected" |
| 51 |
|
| 52 |
# |
| 53 |
# Check out more common case, one (or more) attachments |
| 54 |
# along with message text. |
| 55 |
# |
| 56 |
start_test "out more common case, one (or more) attachments" |
| 57 |
cat > "$draft" <<EOF |
| 58 |
To: Mr Test <[email protected]> |
| 59 |
cc: |
| 60 |
Fcc: +outbox |
| 61 |
Nmh-Attach: ${srcdir}/test/mhbuild/tiny.jpg |
| 62 |
Nmh-Attach: ${srcdir}/test/mhbuild/nulls |
| 63 |
------ |
| 64 |
This is a test |
| 65 |
EOF |
| 66 |
|
| 67 |
run_prog mhbuild "$draft" |
| 68 |
|
| 69 |
cat > "$expected" <<EOF |
| 70 |
To: Mr Test <[email protected]> |
| 71 |
cc: |
| 72 |
Fcc: +outbox |
| 73 |
MIME-Version: 1.0 |
| 74 |
Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" |
| 75 |
|
| 76 |
------- =_aaaaaaaaaa0 |
| 77 |
Content-Type: text/plain; charset="us-ascii" |
| 78 |
|
| 79 |
This is a test |
| 80 |
|
| 81 |
------- =_aaaaaaaaaa0 |
| 82 |
Content-Type: image/jpeg; name="tiny.jpg" |
| 83 |
Content-Description: tiny.jpg |
| 84 |
Content-Disposition: attachment; filename="tiny.jpg" |
| 85 |
Content-Transfer-Encoding: base64 |
| 86 |
|
| 87 |
/9j////////Z |
| 88 |
|
| 89 |
------- =_aaaaaaaaaa0 |
| 90 |
Content-Type: application/octet-stream; name="nulls" |
| 91 |
Content-Description: nulls |
| 92 |
Content-Disposition: attachment; filename="nulls" |
| 93 |
Content-Transfer-Encoding: base64 |
| 94 |
|
| 95 |
AAAAAAAAAAAAAAAAAAAA |
| 96 |
|
| 97 |
------- =_aaaaaaaaaa0-- |
| 98 |
EOF |
| 99 |
|
| 100 |
check "$draft" "$expected" |
| 101 |
|
| 102 |
# |
| 103 |
# An empty Attach header |
| 104 |
# |
| 105 |
start_test "empty Attach header" |
| 106 |
cat > "$draft" <<EOF |
| 107 |
To: Mr Test <[email protected]> |
| 108 |
cc: |
| 109 |
Fcc: +outbox |
| 110 |
Nmh-Attach: |
| 111 |
------ |
| 112 |
This is a test of an empty attach header. |
| 113 |
EOF |
| 114 |
|
| 115 |
run_prog mhbuild "$draft" |
| 116 |
|
| 117 |
cat > "$expected" <<EOF |
| 118 |
To: Mr Test <[email protected]> |
| 119 |
cc: |
| 120 |
Fcc: +outbox |
| 121 |
MIME-Version: 1.0 |
| 122 |
Content-Type: text/plain; charset="us-ascii" |
| 123 |
|
| 124 |
This is a test of an empty attach header. |
| 125 |
EOF |
| 126 |
|
| 127 |
check "$draft" "$expected" |
| 128 |
|
| 129 |
# |
| 130 |
# Check a completely empty message |
| 131 |
# |
| 132 |
start_test "a completely empty message" |
| 133 |
cat > "$draft" <<EOF |
| 134 |
To: Mr Test <[email protected]> |
| 135 |
cc: |
| 136 |
Fcc: +outbox |
| 137 |
Subject: Test of an empty body |
| 138 |
EOF |
| 139 |
|
| 140 |
run_prog mhbuild "$draft" |
| 141 |
|
| 142 |
cat > "$expected" <<EOF |
| 143 |
To: Mr Test <[email protected]> |
| 144 |
cc: |
| 145 |
Fcc: +outbox |
| 146 |
Subject: Test of an empty body |
| 147 |
MIME-Version: 1.0 |
| 148 |
Content-Type: text/plain |
| 149 |
EOF |
| 150 |
|
| 151 |
check "$draft" "$expected" |
| 152 |
|
| 153 |
# |
| 154 |
# Make sure we fail if we run into a MIME-Version header |
| 155 |
# |
| 156 |
start_test "fail if we run into a MIME-Version header" |
| 157 |
cat > "$draft" <<EOF |
| 158 |
To: Mr Test <[email protected]> |
| 159 |
cc: |
| 160 |
Fcc: +outbox |
| 161 |
Subject: Test of an already-MIMEified message |
| 162 |
MIME-Version: 1.0 |
| 163 |
Content-Type: text/plain; charset="us-ascii" |
| 164 |
|
| 165 |
This is a preformatted MIME content test. |
| 166 |
EOF |
| 167 |
|
| 168 |
set +e |
| 169 |
run_test 'eval mhbuild "$draft"' "mhbuild: draft shouldn't contain MIME-Version: field" |
| 170 |
set -e |
| 171 |
|
| 172 |
# |
| 173 |
# Run it again using -auto |
| 174 |
# |
| 175 |
|
| 176 |
run_prog mhbuild -auto "$draft" |
| 177 |
|
| 178 |
cat > "$expected" <<EOF |
| 179 |
To: Mr Test <[email protected]> |
| 180 |
cc: |
| 181 |
Fcc: +outbox |
| 182 |
Subject: Test of an already-MIMEified message |
| 183 |
MIME-Version: 1.0 |
| 184 |
Content-Type: text/plain; charset="us-ascii" |
| 185 |
|
| 186 |
This is a preformatted MIME content test. |
| 187 |
EOF |
| 188 |
|
| 189 |
check "$draft" "$expected" |
| 190 |
|
| 191 |
# |
| 192 |
# Make sure -dist does nothing but encode headers |
| 193 |
# |
| 194 |
start_test "-dist does nothing but encode headers" |
| 195 |
cat > "$draft" <<EOF |
| 196 |
To: Señor Test <[email protected]> |
| 197 |
cc: |
| 198 |
Fcc: +outbox |
| 199 |
Subject: An empty dist test |
| 200 |
EOF |
| 201 |
|
| 202 |
run_prog mhbuild -dist "$draft" |
| 203 |
|
| 204 |
cat > "$expected" <<EOF |
| 205 |
To: =?UTF-8?Q?Se=C3=B1or_Test?= <[email protected]> |
| 206 |
cc: |
| 207 |
Fcc: +outbox |
| 208 |
Subject: An empty dist test |
| 209 |
EOF |
| 210 |
|
| 211 |
check "$draft" "$expected" |
| 212 |
|
| 213 |
# |
| 214 |
# Two parts, one attachment; make sure mixing of multiparts at different |
| 215 |
# levels works. This also tests Attach: instead of Nmh-Attach:. |
| 216 |
# |
| 217 |
start_test "two parts, one attachment" |
| 218 |
cat > "$draft" <<EOF |
| 219 |
To: Mr Test <[email protected]> |
| 220 |
cc: |
| 221 |
Fcc: +outbox |
| 222 |
Subject: A more complete multipart test |
| 223 |
Attach: ${srcdir}/test/mhbuild/tiny.jpg |
| 224 |
-------- |
| 225 |
#begin alternative |
| 226 |
#<text/plain |
| 227 |
This is some tëxt. |
| 228 |
#<text/html |
| 229 |
<html> |
| 230 |
<body> |
| 231 |
This is some HTML tëxt. |
| 232 |
</body> |
| 233 |
</html> |
| 234 |
#end |
| 235 |
EOF |
| 236 |
|
| 237 |
run_prog mhbuild "$draft" |
| 238 |
|
| 239 |
cat > "$expected" <<EOF |
| 240 |
To: Mr Test <[email protected]> |
| 241 |
cc: |
| 242 |
Fcc: +outbox |
| 243 |
Subject: A more complete multipart test |
| 244 |
MIME-Version: 1.0 |
| 245 |
Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" |
| 246 |
Content-Transfer-Encoding: 8bit |
| 247 |
|
| 248 |
------- =_aaaaaaaaaa0 |
| 249 |
Content-Type: multipart/alternative; boundary="----- =_aaaaaaaaaa1" |
| 250 |
Content-Transfer-Encoding: 8bit |
| 251 |
|
| 252 |
------- =_aaaaaaaaaa1 |
| 253 |
Content-Type: text/plain; charset="UTF-8" |
| 254 |
Content-Transfer-Encoding: 8bit |
| 255 |
|
| 256 |
This is some tëxt. |
| 257 |
|
| 258 |
------- =_aaaaaaaaaa1 |
| 259 |
Content-Type: text/html; charset="UTF-8" |
| 260 |
Content-Transfer-Encoding: 8bit |
| 261 |
|
| 262 |
<html> |
| 263 |
<body> |
| 264 |
This is some HTML tëxt. |
| 265 |
</body> |
| 266 |
</html> |
| 267 |
|
| 268 |
------- =_aaaaaaaaaa1-- |
| 269 |
|
| 270 |
------- =_aaaaaaaaaa0 |
| 271 |
Content-Type: image/jpeg; name="tiny.jpg" |
| 272 |
Content-Description: tiny.jpg |
| 273 |
Content-Disposition: attachment; filename="tiny.jpg" |
| 274 |
Content-Transfer-Encoding: base64 |
| 275 |
|
| 276 |
/9j////////Z |
| 277 |
|
| 278 |
------- =_aaaaaaaaaa0-- |
| 279 |
EOF |
| 280 |
|
| 281 |
check "$draft" "$expected" |
| 282 |
|
| 283 |
# |
| 284 |
# One attachment, text/plain containing some binary characters, |
| 285 |
# include NUL bytes. |
| 286 |
# |
| 287 |
start_test "One attachment, text/plain containing some binary characters" |
| 288 |
cat > "$draft" <<EOF |
| 289 |
To: Mr Test <[email protected]> |
| 290 |
cc: |
| 291 |
Fcc: +outbox |
| 292 |
Subject: Testing some binary chars |
| 293 |
-------- |
| 294 |
This is some tëxt. |
| 295 |
#text/plain; name="somebinary" [ - ] {attachment} ${srcdir}/test/mhbuild/somebinary |
| 296 |
EOF |
| 297 |
|
| 298 |
run_prog mhbuild "$draft" |
| 299 |
|
| 300 |
cat > "$expected" <<EOF |
| 301 |
To: Mr Test <[email protected]> |
| 302 |
cc: |
| 303 |
Fcc: +outbox |
| 304 |
Subject: Testing some binary chars |
| 305 |
MIME-Version: 1.0 |
| 306 |
Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" |
| 307 |
Content-Transfer-Encoding: 8bit |
| 308 |
|
| 309 |
------- =_aaaaaaaaaa0 |
| 310 |
Content-Type: text/plain; charset="UTF-8" |
| 311 |
Content-Transfer-Encoding: 8bit |
| 312 |
|
| 313 |
This is some tëxt. |
| 314 |
|
| 315 |
------- =_aaaaaaaaaa0 |
| 316 |
Content-Type: text/plain; name="somebinary"; charset="us-ascii" |
| 317 |
Content-Description: - |
| 318 |
Content-Disposition: attachment; filename="somebinary" |
| 319 |
Content-Transfer-Encoding: quoted-printable |
| 320 |
|
| 321 |
|
| 322 |
=46rom here on, this is only = |
| 323 |
|
| 324 |
a test, though it contains =13ome |
| 325 |
=00odd=00 bytes. |
| 326 |
|
| 327 |
------- =_aaaaaaaaaa0-- |
| 328 |
EOF |
| 329 |
|
| 330 |
check "$draft" "$expected" |
| 331 |
|
| 332 |
# check that blank line is inserted between header and content |
| 333 |
start_test "that blank line is inserted between header and content" |
| 334 |
cat > "$MH_TEST_DIR/Mail/oneline" <<EOF |
| 335 |
There needs to be a blank line before this content line. |
| 336 |
EOF |
| 337 |
|
| 338 |
cat > "$draft" <<EOF |
| 339 |
To: Mr Test <[email protected]> |
| 340 |
cc: |
| 341 |
Fcc: +outbox |
| 342 |
Subject: test blank line between header and content |
| 343 |
-------- |
| 344 |
#text/plain {inline} $MH_TEST_DIR/Mail/oneline |
| 345 |
#application/octet-stream {inline} $MH_TEST_DIR/Mail/oneline |
| 346 |
EOF |
| 347 |
|
| 348 |
run_prog mhbuild "$draft" |
| 349 |
|
| 350 |
cat > "$expected" <<EOF |
| 351 |
To: Mr Test <[email protected]> |
| 352 |
cc: |
| 353 |
Fcc: +outbox |
| 354 |
Subject: test blank line between header and content |
| 355 |
MIME-Version: 1.0 |
| 356 |
Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" |
| 357 |
|
| 358 |
------- =_aaaaaaaaaa0 |
| 359 |
Content-Type: text/plain; charset="us-ascii" |
| 360 |
Content-Disposition: inline; filename="oneline" |
| 361 |
|
| 362 |
There needs to be a blank line before this content line. |
| 363 |
|
| 364 |
------- =_aaaaaaaaaa0 |
| 365 |
Content-Type: application/octet-stream |
| 366 |
Content-Disposition: inline; filename="oneline" |
| 367 |
|
| 368 |
There needs to be a blank line before this content line. |
| 369 |
|
| 370 |
------- =_aaaaaaaaaa0-- |
| 371 |
EOF |
| 372 |
|
| 373 |
check "$draft" "$expected" |
| 374 |
|
| 375 |
|
| 376 |
[ ${failed:=0} -eq 0 ] && rm -f ${backup} |
| 377 |
|
| 378 |
finish_test |
| 379 |
exit ${failed:-0} |