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 [-t(o)] addrs ... [switches]
77 -at(tach) file [-at(tach) file] ...
81 -hea(derfield) name:value [-hea(derfield) name:value] ...
89 and all post(8)/send(1) switches
90 mhmail with no arguments is equivalent to inc
93 mhmail -help >$actual 2>&1
94 check $expected $actual
98 # Verified same behavior as compiled mhmail.
101 * ) echo "$0: mhmail -v generated unexpected output" 1>&2
102 failed=`expr ${failed:-0} + 1`;;
105 # check for missing argument to switches that require them
106 for switch in attach body cc from headerfield subject to; do
107 run_test "mhmail recipient -$switch" \
108 "mhmail: missing argument to -$switch"
110 for switch in attach body cc from headerfield subject to; do
111 run_test "mhmail recipient -$switch -nosend" \
112 "mhmail: missing argument to -$switch"
114 for switch in attach body cc from headerfield subject to; do
115 run_test "mhmail recipient -$switch -server 127.0.0.1" \
116 "mhmail: missing argument to -$switch"
120 # check with no switches
121 # That will just run inc, which we don't want to do anything,
122 # so tell inc to just display its version.
123 # Verified same behavior as compiled mhmail.
124 printf "inc: -version\n" >> $MH
127 * ) echo "$0: mhmail generated unexpected output" 1>&2
128 failed=`expr ${failed:-0} + 1`;;
133 # Not supported by compiled mhmail.
134 mhmail -nosend recipient@example.com -from sender@localhost \
135 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
137 tmpfil=`head -1 $actual | sed -e 's/://'`
139 cat > "$expected" <<EOF
140 To: recipient@example.com
141 From: sender@localhost
146 cat > "$expected_err" <<EOF
149 check "$expected" "$actual"
150 check "$expected_err" "$actual_err"
151 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
155 # Not supported by compiled mhmail.
156 cat > "$expected" <<EOF
157 EHLO nosuchhost.example.com
158 MAIL FROM:<sender@localhost>
159 RCPT TO:<recipient@example.com>
161 To: recipient@example.com
162 From: sender@localhost
170 test_mhmail "$expected" "-from sender@localhost -nosend -send" '|' message
171 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
175 # Verified same behavior as compiled mhmail.
176 cat > "$expected" <<EOF
177 EHLO nosuchhost.example.com
178 MAIL FROM:<sender@localhost>
179 RCPT TO:<recipient@example.com>
181 To: recipient@example.com
182 From: sender@localhost
190 test_mhmail "$expected" "-from sender@localhost" '|' message
191 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
194 # check -from and -body
195 # Verified same behavior as compiled mhmail.
196 cat > "$expected" <<EOF
197 EHLO nosuchhost.example.com
198 MAIL FROM:<sender@localhost>
199 RCPT TO:<recipient@example.com>
201 To: recipient@example.com
202 From: sender@localhost
210 test_mhmail "$expected" "-from sender@localhost" -b body
211 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
214 # check -from and -cc
215 # Verified same behavior as compiled mhmail.
216 cat > "$expected" <<EOF
217 EHLO nosuchhost.example.com
218 MAIL FROM:<sender@localhost>
219 RCPT TO:<recipient@example.com>
220 RCPT TO:<recipient2@example.com>
222 To: recipient@example.com
223 Cc: recipient2@example.com
224 From: sender@localhost
232 test_mhmail "$expected" \
233 "-from sender@localhost -cc recipient2@example.com" '|' message
234 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
237 # check -from and multiple -cc addresses
238 # Verified same behavior as compiled mhmail.
239 cat > "$expected" <<EOF
240 EHLO nosuchhost.example.com
241 MAIL FROM:<sender@localhost>
242 RCPT TO:<recipient@example.com>
243 RCPT TO:<recipient2@example.com>
244 RCPT TO:<recipient3@example.com>
245 RCPT TO:<recipient4@example.com>
247 To: recipient@example.com
248 Cc: recipient2@example.com, recipient3@example.com,
249 recipient4@example.com
250 From: sender@localhost
258 test_mhmail "$expected" \
259 '-from sender@localhost -cc recipient2@example.com recipient3@example.com '\
260 'recipient4@example.com' '|' message
261 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
264 # check -from and -subject
265 # Verified same behavior as compiled mhmail.
266 cat > "$expected" <<EOF
267 EHLO nosuchhost.example.com
268 MAIL FROM:<sender@localhost>
269 RCPT TO:<recipient@example.com>
271 To: recipient@example.com
273 From: sender@localhost
281 test_mhmail "$expected" '-from sender@localhost -subject Test' '|' message
282 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
285 # check -from and -profile
286 # Show that -profile causes mhmail to 1) read the profile and
287 # 2) use send(1) by added a send switch to the profile and
288 # verifying that it gets used.
289 # Not supported by compiled mhmail.
290 printf "send: -msgid\n" >> $MH
292 cat > "$expected" <<EOF
293 EHLO nosuchhost.example.com
294 MAIL FROM:<sender@localhost>
295 RCPT TO:<recipient@example.com>
297 To: recipient@example.com
298 From: sender@localhost
307 test_mhmail "$expected" '-from sender@localhost -profile' '|' message
308 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
311 # check repeated -from and -subject switches
312 # Verified same behavior as compiled mhmail.
313 cat > "$expected" <<EOF
314 EHLO nosuchhost.example.com
315 MAIL FROM:<sender2@localhost>
316 RCPT TO:<recipient@example.com>
318 To: recipient@example.com
320 From: sender2@localhost
328 test_mhmail "$expected" '-from sender@localhost -from sender2@localhost '\
329 '-subject Subject1 -subject Subject2' -b message
330 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
332 # check repeated -body switches
333 # Verified same behavior as compiled mhmail.
334 cat > "$expected" <<EOF
335 EHLO nosuchhost.example.com
336 MAIL FROM:<sender@localhost>
337 RCPT TO:<recipient@example.com>
339 To: recipient@example.com
340 From: sender@localhost
348 test_mhmail "$expected" "-from sender@localhost -body body1" -b body2
349 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
352 # check multiple -cc switches
353 # Verified same behavior as compiled mhmail.
354 cat > "$expected" <<EOF
355 EHLO nosuchhost.example.com
356 MAIL FROM:<sender@localhost>
357 RCPT TO:<recipient@example.com>
358 RCPT TO:<cc1@example.com>
359 RCPT TO:<cc2@example.com>
361 To: recipient@example.com
362 Cc: cc1@example.com, cc2@example.com
363 From: sender@localhost
371 test_mhmail "$expected" \
372 '-from sender@localhost -cc cc1@example.com -cc cc2@example.com' -b message
373 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
376 # check separated -cc arguments
377 # Verified same behavior as compiled mhmail.
378 cat > "$expected" <<EOF
379 EHLO nosuchhost.example.com
380 MAIL FROM:<sender@localhost>
381 RCPT TO:<recipient@example.com>
382 RCPT TO:<cc1@example.com>
383 RCPT TO:<cc2@example.com>
385 To: recipient@example.com
386 Cc: cc1@example.com, cc2@example.com
388 From: sender@localhost
396 test_mhmail "$expected" \
397 '-from sender@localhost -cc cc1@example.com -subject Test cc2@example.com' \
399 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
402 # check -cc switch followed by -to switch
403 # Verified same behavior as compiled mhmail.
404 cat > "$expected" <<EOF
405 EHLO nosuchhost.example.com
406 MAIL FROM:<sender@localhost>
407 RCPT TO:<recipient@example.com>
408 RCPT TO:<recipient2@example.com>
409 RCPT TO:<cc1@example.com>
411 To: recipient@example.com, recipient2@example.com
414 From: sender@localhost
422 test_mhmail "$expected" \
423 "-from sender@localhost -cc cc1@example.com -subject Test \
424 -to recipient2@example.com" \
426 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
429 # check with no newline on stdin
430 # Shows different behavior than compiled mhmail, which was silent in this case.
431 cat > "$expected" <<EOF
434 cat > "$expected_err" <<EOF
435 mhmail: empty message not sent, use -body '' to force.
439 printf '' | mhmail recipient@example.com -server 127.0.0.1 -port $localport \
440 >"$actual" 2>"$actual_err"
443 check "$expected" "$actual"
444 check "$expected_err" "$actual_err"
445 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
448 # check with one newline on stdin
449 # Verified same behavior as compiled mhmail.
450 cat > "$expected" <<EOF
451 EHLO nosuchhost.example.com
452 MAIL FROM:<sender@localhost>
453 RCPT TO:<recipient@example.com>
455 To: recipient@example.com
456 From: sender@localhost
464 test_mhmail "$expected" '-from sender@localhost' '|' '\n'
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' '|' '\n\n\n'
487 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
490 # check with text and no trailing newline on stdin
491 # Verified same behavior as compiled mhmail.
492 cat > "$expected" <<EOF
493 EHLO nosuchhost.example.com
494 MAIL FROM:<sender@localhost>
495 RCPT TO:<recipient@example.com>
497 To: recipient@example.com
498 From: sender@localhost
506 test_mhmail "$expected" '-from sender@localhost' '|' 'no newline in input'
507 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
510 # check with text and multiple trailing blank lines on stdin
511 # Verified same behavior as compiled mhmail.
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
528 test_mhmail "$expected" '-from sender@localhost' '|' "here's some text\n\n\n"
529 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
532 # check with no newline to -body
533 # Verified same behavior as compiled mhmail.
534 cat > "$expected" <<EOF
535 EHLO nosuchhost.example.com
536 MAIL FROM:<sender@localhost>
537 RCPT TO:<recipient@example.com>
539 To: recipient@example.com
540 From: sender@localhost
548 test_mhmail "$expected" '-from sender@localhost' -b ''
549 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
552 # check with one newline to -body
553 # Shows different behavior than compiled mhmail, which suppressed the newline.
554 cat > "$expected" <<EOF
555 EHLO nosuchhost.example.com
556 MAIL FROM:<sender@localhost>
557 RCPT TO:<recipient@example.com>
559 To: recipient@example.com
560 From: sender@localhost
569 test_mhmail "$expected" '-from sender@localhost' -b '
571 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
574 # check with multiple newlines to -body
575 # Shows different behavior than compiled mhmail, which suppressed one
577 cat > "$expected" <<EOF
578 EHLO nosuchhost.example.com
579 MAIL FROM:<sender@localhost>
580 RCPT TO:<recipient@example.com>
582 To: recipient@example.com
583 From: sender@localhost
594 test_mhmail "$expected" '-from sender@localhost' -b '
598 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
601 # check with text and no trailing newline to -body
602 # Verified same behavior as compiled mhmail.
603 cat > "$expected" <<EOF
604 EHLO nosuchhost.example.com
605 MAIL FROM:<sender@localhost>
606 RCPT TO:<recipient@example.com>
608 To: recipient@example.com
609 From: sender@localhost
617 test_mhmail "$expected" '-from sender@localhost' -b 'no newline in input'
618 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
621 # check with text and multiple trailing blank lines to -body
622 # Shows different behavior than compiled mhmail, which suppressed one
624 cat > "$expected" <<EOF
625 EHLO nosuchhost.example.com
626 MAIL FROM:<sender@localhost>
627 RCPT TO:<recipient@example.com>
629 To: recipient@example.com
630 From: sender@localhost
640 test_mhmail "$expected" '-from sender@localhost' -b "here's some text
643 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
647 # Verified same behavior as compiled mhmail.
648 cat > "$expected" <<EOF
649 EHLO nosuchhost.example.com
650 MAIL FROM:<orig_recipient@example.com>
651 RCPT TO:<recipient@example.com>
653 Resent-To: recipient@example.com
654 Resent-From: orig_recipient@example.com
655 To: recipient@example.com
656 From: sender@localhost
660 please resend this message, 1
665 test_mhmail "$expected" '-from orig_recipient@example.com -resent' \
666 -b 'To: recipient@example.com
667 From: sender@localhost
668 Date: Sat Jun 16 18:35:15 -0500
670 please resend this message, 1'
672 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
674 # check -resent -profile, using stdin
675 # Not supported by compiled mhmail.
676 cat > "$expected" <<EOF
677 EHLO nosuchhost.example.com
678 MAIL FROM:<orig_recipient@example.com>
679 RCPT TO:<recipient@example.com>
681 To: recipient@example.com
682 From: sender@localhost
684 Resent-To: recipient@example.com
685 Resent-From: orig_recipient@example.com
688 please resend this message, 2
693 test_mhmail "$expected" \
694 '-from orig_recipient@example.com -resent -profile -nomsgid' \
695 '|' 'To: recipient@example.com
696 From: sender@localhost
697 Date: Sat Jun 16 18:35:15 -0500
699 please resend this message, 2'
701 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
704 # check -resent -profile, using -b
705 # Not supported by compiled mhmail.
706 cat > "$expected" <<EOF
707 EHLO nosuchhost.example.com
708 MAIL FROM:<orig_recipient@example.com>
709 RCPT TO:<recipient@example.com>
711 To: recipient@example.com
712 From: sender@localhost
714 Resent-To: recipient@example.com
715 Resent-From: orig_recipient@example.com
718 please resend this message, 3
723 test_mhmail "$expected" \
724 '-from orig_recipient@example.com -resent -profile -nomsgid' \
725 -b 'To: recipient@example.com
726 From: sender@localhost
727 Date: Sat Jun 16 18:35:15 -0500
729 please resend this message, 3'
731 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
734 # check -headerfield.
735 # Not supported by compiled mhmail.
736 cat > "$expected" <<EOF
737 EHLO nosuchhost.example.com
738 MAIL FROM:<sender@example.com>
739 RCPT TO:<recipient@example.com>
741 To: recipient@example.com
742 From: sender@example.com
746 with added header field
751 test_mhmail "$expected" \
752 '-from sender@example.com -headerfield User-Agent:nmh' \
753 -b 'with added header field'
755 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
758 # check multiple -headerfields.
759 # Not supported by compiled mhmail.
760 cat > "$expected" <<EOF
761 EHLO nosuchhost.example.com
762 MAIL FROM:<sender@example.com>
763 RCPT TO:<recipient@example.com>
765 To: recipient@example.com
766 From: sender@example.com
768 Content-Type: text/plain;charset=utf-8
769 Content-Transfer-Encoding: 8bit
772 with added header fields
777 test_mhmail "$expected" \
778 "-from sender@example.com -headerfield MIME-Version:1.0 \
779 -headerfield Content-Type:text/plain;charset=utf-8 \
780 -headerfield Content-Transfer-Encoding:8bit" \
781 -b 'with added header fields'
783 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
787 # Not supported by compiled mhmail.
788 cat > "$expected" <<EOF
789 EHLO nosuchhost.example.com
790 MAIL FROM:<sender@example.com>
791 RCPT TO:<recipient@example.com>
793 To: recipient@example.com
794 From: sender@example.com
796 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
800 ------- =_aaaaaaaaaa0
801 Content-Type: text/plain; charset="us-ascii"
803 See how easy it is to add an attachment!
805 ------- =_aaaaaaaaaa0
806 Content-Type: text/plain; name="attachment.txt"; charset="us-ascii"
807 Content-Description: attachment.txt
808 Content-Disposition: attachment; filename="attachment.txt"
810 The future disappears into memory, With only a moment between,
811 Forever dwells in that moment, hope is what remains to be seen
812 Forever dwells in that moment, hope is what remains to be seen.
814 ------- =_aaaaaaaaaa0--
819 test_mhmail "$expected" \
820 "-from sender@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
821 -b 'See how easy it is to add an attachment!'
823 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}