Fixed printf's in test suite.
[mmh] / 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
20
21 #### Rely on sendmail/pipe below to override default mts.
22 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
23 cp "${MHMTSCONF}" "$mts_fakesendmail"
24 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
25 MHMTSCONF="$mts_fakesendmail"
26
27 # argument: expected output
28 test_attachment ()
29 {
30   send -draft -mts sendmail/pipe
31
32   # fakesendmail drops the message and any cc's into this mbox.
33   mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
34   inc -silent -file "$mbox"
35   rm -f "$mbox" "$mbox.map"
36
37   #
38   # It's hard to calculate the exact Date: header post is going to
39   # use, so we'll just use sed to remove the actual date so we can easily
40   # compare it against our "correct" output.  And same for charset.
41   #
42   sed -e 's/^Date:.*/Date:/' -e 's/; charset=".*//' \
43       "`mhpath cur`" > "${testname}.actual"
44
45   check "${testname}.actual" "$1"
46 }
47
48 # check that 7-bit body isn't encoded
49 cat > "${MH_TEST_DIR}/attachment.txt" <<EOF
50 this is an attachment
51 EOF
52
53 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
54 From: Mr Nobody <nobody@example.com>
55 To: Somebody <somebody@example.com>
56 Subject: Test
57 Nmh-Attachment: $MH_TEST_DIR/attachment.txt
58
59 This is a test.
60 EOF
61
62 cat > "${testname}.expected" <<EOF
63 From: Mr Nobody <nobody@example.com>
64 To: Somebody <somebody@example.com>
65 Subject: Test
66 MIME-Version: 1.0
67 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
68 Date:
69
70 ------- =_aaaaaaaaaa0
71 Content-Type: text/plain
72
73 This is a test.
74
75 ------- =_aaaaaaaaaa0
76 Content-Type: text/plain; name="attachment.txt"
77 Content-Description: attachment.txt
78 Content-Disposition: attachment; filename="attachment.txt"
79
80 this is an attachment
81
82 ------- =_aaaaaaaaaa0--
83 EOF
84
85 test_attachment "${testname}.expected"
86
87 # check that 8-bit body is encoded as quoted-printable text/plain,
88 # even with an attachment
89
90 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
91 From: Mr Nobody <nobody@example.com>
92 To: Somebody <somebody@example.com>
93 Subject: Test
94 Nmh-Attachment: $MH_TEST_DIR/attachment.txt
95
96 ¡Ay, caramba!
97 EOF
98
99 cat > "${testname}.expected" <<EOF
100 From: Mr Nobody <nobody@example.com>
101 To: Somebody <somebody@example.com>
102 Subject: Test
103 MIME-Version: 1.0
104 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
105 Date:
106
107 ------- =_aaaaaaaaaa0
108 Content-Type: text/plain
109 Content-Transfer-Encoding: quoted-printable
110
111 =A1Ay, caramba!
112
113 ------- =_aaaaaaaaaa0
114 Content-Type: text/plain; name="attachment.txt"
115 Content-Description: attachment.txt
116 Content-Disposition: attachment; filename="attachment.txt"
117
118 this is an attachment
119
120 ------- =_aaaaaaaaaa0--
121 EOF
122
123 test_attachment "${testname}.expected"
124
125 rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt"
126
127 exit ${failed:-0}