]> diplodocus.org Git - nmh/blob - test/post/test-mts
Subtracted 1 from size argument in some calls to strncpy(3).
[nmh] / 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 MIME-Version: 1.0
34 Content-Type: text/plain; charset="us-ascii"
35 Date:
36
37 This is a test
38 .
39 QUIT
40 EOF
41
42 # check invalid -mts selection
43 start_test 'invalid -mts selection'
44 run_test "send -draft -mts invalid" \
45 "post: unsupported mts selection \"invalid\"
46 send: message not delivered to anyone"
47
48 test_post "${testname}.actual" "${testname}.expected" "-mts smtp"
49
50 #### Rely on sendmail/smtp or sendmail/pipe below to override default mts.
51 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
52 cp "${MHMTSCONF}" "$mts_fakesendmail"
53 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
54 MHMTSCONF="$mts_fakesendmail"
55
56 # $1: -mts switch selection
57 # remaining arguments: expected output(s)
58 test_sendmail ()
59 {
60 run_prog send -draft -mts "$1"
61 send_status=$?
62 shift
63
64 # fakesendmail drops the message and any cc's into this mbox.
65 if [ $send_status -eq 0 ]; then
66 mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
67 inc -silent -file "$mbox"
68 rm -f "$mbox"
69 fi
70
71 n=1
72 for expected in "$@"; do
73 #
74 # It's hard to calculate the exact Date: header post is going to
75 # use, so we'll just use sed to remove the actual date so we can easily
76 # compare it against our "correct" output.
77 #
78 sed -e 's/^Date:.*/Date:/' "`mhpath cur`" > "${testname}.actual$n"
79
80 check "${testname}.actual$n" "$expected"
81
82 if [ "`mhpath cur`" != "`mhpath last`" ]; then
83 folder next >/dev/null
84 arith_eval $n + 1; n=$arith_val
85 fi
86 done
87 }
88
89 # check -mts sendmail/smtp
90 start_test '-mts sendmail/smtp'
91 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
92 From: Mr Nobody <nobody@example.com>
93 To: Somebody Else <somebody@example.com>
94 Subject: Test
95
96 This is a test
97 .
98 EOF
99
100 cat > "${testname}.expected" <<EOF
101 From: Mr Nobody <nobody@example.com>
102 To: Somebody Else <somebody@example.com>
103 Subject: Test
104 MIME-Version: 1.0
105 Content-Type: text/plain; charset="us-ascii"
106 Date:
107
108 This is a test
109 ..
110 EOF
111
112 test_sendmail sendmail/smtp "${testname}.expected"
113
114 # check -mts sendmail/pipe
115 # Dots are not stuffed because sendmail/pipe causes sendmail to be
116 # invoked with -i.
117 start_test '-mts sendmail/pipe'
118 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
119 From: Mr Nobody <nobody@example.com>
120 To: Somebody Else <somebody@example.com>
121 Subject: Test
122
123 This is a test
124 .
125 EOF
126
127 cat > "${testname}.expected" <<EOF
128 From: Mr Nobody <nobody@example.com>
129 To: Somebody Else <somebody@example.com>
130 Subject: Test
131 MIME-Version: 1.0
132 Content-Type: text/plain; charset="us-ascii"
133 Date:
134
135 This is a test
136 .
137 EOF
138
139 test_sendmail sendmail/pipe "${testname}.expected"
140
141 # check Bcc with sendmail/pipe
142 start_test 'Bcc with sendmail/pipe'
143 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
144 From: Mr Nobody <nobody@example.com>
145 To: Somebody Else <somebody@example.com>
146 Bcc: Silent Partner <bcc@example.com>
147 Subject: Test
148
149 This is a test
150 .
151 EOF
152
153 cat > "${testname}.expected1" <<EOF
154 From: Mr Nobody <nobody@example.com>
155 To: Somebody Else <somebody@example.com>
156 Subject: Test
157 MIME-Version: 1.0
158 Content-Type: text/plain; charset="us-ascii"
159 Date:
160
161 This is a test
162 .
163 EOF
164
165 cat > "${testname}.expected2" <<EOF
166 From: Mr Nobody <nobody@example.com>
167 Date:
168 Subject: Test
169 BCC: bcc@example.com
170
171 ------- Blind-Carbon-Copy
172
173 From: Mr Nobody <nobody@example.com>
174 To: Somebody Else <somebody@example.com>
175 Subject: Test
176 MIME-Version: 1.0
177 Content-Type: text/plain; charset="us-ascii"
178 Date:
179
180 This is a test
181 .
182
183 ------- End of Blind-Carbon-Copy
184 EOF
185
186 test_sendmail sendmail/pipe "${testname}.expected1" "${testname}.expected2"
187
188
189 # check Dcc with sendmail/pipe: it is unsupported
190 start_test 'Dcc with sendmail/pipe'
191 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
192 From: nobody@example.com
193 Dcc: dcc@example.com
194
195 .
196 EOF
197
198 cat > "${testname}.expected1" <<EOF
199 post: Dcc header is not supported with sendmail/pipe
200 post: re-format message and try again
201 send: message not delivered to anyone
202 EOF
203
204 ! test_sendmail sendmail/pipe 2>"${testname}.actual1"
205 check "${testname}.actual1" "${testname}.expected1"
206
207 rm -f ${MHMTSCONF}
208
209 finish_test
210 exit ${failed:-0}