e7cb2f8300bc35fec5b366732803f35da2b564d4
[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 "%s\n" "sendmail: ${srcdir}/test/fakesendmail" >>"$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   cur=`mhpath cur`
38
39   #
40   # It's hard to calculate the exact Date: header post is going to
41   # use, so we'll just use sed to remove the actual date so we can easily
42   # compare it against our "correct" output.  And same for
43   # Content-ID and charset.
44   #
45   sed -e 's/^Date:.*/Date:/' \
46       -e 's/^Content-ID:.*/Content-ID:/' \
47       -e 's/; charset=".*//' \
48       "$cur" > "${testname}.actual"
49
50   check "${testname}.actual" "$1"
51 }
52
53 # check that 7-bit body isn't encoded
54 cat > "${MH_TEST_DIR}/attachment.txt" <<EOF
55 this is an attachment
56 EOF
57
58 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
59 From: Mr Nobody <nobody@example.com>
60 To: Somebody Else <somebody@example.com>
61 Subject: Test
62 Nmh-Attachment: $MH_TEST_DIR/attachment.txt
63
64 This is a test.
65 EOF
66
67 cat > "${testname}.expected" <<EOF
68 From: Mr Nobody <nobody@example.com>
69 To: Somebody Else <somebody@example.com>
70 Subject: Test
71 MIME-Version: 1.0
72 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
73 Content-ID:
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 # check that 8-bit body is still encoded as quoted-printable
94 # text/plain, even with an attachment
95
96 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
97 From: Mr Nobody <nobody@example.com>
98 To: Somebody Else <somebody@example.com>
99 Subject: Test
100 Nmh-Attachment: $MH_TEST_DIR/attachment.txt
101
102 ¡Ay, caramba!
103 EOF
104
105 cat > "${testname}.expected" <<EOF
106 From: Mr Nobody <nobody@example.com>
107 To: Somebody Else <somebody@example.com>
108 Subject: Test
109 MIME-Version: 1.0
110 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
111 Content-ID:
112 Date:
113
114 ------- =_aaaaaaaaaa0
115 Content-Type: text/plain
116 Content-Transfer-Encoding: quoted-printable
117
118 =A1Ay, caramba!
119
120 ------- =_aaaaaaaaaa0
121 Content-Type: text/plain; name="attachment.txt"
122 Content-Description: attachment.txt
123 Content-Disposition: attachment; filename="attachment.txt"
124
125 this is an attachment
126
127 ------- =_aaaaaaaaaa0--
128 EOF
129
130 test_attachment "${testname}.expected"
131
132 rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt"
133
134 exit ${failed:-0}