Fixed printf's in test suite.
[mmh] / test / post / test-mts
1 #!/bin/sh
2 #
3 # Test the sendmail/smtp and sendmail/pipe transport methods
4 # via the -mts option.
5 #
6
7 set -e
8
9 if test -z "${MH_OBJ_DIR}"; then
10     srcdir=`dirname "$0"`/../..
11     MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
12 fi
13
14 . "${srcdir}/test/post/test-post-common.sh"
15
16
17 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
18 From: Mr Nobody <nobody@example.com>
19 To: Somebody Else <somebody@example.com>
20 Subject: Test
21
22 This is a test
23 EOF
24
25 cat > "${testname}.expected" <<EOF
26 EHLO nosuchhost.example.com
27 MAIL FROM:<nobody@example.com>
28 RCPT TO:<somebody@example.com>
29 DATA
30 From: Mr Nobody <nobody@example.com>
31 To: Somebody Else <somebody@example.com>
32 Subject: Test
33 Date:
34
35 This is a test
36 .
37 QUIT
38 EOF
39
40 # check invalid -mts selection
41 run_test "send -draft -mts invalid" \
42 "post: unsupported mts selection \"invalid\"
43 send: message not delivered to anyone"
44
45 test_post "${testname}.actual" "${testname}.expected" "-mts smtp"
46
47 #### Rely on sendmail/smtp or sendmail/pipe below to override default mts.
48 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
49 cp "${MHMTSCONF}" "$mts_fakesendmail"
50 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
51 MHMTSCONF="$mts_fakesendmail"
52
53 # $1: -mts switch selection
54 # remaining arguments: expected output(s)
55 test_sendmail ()
56 {
57   send -draft -mts "$1"
58   shift
59
60   # fakesendmail drops the message and any cc's into this mbox.
61   mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
62   inc -silent -file "$mbox"
63   rm -f "$mbox" "$mbox.map"
64
65   n=1
66   for expected in "$@"; do
67     #
68     # It's hard to calculate the exact Date: header post is going to
69     # use, so we'll just use sed to remove the actual date so we can easily
70     # compare it against our "correct" output.
71     #
72     sed -e 's/^Date:.*/Date:/' "`mhpath cur`" > "${testname}.actual$n"
73
74     check "${testname}.actual$n" "$expected"
75
76     if [ "`mhpath cur`" != "`mhpath last`" ]; then
77       folder next >/dev/null
78       arith_eval $n + 1; n=$arith_val
79     fi
80   done
81 }
82
83 # check -mts sendmail/smtp
84 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
85 From: Mr Nobody <nobody@example.com>
86 To: Somebody Else <somebody@example.com>
87 Subject: Test
88
89 This is a test
90 .
91 EOF
92
93 cat > "${testname}.expected" <<EOF
94 From: Mr Nobody <nobody@example.com>
95 To: Somebody Else <somebody@example.com>
96 Subject: Test
97 Date:
98
99 This is a test
100 ..
101 EOF
102
103 test_sendmail sendmail/smtp "${testname}.expected"
104
105 # check -mts sendmail/pipe
106 # Dots are not stuffed because sendmail/pipe causes sendmail to be
107 # invoked with -i.
108 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
109 From: Mr Nobody <nobody@example.com>
110 To: Somebody Else <somebody@example.com>
111 Subject: Test
112
113 This is a test
114 .
115 EOF
116
117 cat > "${testname}.expected" <<EOF
118 From: Mr Nobody <nobody@example.com>
119 To: Somebody Else <somebody@example.com>
120 Subject: Test
121 Date:
122
123 This is a test
124 .
125 EOF
126
127 test_sendmail sendmail/pipe "${testname}.expected"
128
129 # check Bcc
130 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
131 From: Mr Nobody <nobody@example.com>
132 To: Somebody Else <somebody@example.com>
133 Bcc: Silent Partner <bcc@example.com>
134 Subject: Test
135
136 This is a test
137 .
138 EOF
139
140 cat > "${testname}.expected1" <<EOF
141 From: Mr Nobody <nobody@example.com>
142 To: Somebody Else <somebody@example.com>
143 Subject: Test
144 Date:
145
146 This is a test
147 .
148 EOF
149
150 cat > "${testname}.expected2" <<EOF
151 From: Mr Nobody <nobody@example.com>
152 Date:
153 Subject: Test
154
155 ------- Blind-Carbon-Copy
156
157 From: Mr Nobody <nobody@example.com>
158 To: Somebody Else <somebody@example.com>
159 Subject: Test
160 Date:
161
162 This is a test
163 .
164
165 ------- End of Blind-Carbon-Copy
166 EOF
167
168 test_sendmail sendmail/pipe "${testname}.expected1" "${testname}.expected2"
169
170
171 rm -f ${MHMTSCONF}
172
173 exit ${failed:-0}