]> diplodocus.org Git - nmh/blob - test/mhbuild/test-header-encode
First round of tests! Still want to do more before it gets merged.
[nmh] / test / mhbuild / test-header-encode
1 #!/bin/sh
2 ######################################################
3 #
4 # Test encoding headers according to RFC 2047
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
20 #
21 # We're going to hardcode UTF-8 for this test.
22 #
23
24 LC_ALL=en_US.UTF-8; export LC_ALL
25
26 #
27 # Basic test of encoding a short subject
28 #
29 cat > "${testname}.basic.actual" <<EOF
30 From: Mr Foo Bar <foobar@example.com>
31 To: Somebody <somebody@example.com>
32 Subject: This is ä test
33
34 This is a test
35 EOF
36
37 cat > "${testname}.basic.expected" <<EOF
38 From: Mr Foo Bar <foobar@example.com>
39 To: Somebody <somebody@example.com>
40 Subject: =?UTF-8?Q?This_is_=C3=A4_test?=
41 MIME-Version: 1.0
42 Content-Type: text/plain; charset="us-ascii"
43
44 This is a test
45 EOF
46
47 mhbuild "${testname}.basic.actual"
48
49 check "${testname}.basic.actual" "${testname}.basic.expected" 'keep first'
50
51 #
52 # Make sure we can undo the encoding
53 #
54
55 run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test'
56
57 rm -f "${testname}.basic.actual"
58
59 #
60 # Basic test of encoding a short subject, but with base64
61 #
62 cat > "${testname}.basic.actual" <<EOF
63 From: Mr Foo Bar <foobar@example.com>
64 To: Somebody <somebody@example.com>
65 Subject: This is ä test
66
67 This is a test
68 EOF
69
70 cat > "${testname}.basic.expected" <<EOF
71 From: Mr Foo Bar <foobar@example.com>
72 To: Somebody <somebody@example.com>
73 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0ZXN0?=
74 MIME-Version: 1.0
75 Content-Type: text/plain; charset="us-ascii"
76
77 This is a test
78 EOF
79
80 mhbuild -headerencoding base64 "${testname}.basic.actual"
81
82 check "${testname}.basic.actual" "${testname}.basic.expected" 'keep first'
83
84 run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.basic.actual"' 'This is ä test'
85
86 rm -f "${testname}.basic.actual"
87
88 #
89 # Have a subject that will pick base64 as the shorter encoding
90 #
91
92 cat > "${testname}.autopick.actual" <<EOF
93 From: Mr Foo Bar <foobar@example.com>
94 To: Somebody <somebody@example.com>
95 Subject: This is ä tëst©
96
97 This is a test
98 EOF
99
100 cat > "${testname}.autopick.expected" <<EOF
101 From: Mr Foo Bar <foobar@example.com>
102 To: Somebody <somebody@example.com>
103 Subject: =?UTF-8?B?VGhpcyBpcyDDpCB0w6tzdMKp?=
104 MIME-Version: 1.0
105 Content-Type: text/plain; charset="us-ascii"
106
107 This is a test
108 EOF
109
110 mhbuild "${testname}.autopick.actual"
111
112 check "${testname}.autopick.actual" "${testname}.autopick.expected" 'keep first'
113
114 run_test 'eval fmttest -outsize max -format "%(decode{subject})" -message -file "${testname}.autopick.actual"' 'This is ä tëst©'
115
116 rm -f "${testname}.basic.autopick"
117
118 exit ${failed:-0}