Added mhbuild: -nocontentid to profile used for tests, to simplify
[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 charset.
43   #
44   sed -e 's/^Date:.*/Date:/' \
45       -e 's/; charset=".*//' \
46       "$cur" > "${testname}.actual"
47
48   check "${testname}.actual" "$1"
49 }
50
51 # check that 7-bit body isn't encoded
52 cat > "${MH_TEST_DIR}/attachment.txt" <<EOF
53 this is an attachment
54 EOF
55
56 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
57 From: Mr Nobody <nobody@example.com>
58 To: Somebody Else <somebody@example.com>
59 Subject: Test
60 Nmh-Attachment: $MH_TEST_DIR/attachment.txt
61
62 This is a test.
63 EOF
64
65 cat > "${testname}.expected" <<EOF
66 From: Mr Nobody <nobody@example.com>
67 To: Somebody Else <somebody@example.com>
68 Subject: Test
69 MIME-Version: 1.0
70 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
71 Date:
72
73 ------- =_aaaaaaaaaa0
74 Content-Type: text/plain
75
76 This is a test.
77
78 ------- =_aaaaaaaaaa0
79 Content-Type: text/plain; name="attachment.txt"
80 Content-Description: attachment.txt
81 Content-Disposition: attachment; filename="attachment.txt"
82
83 this is an attachment
84
85 ------- =_aaaaaaaaaa0--
86 EOF
87
88 test_attachment "${testname}.expected"
89
90 # check that 8-bit body is still encoded as quoted-printable
91 # text/plain, even with an attachment
92
93 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
94 From: Mr Nobody <nobody@example.com>
95 To: Somebody Else <somebody@example.com>
96 Subject: Test
97 Nmh-Attachment: $MH_TEST_DIR/attachment.txt
98
99 ¡Ay, caramba!
100 EOF
101
102 cat > "${testname}.expected" <<EOF
103 From: Mr Nobody <nobody@example.com>
104 To: Somebody Else <somebody@example.com>
105 Subject: Test
106 MIME-Version: 1.0
107 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
108 Date:
109
110 ------- =_aaaaaaaaaa0
111 Content-Type: text/plain
112 Content-Transfer-Encoding: quoted-printable
113
114 =A1Ay, caramba!
115
116 ------- =_aaaaaaaaaa0
117 Content-Type: text/plain; name="attachment.txt"
118 Content-Description: attachment.txt
119 Content-Disposition: attachment; filename="attachment.txt"
120
121 this is an attachment
122
123 ------- =_aaaaaaaaaa0--
124 EOF
125
126 test_attachment "${testname}.expected"
127
128 rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt"
129
130 exit ${failed:-0}