2 ######################################################
6 ######################################################
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirname $0`/../..
12 MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
15 . "${srcdir}/test/post/test-post-common.sh"
17 # Customize test_post () for use with mhmail.
18 # $1 is expected output file, provided by caller
19 # $2 is mhmail switches, except for -body
20 # $3 of -b signifies use -body switch, | signifies provide body on stdin
21 # $4 contains message body. When using stdin, can contain printf(1) format
25 "${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport &
28 # The server doesn't always come up fast enough, so sleep and
29 # retry a few times if it fails...
31 for i in 0 1 2 3 4 5 6 7 8 9; do
33 if printf "$4" | mhmail recipient@example.com $2 \
34 -server 127.0.0.1 -port $localport; then
39 if mhmail recipient@example.com $2 -body "$4" \
40 -server 127.0.0.1 -port $localport; then
47 [ $status -eq 0 ] || exit 1
52 # It's hard to calculate the exact Date: header post is going to
53 # use, so we'll just use sed to remove the actual date so we can easily
54 # compare it against our "correct" output. And same for
58 sed -e 's/^Date:.*/Date:/' \
59 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
62 check "$actual".nodate "$1"
65 expected=$MH_TEST_DIR/test-mhmail$$.expected
66 expected_err=$MH_TEST_DIR/test-mhmail$$.expected_err
67 actual=$MH_TEST_DIR/test-mhmail$$.actual
68 actual_err=$MH_TEST_DIR/test-mhmail$$.actual_err
72 # Verified behavior consistent with compiled sendmail.
74 Usage: mhmail [addrs ... [switches]]
84 and all post(8)/send(1) switches
87 mhmail -help >$actual 2>&1
88 check $expected $actual
92 # Verified same behavior as compiled mhmail.
95 * ) echo "$0: mhmail -v generated unexpected output" 1>&2
96 failed=`expr ${failed:-0} + 1`;;
100 # check with no arguments
101 # That will just run inc, which we don't want to do anything,
102 # so tell inc to just display its version.
103 # Verified same behavior as compiled mhmail.
104 printf "inc: -version\n" >> $MH
107 * ) echo "$0: mhmail generated unexpected output" 1>&2
108 failed=`expr ${failed:-0} + 1`;;
113 # Not supported by compiled mhmail.
114 mhmail -debug recipient@example.com -from sender@localhost \
115 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
117 tmpfil=`head -1 $actual | sed -e 's/://'`
119 cat > "$expected" <<EOF
121 To: recipient@example.com
122 From: sender@localhost
125 $MH_INST_DIR$auxexecdir/post ${tmpfil} -server 127.0.0.1 -port $localport
128 cat > "$expected_err" <<EOF
131 check "$expected" "$actual"
132 check "$expected_err" "$actual_err"
133 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
137 # Verified same behavior as compiled mhmail.
138 cat > "$expected" <<EOF
139 EHLO nosuchhost.example.com
140 MAIL FROM:<sender@localhost>
141 RCPT TO:<recipient@example.com>
143 To: recipient@example.com
144 From: sender@localhost
152 test_mhmail "$expected" "-from sender@localhost" '|' message
153 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
156 # check -from and -body
157 # Verified same behavior as compiled mhmail.
158 cat > "$expected" <<EOF
159 EHLO nosuchhost.example.com
160 MAIL FROM:<sender@localhost>
161 RCPT TO:<recipient@example.com>
163 To: recipient@example.com
164 From: sender@localhost
172 test_mhmail "$expected" "-from sender@localhost" -b body
173 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
176 # check -from and -cc
177 # Verified same behavior as compiled mhmail.
178 cat > "$expected" <<EOF
179 EHLO nosuchhost.example.com
180 MAIL FROM:<sender@localhost>
181 RCPT TO:<recipient@example.com>
182 RCPT TO:<recipient2@example.com>
184 To: recipient@example.com
185 Cc: recipient2@example.com
186 From: sender@localhost
194 test_mhmail "$expected" \
195 "-from sender@localhost -cc recipient2@example.com" '|' message
196 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
199 # check -from and multiple -cc addresses
200 # Verified same behavior as compiled mhmail.
201 cat > "$expected" <<EOF
202 EHLO nosuchhost.example.com
203 MAIL FROM:<sender@localhost>
204 RCPT TO:<recipient@example.com>
205 RCPT TO:<recipient2@example.com>
206 RCPT TO:<recipient3@example.com>
207 RCPT TO:<recipient4@example.com>
209 To: recipient@example.com
210 Cc: recipient2@example.com, recipient3@example.com,
211 recipient4@example.com
212 From: sender@localhost
220 test_mhmail "$expected" \
221 "-from sender@localhost -cc recipient2@example.com recipient3@example.com recipient4@example.com" '|' message
222 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
225 # check -from and -subject
226 # Verified same behavior as compiled mhmail.
227 cat > "$expected" <<EOF
228 EHLO nosuchhost.example.com
229 MAIL FROM:<sender@localhost>
230 RCPT TO:<recipient@example.com>
232 To: recipient@example.com
234 From: sender@localhost
242 test_mhmail "$expected" \
243 "-from sender@localhost -subject Test" '|' message
244 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
247 # check -from and -profile
248 # Show that -profile causes mhmail to 1) read the profile and
249 # 2) use send(1) by added a send switch to the profile and
250 # verifying that it gets used.
251 # Not supported by compiled mhmail.
252 printf "send: -msgid\n" >> $MH
254 cat > "$expected" <<EOF
255 EHLO nosuchhost.example.com
256 MAIL FROM:<sender@localhost>
257 RCPT TO:<recipient@example.com>
259 To: recipient@example.com
260 From: sender@localhost
269 test_mhmail "$expected" \
270 "-from sender@localhost -profile" '|' message
271 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
274 # check repeated -from and -subject arguments
275 # Verified same behavior as compiled mhmail.
276 cat > "$expected" <<EOF
277 EHLO nosuchhost.example.com
278 MAIL FROM:<sender2@localhost>
279 RCPT TO:<recipient@example.com>
281 To: recipient@example.com
283 From: sender2@localhost
291 test_mhmail "$expected" "-from sender@localhost -from sender2@localhost \
292 -subject Subject1 -subject Subject2" -b message
293 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
295 # check repeated -body arguments
296 # Verified same behavior as compiled mhmail.
297 cat > "$expected" <<EOF
298 EHLO nosuchhost.example.com
299 MAIL FROM:<sender@localhost>
300 RCPT TO:<recipient@example.com>
302 To: recipient@example.com
303 From: sender@localhost
311 test_mhmail "$expected" "-from sender@localhost -body body1" -b body2
312 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
315 # check multiple -cc arguments
316 # Verified same behavior as compiled mhmail.
317 cat > "$expected" <<EOF
318 EHLO nosuchhost.example.com
319 MAIL FROM:<sender@localhost>
320 RCPT TO:<recipient@example.com>
321 RCPT TO:<cc1@example.com>
322 RCPT TO:<cc2@example.com>
324 To: recipient@example.com
325 Cc: cc1@example.com, cc2@example.com
326 From: sender@localhost
334 test_mhmail "$expected" "-from sender@localhost \
335 -cc cc1@example.com -cc cc2@example.com" -b message
336 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
339 # check separated -cc arguments
340 # Verified same behavior as compiled mhmail.
341 cat > "$expected" <<EOF
342 EHLO nosuchhost.example.com
343 MAIL FROM:<sender@localhost>
344 RCPT TO:<recipient@example.com>
345 RCPT TO:<cc1@example.com>
346 RCPT TO:<cc2@example.com>
348 To: recipient@example.com
349 Cc: cc1@example.com, cc2@example.com
351 From: sender@localhost
359 test_mhmail "$expected" "-from sender@localhost \
360 -cc cc1@example.com -subject Test cc2@example.com" -b message
361 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
364 # check with no newline on stdin
365 # Shows different behavior than compiled mhmail, which was silent in this case.
366 cat > "$expected" <<EOF
369 cat > "$expected_err" <<EOF
370 mhmail: empty message not sent, use -body '' to force.
374 printf '' | mhmail recipient@example.com -server 127.0.0.1 -port $localport \
375 >"$actual" 2>"$actual_err"
378 check "$expected" "$actual"
379 check "$expected_err" "$actual_err"
380 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
383 # check with one newline on stdin
384 # Verified same behavior as compiled mhmail.
385 cat > "$expected" <<EOF
386 EHLO nosuchhost.example.com
387 MAIL FROM:<sender@localhost>
388 RCPT TO:<recipient@example.com>
390 To: recipient@example.com
391 From: sender@localhost
399 test_mhmail "$expected" "-from sender@localhost" '|' '\n'
400 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
403 # check with multiple newlines on stdin
404 # Verified same behavior as compiled mhmail.
405 cat > "$expected" <<EOF
406 EHLO nosuchhost.example.com
407 MAIL FROM:<sender@localhost>
408 RCPT TO:<recipient@example.com>
410 To: recipient@example.com
411 From: sender@localhost
421 test_mhmail "$expected" "-from sender@localhost" '|' '\n\n\n'
422 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
425 # check with text and no trailing newline on stdin
426 # Verified same behavior as compiled mhmail.
427 cat > "$expected" <<EOF
428 EHLO nosuchhost.example.com
429 MAIL FROM:<sender@localhost>
430 RCPT TO:<recipient@example.com>
432 To: recipient@example.com
433 From: sender@localhost
441 test_mhmail "$expected" "-from sender@localhost" '|' 'no newline in input'
442 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
445 # check with text and multiple trailing blank lines on stdin
446 # Verified same behavior as compiled mhmail.
447 cat > "$expected" <<EOF
448 EHLO nosuchhost.example.com
449 MAIL FROM:<sender@localhost>
450 RCPT TO:<recipient@example.com>
452 To: recipient@example.com
453 From: sender@localhost
463 test_mhmail "$expected" "-from sender@localhost" '|' "here's some text\n\n\n"
464 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
467 # check with no newline to -body
468 # Verified same behavior as compiled mhmail.
469 cat > "$expected" <<EOF
470 EHLO nosuchhost.example.com
471 MAIL FROM:<sender@localhost>
472 RCPT TO:<recipient@example.com>
474 To: recipient@example.com
475 From: sender@localhost
483 test_mhmail "$expected" "-from sender@localhost" -b ''
484 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
487 # check with one newline to -body
488 # Shows different behavior than compiled mhmail, which suppressed the newline.
489 cat > "$expected" <<EOF
490 EHLO nosuchhost.example.com
491 MAIL FROM:<sender@localhost>
492 RCPT TO:<recipient@example.com>
494 To: recipient@example.com
495 From: sender@localhost
504 test_mhmail "$expected" "-from sender@localhost" -b '
506 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
509 # check with multiple newlines to -body
510 # Shows different behavior than compiled mhmail, which suppressed one
512 cat > "$expected" <<EOF
513 EHLO nosuchhost.example.com
514 MAIL FROM:<sender@localhost>
515 RCPT TO:<recipient@example.com>
517 To: recipient@example.com
518 From: sender@localhost
529 test_mhmail "$expected" "-from sender@localhost" -b '
533 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
536 # check with text and no trailing newline to -body
537 # Verified same behavior as compiled mhmail.
538 cat > "$expected" <<EOF
539 EHLO nosuchhost.example.com
540 MAIL FROM:<sender@localhost>
541 RCPT TO:<recipient@example.com>
543 To: recipient@example.com
544 From: sender@localhost
552 test_mhmail "$expected" "-from sender@localhost" -b 'no newline in input'
553 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
556 # check with text and multiple trailing blank lines to -body
557 # Shows different behavior than compiled mhmail, which suppressed one
559 cat > "$expected" <<EOF
560 EHLO nosuchhost.example.com
561 MAIL FROM:<sender@localhost>
562 RCPT TO:<recipient@example.com>
564 To: recipient@example.com
565 From: sender@localhost
575 test_mhmail "$expected" "-from sender@localhost" -b "here's some text
578 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}