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 pid
=`"${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport`
27 printf '%s' "$4" | mhmail recipient@example.com
$2 \
28 -server 127.0.0.1 -port $localport
30 mhmail recipient@example.com
$2 -body "$4" \
31 -server 127.0.0.1 -port $localport
35 # It's hard to calculate the exact Date: header post is going to
36 # use, so we'll just use sed to remove the actual date so we can easily
37 # compare it against our "correct" output. And same for
41 ls -l $actual >&2 # ???? temporary
46 sed -e 's/^Date:.*/Date:/' \
47 -e 's/^Resent-Date:.*/Resent-Date:/' \
48 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
51 check
"$actual".nodate
"$1"
54 expected
=$MH_TEST_DIR/test-mhmail$$.expected
55 expected_err
=$MH_TEST_DIR/test-mhmail$$.expected_err
56 actual
=$MH_TEST_DIR/test-mhmail$$.actual
57 actual_err
=$MH_TEST_DIR/test-mhmail$$.actual_err
61 # Verified behavior consistent with compiled sendmail.
63 Usage: mhmail [-t(o)] addrs ... [switches]
65 -at(tach) file [-at(tach) file] ...
69 -hea(derfield) name:value [-hea(derfield) name:value] ...
77 and all post(8)/send(1) switches
78 mhmail with no arguments is equivalent to inc
81 mhmail
-help >$actual 2>&1
82 check
$expected $actual
86 # Verified same behavior as compiled mhmail.
89 * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2
90 failed
=`expr ${failed:-0} + 1`;;
93 # check for missing argument to switches that require them
94 for switch
in attach body cc from headerfield subject to
; do
95 run_test
"mhmail recipient -$switch" \
96 "mhmail: missing argument to -$switch"
98 for switch
in attach body cc from headerfield subject to
; do
99 run_test
"mhmail recipient -$switch -nosend" \
100 "mhmail: missing argument to -$switch"
102 for switch
in attach body cc from headerfield subject to
; do
103 run_test
"mhmail recipient -$switch -server 127.0.0.1" \
104 "mhmail: missing argument to -$switch"
108 # check with no switches
109 # That will just run inc, which we don't want to do anything,
110 # so tell inc to just display its version.
111 # Verified same behavior as compiled mhmail.
112 printf 'inc: -version\n' >> $MH
115 * ) echo "$0: mhmail generated unexpected output" >&2
116 failed
=`expr ${failed:-0} + 1`;;
121 # Not supported by compiled mhmail.
122 mhmail
-nosend recipient@example.com
-from sender@localhost \
123 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
125 cat > "$expected" <<EOF
126 To: recipient@example.com
127 From: sender@localhost
132 cat > "$expected_err" <<EOF
135 check
"$expected" "$actual"
136 check
"$expected_err" "$actual_err"
137 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
141 # Not supported by compiled mhmail.
142 cat > "$expected" <<EOF
143 EHLO nosuchhost.example.com
144 MAIL FROM:<sender@localhost>
145 RCPT TO:<recipient@example.com>
147 To: recipient@example.com
148 From: sender@localhost
156 test_mhmail
"$expected" "-from sender@localhost -nosend -send" '|' message
157 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
161 # Verified same behavior as compiled mhmail.
162 cat > "$expected" <<EOF
163 EHLO nosuchhost.example.com
164 MAIL FROM:<sender@localhost>
165 RCPT TO:<recipient@example.com>
167 To: recipient@example.com
168 From: sender@localhost
176 test_mhmail
"$expected" "-from sender@localhost" '|' message
177 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
180 # check -from and -body
181 # Verified same behavior as compiled mhmail.
182 cat > "$expected" <<EOF
183 EHLO nosuchhost.example.com
184 MAIL FROM:<sender@localhost>
185 RCPT TO:<recipient@example.com>
187 To: recipient@example.com
188 From: sender@localhost
196 test_mhmail
"$expected" "-from sender@localhost" -b body
197 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
200 # check -from and -cc
201 # Verified same behavior as compiled mhmail.
202 cat > "$expected" <<EOF
203 EHLO nosuchhost.example.com
204 MAIL FROM:<sender@localhost>
205 RCPT TO:<recipient@example.com>
206 RCPT TO:<recipient2@example.com>
208 To: recipient@example.com
209 Cc: recipient2@example.com
210 From: sender@localhost
218 test_mhmail
"$expected" \
219 "-from sender@localhost -cc recipient2@example.com" '|' message
220 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
223 # check -from and multiple -cc addresses
224 # Verified same behavior as compiled mhmail.
225 cat > "$expected" <<EOF
226 EHLO nosuchhost.example.com
227 MAIL FROM:<sender@localhost>
228 RCPT TO:<recipient@example.com>
229 RCPT TO:<recipient2@example.com>
230 RCPT TO:<recipient3@example.com>
231 RCPT TO:<recipient4@example.com>
233 To: recipient@example.com
234 Cc: recipient2@example.com, recipient3@example.com,
235 recipient4@example.com
236 From: sender@localhost
244 test_mhmail
"$expected" \
245 '-from sender@localhost -cc recipient2@example.com recipient3@example.com '\
246 'recipient4@example.com' '|' message
247 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
250 # check -from and -subject
251 # Verified same behavior as compiled mhmail.
252 cat > "$expected" <<EOF
253 EHLO nosuchhost.example.com
254 MAIL FROM:<sender@localhost>
255 RCPT TO:<recipient@example.com>
257 To: recipient@example.com
259 From: sender@localhost
267 test_mhmail
"$expected" '-from sender@localhost -subject Test' '|' message
268 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
271 # check -from and -profile
272 # Show that -profile causes mhmail to 1) read the profile and
273 # 2) use send(1) by added a send switch to the profile and
274 # verifying that it gets used.
275 # Not supported by compiled mhmail.
276 printf 'send: -msgid\n' >> $MH
278 cat > "$expected" <<EOF
279 EHLO nosuchhost.example.com
280 MAIL FROM:<sender@localhost>
281 RCPT TO:<recipient@example.com>
283 To: recipient@example.com
284 From: sender@localhost
293 test_mhmail
"$expected" '-from sender@localhost -profile' '|' message
294 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
297 # check repeated -from and -subject switches
298 # Verified same behavior as compiled mhmail.
299 cat > "$expected" <<EOF
300 EHLO nosuchhost.example.com
301 MAIL FROM:<sender2@localhost>
302 RCPT TO:<recipient@example.com>
304 To: recipient@example.com
306 From: sender2@localhost
314 test_mhmail
"$expected" '-from sender@localhost -from sender2@localhost '\
315 '-subject Subject1 -subject Subject2' -b message
316 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
318 # check repeated -body switches
319 # Verified same behavior as compiled mhmail.
320 cat > "$expected" <<EOF
321 EHLO nosuchhost.example.com
322 MAIL FROM:<sender@localhost>
323 RCPT TO:<recipient@example.com>
325 To: recipient@example.com
326 From: sender@localhost
334 test_mhmail
"$expected" "-from sender@localhost -body body1" -b body2
335 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
338 # check multiple -cc switches
339 # Verified same behavior as compiled mhmail.
340 cat > "$expected" <<EOF
341 EHLO nosuchhost.example.com
342 MAIL FROM:<sender@localhost>
343 RCPT TO:<recipient@example.com>
344 RCPT TO:<cc1@example.com>
345 RCPT TO:<cc2@example.com>
347 To: recipient@example.com
348 Cc: cc1@example.com, cc2@example.com
349 From: sender@localhost
357 test_mhmail
"$expected" \
358 '-from sender@localhost -cc cc1@example.com -cc cc2@example.com' -b message
359 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
362 # check separated -cc arguments
363 # Verified same behavior as compiled mhmail.
364 cat > "$expected" <<EOF
365 EHLO nosuchhost.example.com
366 MAIL FROM:<sender@localhost>
367 RCPT TO:<recipient@example.com>
368 RCPT TO:<cc1@example.com>
369 RCPT TO:<cc2@example.com>
371 To: recipient@example.com
372 Cc: cc1@example.com, cc2@example.com
374 From: sender@localhost
382 test_mhmail
"$expected" \
383 '-from sender@localhost -cc cc1@example.com -subject Test cc2@example.com' \
385 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
388 # check -cc switch followed by -to switch
389 # Verified same behavior as compiled mhmail.
390 cat > "$expected" <<EOF
391 EHLO nosuchhost.example.com
392 MAIL FROM:<sender@localhost>
393 RCPT TO:<recipient@example.com>
394 RCPT TO:<recipient2@example.com>
395 RCPT TO:<cc1@example.com>
397 To: recipient@example.com, recipient2@example.com
400 From: sender@localhost
408 test_mhmail
"$expected" \
409 "-from sender@localhost -cc cc1@example.com -subject Test \
410 -to recipient2@example.com" \
412 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
415 # check with no newline on stdin
416 # Shows different behavior than compiled mhmail, which was silent in this case.
417 cat > "$expected" <<EOF
420 cat > "$expected_err" <<EOF
421 mhmail: empty message not sent, use -body '' to force.
425 printf '' | mhmail recipient@example.com
-server 127.0.0.1 -port $localport \
426 >"$actual" 2>"$actual_err"
429 check
"$expected" "$actual"
430 check
"$expected_err" "$actual_err"
431 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
434 # check with one newline on stdin
435 # Verified same behavior as compiled mhmail.
436 cat > "$expected" <<EOF
437 EHLO nosuchhost.example.com
438 MAIL FROM:<sender@localhost>
439 RCPT TO:<recipient@example.com>
441 To: recipient@example.com
442 From: sender@localhost
450 test_mhmail
"$expected" '-from sender@localhost' '|' '
452 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
455 # check with multiple newlines on stdin
456 # Verified same behavior as compiled mhmail.
457 cat > "$expected" <<EOF
458 EHLO nosuchhost.example.com
459 MAIL FROM:<sender@localhost>
460 RCPT TO:<recipient@example.com>
462 To: recipient@example.com
463 From: sender@localhost
473 test_mhmail
"$expected" '-from sender@localhost' '|' '
477 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
480 # check with text and no trailing newline on stdin
481 # Verified same behavior as compiled mhmail.
482 cat > "$expected" <<EOF
483 EHLO nosuchhost.example.com
484 MAIL FROM:<sender@localhost>
485 RCPT TO:<recipient@example.com>
487 To: recipient@example.com
488 From: sender@localhost
496 test_mhmail
"$expected" '-from sender@localhost' '|' 'no newline in input'
497 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
500 # check with text and multiple trailing blank lines on stdin
501 # Verified same behavior as compiled mhmail.
502 cat > "$expected" <<EOF
503 EHLO nosuchhost.example.com
504 MAIL FROM:<sender@localhost>
505 RCPT TO:<recipient@example.com>
507 To: recipient@example.com
508 From: sender@localhost
518 test_mhmail
"$expected" '-from sender@localhost' '|' "here's some text
522 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
525 # check with no newline to -body
526 # Verified same behavior as compiled mhmail.
527 cat > "$expected" <<EOF
528 EHLO nosuchhost.example.com
529 MAIL FROM:<sender@localhost>
530 RCPT TO:<recipient@example.com>
532 To: recipient@example.com
533 From: sender@localhost
541 test_mhmail
"$expected" '-from sender@localhost' -b ''
542 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
545 # check with one newline to -body
546 # Shows different behavior than compiled mhmail, which suppressed the newline.
547 cat > "$expected" <<EOF
548 EHLO nosuchhost.example.com
549 MAIL FROM:<sender@localhost>
550 RCPT TO:<recipient@example.com>
552 To: recipient@example.com
553 From: sender@localhost
562 test_mhmail
"$expected" '-from sender@localhost' -b '
564 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
567 # check with multiple newlines to -body
568 # Shows different behavior than compiled mhmail, which suppressed one
570 cat > "$expected" <<EOF
571 EHLO nosuchhost.example.com
572 MAIL FROM:<sender@localhost>
573 RCPT TO:<recipient@example.com>
575 To: recipient@example.com
576 From: sender@localhost
587 test_mhmail
"$expected" '-from sender@localhost' -b '
591 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
594 # check with text and no trailing newline to -body
595 # Verified same behavior as compiled mhmail.
596 cat > "$expected" <<EOF
597 EHLO nosuchhost.example.com
598 MAIL FROM:<sender@localhost>
599 RCPT TO:<recipient@example.com>
601 To: recipient@example.com
602 From: sender@localhost
610 test_mhmail
"$expected" '-from sender@localhost' -b 'no newline in input'
611 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
614 # check with text and multiple trailing blank lines to -body
615 # Shows different behavior than compiled mhmail, which suppressed one
617 cat > "$expected" <<EOF
618 EHLO nosuchhost.example.com
619 MAIL FROM:<sender@localhost>
620 RCPT TO:<recipient@example.com>
622 To: recipient@example.com
623 From: sender@localhost
633 test_mhmail
"$expected" '-from sender@localhost' -b "here's some text
636 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
640 # Verified same behavior as compiled mhmail.
641 cat > "$expected" <<EOF
642 EHLO nosuchhost.example.com
643 MAIL FROM:<orig_recipient@example.com>
644 RCPT TO:<recipient@example.com>
646 Resent-To: recipient@example.com
647 Resent-From: orig_recipient@example.com
648 To: recipient@example.com
649 From: sender@localhost
653 please resend this message, 1
658 test_mhmail
"$expected" '-from orig_recipient@example.com -resent' \
659 -b 'To: recipient@example.com
660 From: sender@localhost
661 Date: Sat Jun 16 18:35:15 -0500
663 please resend this message, 1'
665 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
667 # check -resent -profile, using stdin
668 # Not supported by compiled mhmail.
669 cat > "$expected" <<EOF
670 EHLO nosuchhost.example.com
671 MAIL FROM:<orig_recipient@example.com>
672 RCPT TO:<recipient@example.com>
674 To: recipient@example.com
675 From: sender@localhost
677 Resent-To: recipient@example.com
678 Resent-From: orig_recipient@example.com
681 please resend this message, 2
686 test_mhmail
"$expected" \
687 '-from orig_recipient@example.com -resent -profile -nomsgid' \
688 '|' 'To: recipient@example.com
689 From: sender@localhost
690 Date: Sat Jun 16 18:35:15 -0500
692 please resend this message, 2'
694 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
697 # check -resent -profile, using -b
698 # Not supported by compiled mhmail.
699 cat > "$expected" <<EOF
700 EHLO nosuchhost.example.com
701 MAIL FROM:<orig_recipient@example.com>
702 RCPT TO:<recipient@example.com>
704 To: recipient@example.com
705 From: sender@localhost
707 Resent-To: recipient@example.com
708 Resent-From: orig_recipient@example.com
711 please resend this message, 3
716 test_mhmail
"$expected" \
717 '-from orig_recipient@example.com -resent -profile -nomsgid' \
718 -b 'To: recipient@example.com
719 From: sender@localhost
720 Date: Sat Jun 16 18:35:15 -0500
722 please resend this message, 3'
724 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
727 # check -headerfield.
728 # Not supported by compiled mhmail.
729 cat > "$expected" <<EOF
730 EHLO nosuchhost.example.com
731 MAIL FROM:<sender@example.com>
732 RCPT TO:<recipient@example.com>
734 To: recipient@example.com
735 From: sender@example.com
739 with added header field
744 test_mhmail
"$expected" \
745 '-from sender@example.com -headerfield User-Agent:nmh' \
746 -b 'with added header field'
748 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
751 # check multiple -headerfields.
752 # Not supported by compiled mhmail.
753 cat > "$expected" <<EOF
754 EHLO nosuchhost.example.com
755 MAIL FROM:<sender@example.com>
756 RCPT TO:<recipient@example.com>
758 To: recipient@example.com
759 From: sender@example.com
761 Content-Type: text/plain;charset=utf-8
762 Content-Transfer-Encoding: 8bit
765 with added header fields
770 test_mhmail
"$expected" \
771 "-from sender@example.com -headerfield MIME-Version:1.0 \
772 -headerfield Content-Type:text/plain;charset=utf-8 \
773 -headerfield Content-Transfer-Encoding:8bit" \
774 -b 'with added header fields'
776 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
780 # Not supported by compiled mhmail.
781 cat > "$expected" <<EOF
782 EHLO nosuchhost.example.com
783 MAIL FROM:<sender@example.com>
784 RCPT TO:<recipient@example.com>
786 To: recipient@example.com
787 From: sender@example.com
789 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
793 ------- =_aaaaaaaaaa0
794 Content-Type: text/plain; charset="us-ascii"
796 See how easy it is to add an attachment!
798 ------- =_aaaaaaaaaa0
799 Content-Type: text/plain; name="attachment.txt"; charset="us-ascii"
800 Content-Description: attachment.txt
801 Content-Disposition: attachment; filename="attachment.txt"
803 The future disappears into memory, With only a moment between,
804 Forever dwells in that moment, hope is what remains to be seen
805 Forever dwells in that moment, hope is what remains to be seen.
807 ------- =_aaaaaaaaaa0--
812 test_mhmail
"$expected" \
813 "-from sender@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
814 -b 'See how easy it is to add an attachment!'
816 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}