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