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/^Resent-Date:.*/Resent-Date:/' \
60 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
63 check "$actual".nodate "$1"
66 expected=$MH_TEST_DIR/test-mhmail$$.expected
67 expected_err=$MH_TEST_DIR/test-mhmail$$.expected_err
68 actual=$MH_TEST_DIR/test-mhmail$$.actual
69 actual_err=$MH_TEST_DIR/test-mhmail$$.actual_err
73 # Verified behavior consistent with compiled sendmail.
75 Usage: mhmail [addrs ... [switches]]
87 and all post(8)/send(1) switches
90 mhmail -help >$actual 2>&1
91 check $expected $actual
95 # Verified same behavior as compiled mhmail.
98 * ) echo "$0: mhmail -v generated unexpected output" 1>&2
99 failed=`expr ${failed:-0} + 1`;;
103 # check with no arguments
104 # That will just run inc, which we don't want to do anything,
105 # so tell inc to just display its version.
106 # Verified same behavior as compiled mhmail.
107 printf "inc: -version\n" >> $MH
110 * ) echo "$0: mhmail generated unexpected output" 1>&2
111 failed=`expr ${failed:-0} + 1`;;
116 # Not supported by compiled mhmail.
117 mhmail -nosend recipient@example.com -from sender@localhost \
118 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
120 tmpfil=`head -1 $actual | sed -e 's/://'`
122 cat > "$expected" <<EOF
123 To: recipient@example.com
124 From: sender@localhost
129 cat > "$expected_err" <<EOF
132 check "$expected" "$actual"
133 check "$expected_err" "$actual_err"
134 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
138 # Not supported by compiled mhmail.
139 cat > "$expected" <<EOF
140 EHLO nosuchhost.example.com
141 MAIL FROM:<sender@localhost>
142 RCPT TO:<recipient@example.com>
144 To: recipient@example.com
145 From: sender@localhost
153 test_mhmail "$expected" "-from sender@localhost -nosend -send" '|' message
154 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
158 # Verified same behavior as compiled mhmail.
159 cat > "$expected" <<EOF
160 EHLO nosuchhost.example.com
161 MAIL FROM:<sender@localhost>
162 RCPT TO:<recipient@example.com>
164 To: recipient@example.com
165 From: sender@localhost
173 test_mhmail "$expected" "-from sender@localhost" '|' message
174 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
177 # check -from and -body
178 # Verified same behavior as compiled mhmail.
179 cat > "$expected" <<EOF
180 EHLO nosuchhost.example.com
181 MAIL FROM:<sender@localhost>
182 RCPT TO:<recipient@example.com>
184 To: recipient@example.com
185 From: sender@localhost
193 test_mhmail "$expected" "-from sender@localhost" -b body
194 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
197 # check -from and -cc
198 # Verified same behavior as compiled mhmail.
199 cat > "$expected" <<EOF
200 EHLO nosuchhost.example.com
201 MAIL FROM:<sender@localhost>
202 RCPT TO:<recipient@example.com>
203 RCPT TO:<recipient2@example.com>
205 To: recipient@example.com
206 Cc: recipient2@example.com
207 From: sender@localhost
215 test_mhmail "$expected" \
216 "-from sender@localhost -cc recipient2@example.com" '|' message
217 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
220 # check -from and multiple -cc addresses
221 # Verified same behavior as compiled mhmail.
222 cat > "$expected" <<EOF
223 EHLO nosuchhost.example.com
224 MAIL FROM:<sender@localhost>
225 RCPT TO:<recipient@example.com>
226 RCPT TO:<recipient2@example.com>
227 RCPT TO:<recipient3@example.com>
228 RCPT TO:<recipient4@example.com>
230 To: recipient@example.com
231 Cc: recipient2@example.com, recipient3@example.com,
232 recipient4@example.com
233 From: sender@localhost
241 test_mhmail "$expected" \
242 '-from sender@localhost -cc recipient2@example.com recipient3@example.com '\
243 'recipient4@example.com' '|' message
244 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
247 # check -from and -subject
248 # Verified same behavior as compiled mhmail.
249 cat > "$expected" <<EOF
250 EHLO nosuchhost.example.com
251 MAIL FROM:<sender@localhost>
252 RCPT TO:<recipient@example.com>
254 To: recipient@example.com
256 From: sender@localhost
264 test_mhmail "$expected" '-from sender@localhost -subject Test' '|' message
265 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
268 # check -from and -profile
269 # Show that -profile causes mhmail to 1) read the profile and
270 # 2) use send(1) by added a send switch to the profile and
271 # verifying that it gets used.
272 # Not supported by compiled mhmail.
273 printf "send: -msgid\n" >> $MH
275 cat > "$expected" <<EOF
276 EHLO nosuchhost.example.com
277 MAIL FROM:<sender@localhost>
278 RCPT TO:<recipient@example.com>
280 To: recipient@example.com
281 From: sender@localhost
290 test_mhmail "$expected" '-from sender@localhost -profile' '|' message
291 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
294 # check repeated -from and -subject arguments
295 # Verified same behavior as compiled mhmail.
296 cat > "$expected" <<EOF
297 EHLO nosuchhost.example.com
298 MAIL FROM:<sender2@localhost>
299 RCPT TO:<recipient@example.com>
301 To: recipient@example.com
303 From: sender2@localhost
311 test_mhmail "$expected" '-from sender@localhost -from sender2@localhost '\
312 '-subject Subject1 -subject Subject2' -b message
313 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
315 # check repeated -body 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>
322 To: recipient@example.com
323 From: sender@localhost
331 test_mhmail "$expected" "-from sender@localhost -body body1" -b body2
332 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
335 # check multiple -cc arguments
336 # Verified same behavior as compiled mhmail.
337 cat > "$expected" <<EOF
338 EHLO nosuchhost.example.com
339 MAIL FROM:<sender@localhost>
340 RCPT TO:<recipient@example.com>
341 RCPT TO:<cc1@example.com>
342 RCPT TO:<cc2@example.com>
344 To: recipient@example.com
345 Cc: cc1@example.com, cc2@example.com
346 From: sender@localhost
354 test_mhmail "$expected" \
355 '-from sender@localhost -cc cc1@example.com -cc cc2@example.com' -b message
356 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
359 # check separated -cc arguments
360 # Verified same behavior as compiled mhmail.
361 cat > "$expected" <<EOF
362 EHLO nosuchhost.example.com
363 MAIL FROM:<sender@localhost>
364 RCPT TO:<recipient@example.com>
365 RCPT TO:<cc1@example.com>
366 RCPT TO:<cc2@example.com>
368 To: recipient@example.com
369 Cc: cc1@example.com, cc2@example.com
371 From: sender@localhost
379 test_mhmail "$expected" \
380 '-from sender@localhost -cc cc1@example.com -subject Test cc2@example.com' \
382 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
385 # check with no newline on stdin
386 # Shows different behavior than compiled mhmail, which was silent in this case.
387 cat > "$expected" <<EOF
390 cat > "$expected_err" <<EOF
391 mhmail: empty message not sent, use -body '' to force.
395 printf '' | mhmail recipient@example.com -server 127.0.0.1 -port $localport \
396 >"$actual" 2>"$actual_err"
399 check "$expected" "$actual"
400 check "$expected_err" "$actual_err"
401 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
404 # check with one newline on stdin
405 # Verified same behavior as compiled mhmail.
406 cat > "$expected" <<EOF
407 EHLO nosuchhost.example.com
408 MAIL FROM:<sender@localhost>
409 RCPT TO:<recipient@example.com>
411 To: recipient@example.com
412 From: sender@localhost
420 test_mhmail "$expected" '-from sender@localhost' '|' '\n'
421 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
424 # check with multiple newlines on stdin
425 # Verified same behavior as compiled mhmail.
426 cat > "$expected" <<EOF
427 EHLO nosuchhost.example.com
428 MAIL FROM:<sender@localhost>
429 RCPT TO:<recipient@example.com>
431 To: recipient@example.com
432 From: sender@localhost
442 test_mhmail "$expected" '-from sender@localhost' '|' '\n\n\n'
443 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
446 # check with text and no trailing newline on stdin
447 # Verified same behavior as compiled mhmail.
448 cat > "$expected" <<EOF
449 EHLO nosuchhost.example.com
450 MAIL FROM:<sender@localhost>
451 RCPT TO:<recipient@example.com>
453 To: recipient@example.com
454 From: sender@localhost
462 test_mhmail "$expected" '-from sender@localhost' '|' 'no newline in input'
463 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
466 # check with text and multiple trailing blank lines on stdin
467 # Verified same behavior as compiled mhmail.
468 cat > "$expected" <<EOF
469 EHLO nosuchhost.example.com
470 MAIL FROM:<sender@localhost>
471 RCPT TO:<recipient@example.com>
473 To: recipient@example.com
474 From: sender@localhost
484 test_mhmail "$expected" '-from sender@localhost' '|' "here's some text\n\n\n"
485 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
488 # check with no newline to -body
489 # Verified same behavior as compiled mhmail.
490 cat > "$expected" <<EOF
491 EHLO nosuchhost.example.com
492 MAIL FROM:<sender@localhost>
493 RCPT TO:<recipient@example.com>
495 To: recipient@example.com
496 From: sender@localhost
504 test_mhmail "$expected" '-from sender@localhost' -b ''
505 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
508 # check with one newline to -body
509 # Shows different behavior than compiled mhmail, which suppressed the newline.
510 cat > "$expected" <<EOF
511 EHLO nosuchhost.example.com
512 MAIL FROM:<sender@localhost>
513 RCPT TO:<recipient@example.com>
515 To: recipient@example.com
516 From: sender@localhost
525 test_mhmail "$expected" '-from sender@localhost' -b '
527 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
530 # check with multiple newlines to -body
531 # Shows different behavior than compiled mhmail, which suppressed one
533 cat > "$expected" <<EOF
534 EHLO nosuchhost.example.com
535 MAIL FROM:<sender@localhost>
536 RCPT TO:<recipient@example.com>
538 To: recipient@example.com
539 From: sender@localhost
550 test_mhmail "$expected" '-from sender@localhost' -b '
554 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
557 # check with text and no trailing newline to -body
558 # Verified same behavior as compiled mhmail.
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
573 test_mhmail "$expected" '-from sender@localhost' -b 'no newline in input'
574 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
577 # check with text and multiple trailing blank lines to -body
578 # Shows different behavior than compiled mhmail, which suppressed one
580 cat > "$expected" <<EOF
581 EHLO nosuchhost.example.com
582 MAIL FROM:<sender@localhost>
583 RCPT TO:<recipient@example.com>
585 To: recipient@example.com
586 From: sender@localhost
596 test_mhmail "$expected" '-from sender@localhost' -b "here's some text
599 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
603 # Verified same behavior as compiled mhmail.
604 cat > "$expected" <<EOF
605 EHLO nosuchhost.example.com
606 MAIL FROM:<recipient@example.com>
607 RCPT TO:<recipient@example.com>
609 Resent-To: recipient@example.com
610 Resent-From: recipient@example.com
611 To: recipient@example.com
612 From: sender@localhost
616 please resend this message, #1
621 test_mhmail "$expected" '-from recipient@example.com -resent' \
622 -b 'To: recipient@example.com
623 From: sender@localhost
624 Date: Sat Jun 16 18:35:15 -0500
626 please resend this message, #1'
628 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
630 # check -resent -profile, using stdin
631 # Not supported by compiled mhmail.
632 cat > "$expected" <<EOF
633 EHLO nosuchhost.example.com
634 MAIL FROM:<recipient@example.com>
635 RCPT TO:<recipient@example.com>
637 To: recipient@example.com
638 From: sender@localhost
640 Resent-To: recipient@example.com
641 Resent-From: recipient@example.com
644 please resend this message, #2
649 test_mhmail "$expected" \
650 '-from recipient@example.com -resent -profile -nomsgid' \
651 '|' 'To: recipient@example.com
652 From: sender@localhost
653 Date: Sat Jun 16 18:35:15 -0500
655 please resend this message, #2'
657 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
660 # check -resent -profile, using -b
661 # Not supported by compiled mhmail.
662 cat > "$expected" <<EOF
663 EHLO nosuchhost.example.com
664 MAIL FROM:<recipient@example.com>
665 RCPT TO:<recipient@example.com>
667 To: recipient@example.com
668 From: sender@localhost
670 Resent-To: recipient@example.com
671 Resent-From: recipient@example.com
674 please resend this message, #3
679 test_mhmail "$expected" \
680 '-from recipient@example.com -resent -profile -nomsgid' \
681 -b 'To: recipient@example.com
682 From: sender@localhost
683 Date: Sat Jun 16 18:35:15 -0500
685 please resend this message, #3'
687 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}