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 the message body.
24 "${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport &
27 # The server doesn't always come up fast enough, so sleep and
28 # retry a few times if it fails...
30 for i in 0 1 2 3 4 5 6 7 8 9; do
32 if printf '%s' "$4" | mhmail recipient@example.com $2 \
33 -server 127.0.0.1 -port $localport; then
38 if mhmail recipient@example.com $2 -body "$4" \
39 -server 127.0.0.1 -port $localport; then
46 [ $status -eq 0 ] || exit 1
51 # It's hard to calculate the exact Date: header post is going to
52 # use, so we'll just use sed to remove the actual date so we can easily
53 # compare it against our "correct" output. And same for
57 sed -e 's/^Date:.*/Date:/' \
58 -e 's/^Resent-Date:.*/Resent-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 [-t(o)] addrs ... [switches]
76 -at(tach) file [-at(tach) file] ...
80 -hea(derfield) name:value [-hea(derfield) name:value] ...
88 and all post(8)/send(1) switches
89 mhmail with no arguments is equivalent to inc
92 mhmail -help >$actual 2>&1
93 check $expected $actual
97 # Verified same behavior as compiled mhmail.
100 * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2
101 failed=`expr ${failed:-0} + 1`;;
104 # check for missing argument to switches that require them
105 for switch in attach body cc from headerfield subject to; do
106 run_test "mhmail recipient -$switch" \
107 "mhmail: missing argument to -$switch"
109 for switch in attach body cc from headerfield subject to; do
110 run_test "mhmail recipient -$switch -nosend" \
111 "mhmail: missing argument to -$switch"
113 for switch in attach body cc from headerfield subject to; do
114 run_test "mhmail recipient -$switch -server 127.0.0.1" \
115 "mhmail: missing argument to -$switch"
119 # check with no switches
120 # That will just run inc, which we don't want to do anything,
121 # so tell inc to just display its version.
122 # Verified same behavior as compiled mhmail.
123 printf 'inc: -version\n' >> $MH
126 * ) echo "$0: mhmail generated unexpected output" 1>&2
127 failed=`expr ${failed:-0} + 1`;;
132 # Not supported by compiled mhmail.
133 mhmail -nosend recipient@example.com -from sender@localhost \
134 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
136 tmpfil=`head -1 $actual | sed -e 's/://'`
138 cat > "$expected" <<EOF
139 To: recipient@example.com
140 From: sender@localhost
145 cat > "$expected_err" <<EOF
148 check "$expected" "$actual"
149 check "$expected_err" "$actual_err"
150 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
154 # Not supported by compiled mhmail.
155 cat > "$expected" <<EOF
156 EHLO nosuchhost.example.com
157 MAIL FROM:<sender@localhost>
158 RCPT TO:<recipient@example.com>
160 To: recipient@example.com
161 From: sender@localhost
169 test_mhmail "$expected" "-from sender@localhost -nosend -send" '|' message
170 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
174 # Verified same behavior as compiled mhmail.
175 cat > "$expected" <<EOF
176 EHLO nosuchhost.example.com
177 MAIL FROM:<sender@localhost>
178 RCPT TO:<recipient@example.com>
180 To: recipient@example.com
181 From: sender@localhost
189 test_mhmail "$expected" "-from sender@localhost" '|' message
190 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
193 # check -from and -body
194 # Verified same behavior as compiled mhmail.
195 cat > "$expected" <<EOF
196 EHLO nosuchhost.example.com
197 MAIL FROM:<sender@localhost>
198 RCPT TO:<recipient@example.com>
200 To: recipient@example.com
201 From: sender@localhost
209 test_mhmail "$expected" "-from sender@localhost" -b body
210 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
213 # check -from and -cc
214 # Verified same behavior as compiled mhmail.
215 cat > "$expected" <<EOF
216 EHLO nosuchhost.example.com
217 MAIL FROM:<sender@localhost>
218 RCPT TO:<recipient@example.com>
219 RCPT TO:<recipient2@example.com>
221 To: recipient@example.com
222 Cc: recipient2@example.com
223 From: sender@localhost
231 test_mhmail "$expected" \
232 "-from sender@localhost -cc recipient2@example.com" '|' message
233 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
236 # check -from and multiple -cc addresses
237 # Verified same behavior as compiled mhmail.
238 cat > "$expected" <<EOF
239 EHLO nosuchhost.example.com
240 MAIL FROM:<sender@localhost>
241 RCPT TO:<recipient@example.com>
242 RCPT TO:<recipient2@example.com>
243 RCPT TO:<recipient3@example.com>
244 RCPT TO:<recipient4@example.com>
246 To: recipient@example.com
247 Cc: recipient2@example.com, recipient3@example.com,
248 recipient4@example.com
249 From: sender@localhost
257 test_mhmail "$expected" \
258 '-from sender@localhost -cc recipient2@example.com recipient3@example.com '\
259 'recipient4@example.com' '|' message
260 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
263 # check -from and -subject
264 # Verified same behavior as compiled mhmail.
265 cat > "$expected" <<EOF
266 EHLO nosuchhost.example.com
267 MAIL FROM:<sender@localhost>
268 RCPT TO:<recipient@example.com>
270 To: recipient@example.com
272 From: sender@localhost
280 test_mhmail "$expected" '-from sender@localhost -subject Test' '|' message
281 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
284 # check -from and -profile
285 # Show that -profile causes mhmail to 1) read the profile and
286 # 2) use send(1) by added a send switch to the profile and
287 # verifying that it gets used.
288 # Not supported by compiled mhmail.
289 printf 'send: -msgid\n' >> $MH
291 cat > "$expected" <<EOF
292 EHLO nosuchhost.example.com
293 MAIL FROM:<sender@localhost>
294 RCPT TO:<recipient@example.com>
296 To: recipient@example.com
297 From: sender@localhost
306 test_mhmail "$expected" '-from sender@localhost -profile' '|' message
307 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
310 # check repeated -from and -subject switches
311 # Verified same behavior as compiled mhmail.
312 cat > "$expected" <<EOF
313 EHLO nosuchhost.example.com
314 MAIL FROM:<sender2@localhost>
315 RCPT TO:<recipient@example.com>
317 To: recipient@example.com
319 From: sender2@localhost
327 test_mhmail "$expected" '-from sender@localhost -from sender2@localhost '\
328 '-subject Subject1 -subject Subject2' -b message
329 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
331 # check repeated -body switches
332 # Verified same behavior as compiled mhmail.
333 cat > "$expected" <<EOF
334 EHLO nosuchhost.example.com
335 MAIL FROM:<sender@localhost>
336 RCPT TO:<recipient@example.com>
338 To: recipient@example.com
339 From: sender@localhost
347 test_mhmail "$expected" "-from sender@localhost -body body1" -b body2
348 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
351 # check multiple -cc switches
352 # Verified same behavior as compiled mhmail.
353 cat > "$expected" <<EOF
354 EHLO nosuchhost.example.com
355 MAIL FROM:<sender@localhost>
356 RCPT TO:<recipient@example.com>
357 RCPT TO:<cc1@example.com>
358 RCPT TO:<cc2@example.com>
360 To: recipient@example.com
361 Cc: cc1@example.com, cc2@example.com
362 From: sender@localhost
370 test_mhmail "$expected" \
371 '-from sender@localhost -cc cc1@example.com -cc cc2@example.com' -b message
372 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
375 # check separated -cc arguments
376 # Verified same behavior as compiled mhmail.
377 cat > "$expected" <<EOF
378 EHLO nosuchhost.example.com
379 MAIL FROM:<sender@localhost>
380 RCPT TO:<recipient@example.com>
381 RCPT TO:<cc1@example.com>
382 RCPT TO:<cc2@example.com>
384 To: recipient@example.com
385 Cc: cc1@example.com, cc2@example.com
387 From: sender@localhost
395 test_mhmail "$expected" \
396 '-from sender@localhost -cc cc1@example.com -subject Test cc2@example.com' \
398 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
401 # check -cc switch followed by -to switch
402 # Verified same behavior as compiled mhmail.
403 cat > "$expected" <<EOF
404 EHLO nosuchhost.example.com
405 MAIL FROM:<sender@localhost>
406 RCPT TO:<recipient@example.com>
407 RCPT TO:<recipient2@example.com>
408 RCPT TO:<cc1@example.com>
410 To: recipient@example.com, recipient2@example.com
413 From: sender@localhost
421 test_mhmail "$expected" \
422 "-from sender@localhost -cc cc1@example.com -subject Test \
423 -to recipient2@example.com" \
425 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
428 # check with no newline on stdin
429 # Shows different behavior than compiled mhmail, which was silent in this case.
430 cat > "$expected" <<EOF
433 cat > "$expected_err" <<EOF
434 mhmail: empty message not sent, use -body '' to force.
438 printf '' | mhmail recipient@example.com -server 127.0.0.1 -port $localport \
439 >"$actual" 2>"$actual_err"
442 check "$expected" "$actual"
443 check "$expected_err" "$actual_err"
444 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
447 # check with one newline on stdin
448 # Verified same behavior as compiled mhmail.
449 cat > "$expected" <<EOF
450 EHLO nosuchhost.example.com
451 MAIL FROM:<sender@localhost>
452 RCPT TO:<recipient@example.com>
454 To: recipient@example.com
455 From: sender@localhost
463 test_mhmail "$expected" '-from sender@localhost' '|' '
465 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
468 # check with multiple newlines on stdin
469 # Verified same behavior as compiled mhmail.
470 cat > "$expected" <<EOF
471 EHLO nosuchhost.example.com
472 MAIL FROM:<sender@localhost>
473 RCPT TO:<recipient@example.com>
475 To: recipient@example.com
476 From: sender@localhost
486 test_mhmail "$expected" '-from sender@localhost' '|' '
490 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
493 # check with text and no trailing newline on stdin
494 # Verified same behavior as compiled mhmail.
495 cat > "$expected" <<EOF
496 EHLO nosuchhost.example.com
497 MAIL FROM:<sender@localhost>
498 RCPT TO:<recipient@example.com>
500 To: recipient@example.com
501 From: sender@localhost
509 test_mhmail "$expected" '-from sender@localhost' '|' 'no newline in input'
510 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
513 # check with text and multiple trailing blank lines on stdin
514 # Verified same behavior as compiled mhmail.
515 cat > "$expected" <<EOF
516 EHLO nosuchhost.example.com
517 MAIL FROM:<sender@localhost>
518 RCPT TO:<recipient@example.com>
520 To: recipient@example.com
521 From: sender@localhost
531 test_mhmail "$expected" '-from sender@localhost' '|' "here's some text
535 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
538 # check with no newline to -body
539 # Verified same behavior as compiled mhmail.
540 cat > "$expected" <<EOF
541 EHLO nosuchhost.example.com
542 MAIL FROM:<sender@localhost>
543 RCPT TO:<recipient@example.com>
545 To: recipient@example.com
546 From: sender@localhost
554 test_mhmail "$expected" '-from sender@localhost' -b ''
555 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
558 # check with one newline to -body
559 # Shows different behavior than compiled mhmail, which suppressed the newline.
560 cat > "$expected" <<EOF
561 EHLO nosuchhost.example.com
562 MAIL FROM:<sender@localhost>
563 RCPT TO:<recipient@example.com>
565 To: recipient@example.com
566 From: sender@localhost
575 test_mhmail "$expected" '-from sender@localhost' -b '
577 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
580 # check with multiple newlines to -body
581 # Shows different behavior than compiled mhmail, which suppressed one
583 cat > "$expected" <<EOF
584 EHLO nosuchhost.example.com
585 MAIL FROM:<sender@localhost>
586 RCPT TO:<recipient@example.com>
588 To: recipient@example.com
589 From: sender@localhost
600 test_mhmail "$expected" '-from sender@localhost' -b '
604 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
607 # check with text and no trailing newline to -body
608 # Verified same behavior as compiled mhmail.
609 cat > "$expected" <<EOF
610 EHLO nosuchhost.example.com
611 MAIL FROM:<sender@localhost>
612 RCPT TO:<recipient@example.com>
614 To: recipient@example.com
615 From: sender@localhost
623 test_mhmail "$expected" '-from sender@localhost' -b 'no newline in input'
624 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
627 # check with text and multiple trailing blank lines to -body
628 # Shows different behavior than compiled mhmail, which suppressed one
630 cat > "$expected" <<EOF
631 EHLO nosuchhost.example.com
632 MAIL FROM:<sender@localhost>
633 RCPT TO:<recipient@example.com>
635 To: recipient@example.com
636 From: sender@localhost
646 test_mhmail "$expected" '-from sender@localhost' -b "here's some text
649 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
653 # Verified same behavior as compiled mhmail.
654 cat > "$expected" <<EOF
655 EHLO nosuchhost.example.com
656 MAIL FROM:<orig_recipient@example.com>
657 RCPT TO:<recipient@example.com>
659 Resent-To: recipient@example.com
660 Resent-From: orig_recipient@example.com
661 To: recipient@example.com
662 From: sender@localhost
666 please resend this message, 1
671 test_mhmail "$expected" '-from orig_recipient@example.com -resent' \
672 -b 'To: recipient@example.com
673 From: sender@localhost
674 Date: Sat Jun 16 18:35:15 -0500
676 please resend this message, 1'
678 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
680 # check -resent -profile, using stdin
681 # Not supported by compiled mhmail.
682 cat > "$expected" <<EOF
683 EHLO nosuchhost.example.com
684 MAIL FROM:<orig_recipient@example.com>
685 RCPT TO:<recipient@example.com>
687 To: recipient@example.com
688 From: sender@localhost
690 Resent-To: recipient@example.com
691 Resent-From: orig_recipient@example.com
694 please resend this message, 2
699 test_mhmail "$expected" \
700 '-from orig_recipient@example.com -resent -profile -nomsgid' \
701 '|' 'To: recipient@example.com
702 From: sender@localhost
703 Date: Sat Jun 16 18:35:15 -0500
705 please resend this message, 2'
707 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
710 # check -resent -profile, using -b
711 # Not supported by compiled mhmail.
712 cat > "$expected" <<EOF
713 EHLO nosuchhost.example.com
714 MAIL FROM:<orig_recipient@example.com>
715 RCPT TO:<recipient@example.com>
717 To: recipient@example.com
718 From: sender@localhost
720 Resent-To: recipient@example.com
721 Resent-From: orig_recipient@example.com
724 please resend this message, 3
729 test_mhmail "$expected" \
730 '-from orig_recipient@example.com -resent -profile -nomsgid' \
731 -b 'To: recipient@example.com
732 From: sender@localhost
733 Date: Sat Jun 16 18:35:15 -0500
735 please resend this message, 3'
737 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
740 # check -headerfield.
741 # Not supported by compiled mhmail.
742 cat > "$expected" <<EOF
743 EHLO nosuchhost.example.com
744 MAIL FROM:<sender@example.com>
745 RCPT TO:<recipient@example.com>
747 To: recipient@example.com
748 From: sender@example.com
752 with added header field
757 test_mhmail "$expected" \
758 '-from sender@example.com -headerfield User-Agent:nmh' \
759 -b 'with added header field'
761 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
764 # check multiple -headerfields.
765 # Not supported by compiled mhmail.
766 cat > "$expected" <<EOF
767 EHLO nosuchhost.example.com
768 MAIL FROM:<sender@example.com>
769 RCPT TO:<recipient@example.com>
771 To: recipient@example.com
772 From: sender@example.com
774 Content-Type: text/plain;charset=utf-8
775 Content-Transfer-Encoding: 8bit
778 with added header fields
783 test_mhmail "$expected" \
784 "-from sender@example.com -headerfield MIME-Version:1.0 \
785 -headerfield Content-Type:text/plain;charset=utf-8 \
786 -headerfield Content-Transfer-Encoding:8bit" \
787 -b 'with added header fields'
789 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
793 # Not supported by compiled mhmail.
794 cat > "$expected" <<EOF
795 EHLO nosuchhost.example.com
796 MAIL FROM:<sender@example.com>
797 RCPT TO:<recipient@example.com>
799 To: recipient@example.com
800 From: sender@example.com
802 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
806 ------- =_aaaaaaaaaa0
807 Content-Type: text/plain; charset="us-ascii"
809 See how easy it is to add an attachment!
811 ------- =_aaaaaaaaaa0
812 Content-Type: text/plain; name="attachment.txt"; charset="us-ascii"
813 Content-Description: attachment.txt
814 Content-Disposition: attachment; filename="attachment.txt"
816 The future disappears into memory, With only a moment between,
817 Forever dwells in that moment, hope is what remains to be seen
818 Forever dwells in that moment, hope is what remains to be seen.
820 ------- =_aaaaaaaaaa0--
825 test_mhmail "$expected" \
826 "-from sender@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
827 -b 'See how easy it is to add an attachment!'
829 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}