]> diplodocus.org Git - nmh/commitdiff
First round of tests! Still want to do more before it gets merged.
authorKen Hornstein <kenh@pobox.com>
Tue, 3 Dec 2013 20:52:00 +0000 (15:52 -0500)
committerKen Hornstein <kenh@pobox.com>
Tue, 3 Dec 2013 20:52:00 +0000 (15:52 -0500)
Makefile.am
test/mhbuild/test-header-encode [new file with mode: 0755]

index 439ce1520b71d6c7583922b5f880cf7224941ddb..19519569dbcbf4fe69e394f0b48fc5b7573478df 100644 (file)
@@ -63,7 +63,8 @@ TESTS = test/ali/test-ali test/anno/test-anno \
        test/install-mh/test-install-mh \
        test/locking/test-datalocking test/locking/test-spoollocking \
        test/manpages/test-manpages \
        test/install-mh/test-install-mh \
        test/locking/test-datalocking test/locking/test-spoollocking \
        test/manpages/test-manpages \
-       test/mhbuild/test-forw test/mhbuild/test-utf8-body \
+       test/mhbuild/test-forw test/mhbuild/test-header-encode \
+       test/mhbuild/test-utf8-body \
        test/mhfixmsg/test-mhfixmsg \
        test/mhlist/test-mhlist test/mhmail/test-mhmail \
        test/mhparam/test-mhparam test/mhpath/test-mhpath \
        test/mhfixmsg/test-mhfixmsg \
        test/mhlist/test-mhlist test/mhmail/test-mhmail \
        test/mhparam/test-mhparam test/mhpath/test-mhpath \
diff --git a/test/mhbuild/test-header-encode b/test/mhbuild/test-header-encode
new file mode 100755 (executable)
index 0000000..b26298b
--- /dev/null
@@ -0,0 +1,118 @@
+#!/bin/sh
+######################################################
+#
+# Test encoding headers according to RFC 2047
+#
+######################################################
+
+set -e
+
+if test -z "${MH_OBJ_DIR}"; then
+    srcdir=`dirname "$0"`/../..
+    MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
+fi
+
+. "${MH_OBJ_DIR}/test/common.sh"
+
+setup_test
+testname="${MH_TEST_DIR}/$$"
+
+#
+# We're going to hardcode UTF-8 for this test.
+#
+
+LC_ALL=en_US.UTF-8; export LC_ALL
+
+#
+# Basic test of encoding a short subject
+#
+cat > "${testname}.basic.actual" <<EOF
+From: Mr Foo Bar <foobar@example.com>
+To: Somebody <somebody@example.com>
+Subject: This is ä test
+
+This is a test
+EOF
+
+cat > "${testname}.basic.expected" <<EOF
+From: Mr Foo Bar <foobar@example.com>
+To: Somebody <somebody@example.com>
+Subject: =?UTF-8?Q?This_is_=C3=A4_test?=
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+
+This is a test
+EOF
+
+mhbuild "${testname}.basic.actual"
+
+check "${testname}.basic.actual" "${testname}.basic.expected" 'keep first'
+
+#
+# Make sure we can undo the encoding
+#
+
+run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test'
+
+rm -f "${testname}.basic.actual"
+
+#
+# Basic test of encoding a short subject, but with base64
+#
+cat > "${testname}.basic.actual" <<EOF
+From: Mr Foo Bar <foobar@example.com>
+To: Somebody <somebody@example.com>
+Subject: This is ä test
+
+This is a test
+EOF
+
+cat > "${testname}.basic.expected" <<EOF
+From: Mr Foo Bar <foobar@example.com>
+To: Somebody <somebody@example.com>
+Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0ZXN0?=
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+
+This is a test
+EOF
+
+mhbuild -headerencoding base64 "${testname}.basic.actual"
+
+check "${testname}.basic.actual" "${testname}.basic.expected" 'keep first'
+
+run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test'
+
+rm -f "${testname}.basic.actual"
+
+#
+# Have a subject that will pick base64 as the shorter encoding
+#
+
+cat > "${testname}.autopick.actual" <<EOF
+From: Mr Foo Bar <foobar@example.com>
+To: Somebody <somebody@example.com>
+Subject: This is ä tëst©
+
+This is a test
+EOF
+
+cat > "${testname}.autopick.expected" <<EOF
+From: Mr Foo Bar <foobar@example.com>
+To: Somebody <somebody@example.com>
+Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdMKp?=
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+
+This is a test
+EOF
+
+mhbuild "${testname}.autopick.actual"
+
+check "${testname}.autopick.actual" "${testname}.autopick.expected" 'keep first'
+
+run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.autopick.actual"' 'This is ä tëst©'
+
+rm -f "${testname}.basic.autopick"
+
+exit ${failed:-0}