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 sed -e 's/^Date:.*/Date:/' \
42 -e 's/^Resent-Date:.*/Resent-Date:/' \
43 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
46 check
"$actual".nodate
"$1"
49 expected
=$MH_TEST_DIR/test-mhmail$$.expected
50 expected_err
=$MH_TEST_DIR/test-mhmail$$.expected_err
51 actual
=$MH_TEST_DIR/test-mhmail$$.actual
52 actual_err
=$MH_TEST_DIR/test-mhmail$$.actual_err
56 # Verified behavior consistent with compiled sendmail.
58 Usage: mhmail [-t(o)] addrs ... [switches]
60 -at(tach) file [-at(tach) file] ...
64 -hea(derfield) name:value [-hea(derfield) name:value] ...
72 and all post(8)/send(1) switches
73 mhmail with no arguments is equivalent to inc
76 mhmail
-help >$actual 2>&1
77 check
$expected $actual
81 # Verified same behavior as compiled mhmail.
84 * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2
85 failed
=`expr ${failed:-0} + 1`;;
88 # check for missing argument to switches that require them
89 for switch
in attach body cc from headerfield subject to
; do
90 run_test
"mhmail recipient -$switch" \
91 "mhmail: missing argument to -$switch"
93 for switch
in attach body cc from headerfield subject to
; do
94 run_test
"mhmail recipient -$switch -nosend" \
95 "mhmail: missing argument to -$switch"
97 for switch
in attach body cc from headerfield subject to
; do
98 run_test
"mhmail recipient -$switch -server 127.0.0.1" \
99 "mhmail: missing argument to -$switch"
103 # check with no switches
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" >&2
111 failed
=`expr ${failed:-0} + 1`;;
116 # Not supported by compiled mhmail.
117 #### TEMPORARY hack to diagnose failure on Solaris.
119 sh
-x mhmail
-nosend recipient@example.com
-from sender1@localhost
-body '' 2>&1
121 mhmail
-nosend recipient@example.com
-from sender1@localhost \
122 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
124 cat > "$expected" <<EOF
125 To: recipient@example.com
126 From: sender1@localhost
131 cat > "$expected_err" <<EOF
134 check
"$expected" "$actual"
135 check
"$expected_err" "$actual_err"
136 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
140 # Not supported by compiled mhmail.
141 cat > "$expected" <<EOF
142 EHLO nosuchhost.example.com
143 MAIL FROM:<sender2@localhost>
144 RCPT TO:<recipient@example.com>
146 To: recipient@example.com
147 From: sender2@localhost
155 test_mhmail
"$expected" "-from sender2@localhost -nosend -send" '|' message
156 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
160 # Verified same behavior as compiled mhmail.
161 cat > "$expected" <<EOF
162 EHLO nosuchhost.example.com
163 MAIL FROM:<sender3@localhost>
164 RCPT TO:<recipient@example.com>
166 To: recipient@example.com
167 From: sender3@localhost
175 test_mhmail
"$expected" "-from sender3@localhost" '|' message
176 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
179 # check -from and -body
180 # Verified same behavior as compiled mhmail.
181 cat > "$expected" <<EOF
182 EHLO nosuchhost.example.com
183 MAIL FROM:<sender4@localhost>
184 RCPT TO:<recipient@example.com>
186 To: recipient@example.com
187 From: sender4@localhost
195 test_mhmail
"$expected" "-from sender4@localhost" -b body
196 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
199 # check -from and -cc
200 # Verified same behavior as compiled mhmail.
201 cat > "$expected" <<EOF
202 EHLO nosuchhost.example.com
203 MAIL FROM:<sender5@localhost>
204 RCPT TO:<recipient@example.com>
205 RCPT TO:<recipient2@example.com>
207 To: recipient@example.com
208 Cc: recipient2@example.com
209 From: sender5@localhost
217 test_mhmail
"$expected" \
218 "-from sender5@localhost -cc recipient2@example.com" '|' message
219 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
222 # check -from and multiple -cc addresses
223 # Verified same behavior as compiled mhmail.
224 cat > "$expected" <<EOF
225 EHLO nosuchhost.example.com
226 MAIL FROM:<sender6@localhost>
227 RCPT TO:<recipient@example.com>
228 RCPT TO:<recipient2@example.com>
229 RCPT TO:<recipient3@example.com>
230 RCPT TO:<recipient4@example.com>
232 To: recipient@example.com
233 Cc: recipient2@example.com, recipient3@example.com,
234 recipient4@example.com
235 From: sender6@localhost
243 test_mhmail
"$expected" \
244 '-from sender6@localhost -cc recipient2@example.com '\
245 'recipient3@example.com recipient4@example.com' '|' message
246 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
249 # check -from and -subject
250 # Verified same behavior as compiled mhmail.
251 cat > "$expected" <<EOF
252 EHLO nosuchhost.example.com
253 MAIL FROM:<sender7@localhost>
254 RCPT TO:<recipient@example.com>
256 To: recipient@example.com
258 From: sender7@localhost
266 test_mhmail
"$expected" '-from sender7@localhost -subject Test' '|' message
267 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
270 # check -from and -profile
271 # Show that -profile causes mhmail to 1) read the profile and
272 # 2) use send(1) by added a send switch to the profile and
273 # verifying that it gets used.
274 # Not supported by compiled mhmail.
275 printf 'send: -msgid\n' >> $MH
277 cat > "$expected" <<EOF
278 EHLO nosuchhost.example.com
279 MAIL FROM:<sender8@localhost>
280 RCPT TO:<recipient@example.com>
282 To: recipient@example.com
283 From: sender8@localhost
292 test_mhmail
"$expected" '-from sender8@localhost -profile' '|' message
293 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
296 # check repeated -from and -subject switches
297 # Verified same behavior as compiled mhmail.
298 cat > "$expected" <<EOF
299 EHLO nosuchhost.example.com
300 MAIL FROM:<sender9@localhost>
301 RCPT TO:<recipient@example.com>
303 To: recipient@example.com
305 From: sender9@localhost
313 test_mhmail
"$expected" '-from sender9@localhost -from sender9@localhost '\
314 '-subject Subject1 -subject Subject2' -b message
315 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
317 # check repeated -body switches
318 # Verified same behavior as compiled mhmail.
319 cat > "$expected" <<EOF
320 EHLO nosuchhost.example.com
321 MAIL FROM:<sender10@localhost>
322 RCPT TO:<recipient@example.com>
324 To: recipient@example.com
325 From: sender10@localhost
333 test_mhmail
"$expected" "-from sender10@localhost -body body1" -b body2
334 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
337 # check multiple -cc switches
338 # Verified same behavior as compiled mhmail.
339 cat > "$expected" <<EOF
340 EHLO nosuchhost.example.com
341 MAIL FROM:<sender11@localhost>
342 RCPT TO:<recipient@example.com>
343 RCPT TO:<cc1@example.com>
344 RCPT TO:<cc2@example.com>
346 To: recipient@example.com
347 Cc: cc1@example.com, cc2@example.com
348 From: sender11@localhost
356 test_mhmail
"$expected" \
357 '-from sender11@localhost -cc cc1@example.com -cc cc2@example.com' -b message
358 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
361 # check separated -cc arguments
362 # Verified same behavior as compiled mhmail.
363 cat > "$expected" <<EOF
364 EHLO nosuchhost.example.com
365 MAIL FROM:<sender12@localhost>
366 RCPT TO:<recipient@example.com>
367 RCPT TO:<cc1@example.com>
368 RCPT TO:<cc2@example.com>
370 To: recipient@example.com
371 Cc: cc1@example.com, cc2@example.com
373 From: sender12@localhost
381 test_mhmail
"$expected" \
382 '-from sender12@localhost -cc cc1@example.com -subject '\
383 'Test cc2@example.com' -b message
384 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
387 # check -cc switch followed by -to switch
388 # Verified same behavior as compiled mhmail.
389 cat > "$expected" <<EOF
390 EHLO nosuchhost.example.com
391 MAIL FROM:<sender13@localhost>
392 RCPT TO:<recipient@example.com>
393 RCPT TO:<recipient2@example.com>
394 RCPT TO:<cc1@example.com>
396 To: recipient@example.com, recipient2@example.com
399 From: sender13@localhost
407 test_mhmail
"$expected" \
408 "-from sender13@localhost -cc cc1@example.com -subject Test \
409 -to recipient2@example.com" \
411 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
414 # check with no newline on stdin
415 # Shows different behavior than compiled mhmail, which was silent in this case.
416 cat > "$expected" <<EOF
419 cat > "$expected_err" <<EOF
420 mhmail: empty message not sent, use -body '' to force.
424 printf '' | mhmail recipient@example.com
-server 127.0.0.1 -port $localport \
425 >"$actual" 2>"$actual_err"
428 check
"$expected" "$actual"
429 check
"$expected_err" "$actual_err"
430 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
433 # check with one newline on stdin
434 # Verified same behavior as compiled mhmail.
435 cat > "$expected" <<EOF
436 EHLO nosuchhost.example.com
437 MAIL FROM:<sender14@localhost>
438 RCPT TO:<recipient@example.com>
440 To: recipient@example.com
441 From: sender14@localhost
449 test_mhmail
"$expected" '-from sender14@localhost' '|' '
451 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
454 # check with multiple newlines on stdin
455 # Verified same behavior as compiled mhmail.
456 cat > "$expected" <<EOF
457 EHLO nosuchhost.example.com
458 MAIL FROM:<sender15@localhost>
459 RCPT TO:<recipient@example.com>
461 To: recipient@example.com
462 From: sender15@localhost
472 test_mhmail
"$expected" '-from sender15@localhost' '|' '
476 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
479 # check with text and no trailing newline on stdin
480 # Verified same behavior as compiled mhmail.
481 cat > "$expected" <<EOF
482 EHLO nosuchhost.example.com
483 MAIL FROM:<sender16@localhost>
484 RCPT TO:<recipient@example.com>
486 To: recipient@example.com
487 From: sender16@localhost
495 test_mhmail
"$expected" '-from sender16@localhost' '|' 'no newline in input'
496 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
499 # check with text and multiple trailing blank lines on stdin
500 # Verified same behavior as compiled mhmail.
501 cat > "$expected" <<EOF
502 EHLO nosuchhost.example.com
503 MAIL FROM:<sender17@localhost>
504 RCPT TO:<recipient@example.com>
506 To: recipient@example.com
507 From: sender17@localhost
517 test_mhmail
"$expected" '-from sender17@localhost' '|' "here's some text
521 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
524 # check with no newline to -body
525 # Verified same behavior as compiled mhmail.
526 cat > "$expected" <<EOF
527 EHLO nosuchhost.example.com
528 MAIL FROM:<sender18@localhost>
529 RCPT TO:<recipient@example.com>
531 To: recipient@example.com
532 From: sender18@localhost
540 test_mhmail
"$expected" '-from sender18@localhost' -b ''
541 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
544 # check with one newline to -body
545 # Shows different behavior than compiled mhmail, which suppressed the newline.
546 cat > "$expected" <<EOF
547 EHLO nosuchhost.example.com
548 MAIL FROM:<sender19@localhost>
549 RCPT TO:<recipient@example.com>
551 To: recipient@example.com
552 From: sender19@localhost
561 test_mhmail
"$expected" '-from sender19@localhost' -b '
563 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
566 # check with multiple newlines to -body
567 # Shows different behavior than compiled mhmail, which suppressed one
569 cat > "$expected" <<EOF
570 EHLO nosuchhost.example.com
571 MAIL FROM:<sender20@localhost>
572 RCPT TO:<recipient@example.com>
574 To: recipient@example.com
575 From: sender20@localhost
586 test_mhmail
"$expected" '-from sender20@localhost' -b '
590 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
593 # check with text and no trailing newline to -body
594 # Verified same behavior as compiled mhmail.
595 cat > "$expected" <<EOF
596 EHLO nosuchhost.example.com
597 MAIL FROM:<sender21@localhost>
598 RCPT TO:<recipient@example.com>
600 To: recipient@example.com
601 From: sender21@localhost
609 test_mhmail
"$expected" '-from sender21@localhost' -b 'no newline in input'
610 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
613 # check with text and multiple trailing blank lines to -body
614 # Shows different behavior than compiled mhmail, which suppressed one
616 cat > "$expected" <<EOF
617 EHLO nosuchhost.example.com
618 MAIL FROM:<sender22@localhost>
619 RCPT TO:<recipient@example.com>
621 To: recipient@example.com
622 From: sender22@localhost
632 test_mhmail
"$expected" '-from sender22@localhost' -b "here's some text
635 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
639 # Verified same behavior as compiled mhmail.
640 cat > "$expected" <<EOF
641 EHLO nosuchhost.example.com
642 MAIL FROM:<orig_recipient@example.com>
643 RCPT TO:<recipient@example.com>
645 Resent-To: recipient@example.com
646 Resent-From: orig_recipient@example.com
647 To: recipient@example.com
648 From: sender23@localhost
652 please resend this message, 1
657 test_mhmail
"$expected" '-from orig_recipient@example.com -resent' \
658 -b 'To: recipient@example.com
659 From: sender23@localhost
660 Date: Sat Jun 16 18:35:15 -0500
662 please resend this message, 1'
664 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
666 # check -resent -profile, using stdin
667 # Not supported by compiled mhmail.
668 cat > "$expected" <<EOF
669 EHLO nosuchhost.example.com
670 MAIL FROM:<orig_recipient@example.com>
671 RCPT TO:<recipient@example.com>
673 To: recipient@example.com
674 From: sender24@localhost
676 Resent-To: recipient@example.com
677 Resent-From: orig_recipient@example.com
680 please resend this message, 2
685 test_mhmail
"$expected" \
686 '-from orig_recipient@example.com -resent -profile -nomsgid' \
687 '|' 'To: recipient@example.com
688 From: sender24@localhost
689 Date: Sat Jun 16 18:35:15 -0500
691 please resend this message, 2'
693 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
696 # check -resent -profile, using -b
697 # Not supported by compiled mhmail.
698 cat > "$expected" <<EOF
699 EHLO nosuchhost.example.com
700 MAIL FROM:<orig_recipient@example.com>
701 RCPT TO:<recipient@example.com>
703 To: recipient@example.com
704 From: sender25@localhost
706 Resent-To: recipient@example.com
707 Resent-From: orig_recipient@example.com
710 please resend this message, 3
715 test_mhmail
"$expected" \
716 '-from orig_recipient@example.com -resent -profile -nomsgid' \
717 -b 'To: recipient@example.com
718 From: sender25@localhost
719 Date: Sat Jun 16 18:35:15 -0500
721 please resend this message, 3'
723 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
726 # check -headerfield.
727 # Not supported by compiled mhmail.
728 cat > "$expected" <<EOF
729 EHLO nosuchhost.example.com
730 MAIL FROM:<sender26@example.com>
731 RCPT TO:<recipient@example.com>
733 To: recipient@example.com
734 From: sender26@example.com
738 with added header field
743 test_mhmail
"$expected" \
744 '-from sender26@example.com -headerfield User-Agent:nmh' \
745 -b 'with added header field'
747 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
750 # check multiple -headerfields.
751 # Not supported by compiled mhmail.
752 cat > "$expected" <<EOF
753 EHLO nosuchhost.example.com
754 MAIL FROM:<sender27@example.com>
755 RCPT TO:<recipient@example.com>
757 To: recipient@example.com
758 From: sender27@example.com
760 Content-Type: text/plain;charset=utf-8
761 Content-Transfer-Encoding: 8bit
764 with added header fields
769 test_mhmail
"$expected" \
770 "-from sender27@example.com -headerfield MIME-Version:1.0 \
771 -headerfield Content-Type:text/plain;charset=utf-8 \
772 -headerfield Content-Transfer-Encoding:8bit" \
773 -b 'with added header fields'
775 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
779 # Not supported by compiled mhmail.
780 cat > "$expected" <<EOF
781 EHLO nosuchhost.example.com
782 MAIL FROM:<sender28@example.com>
783 RCPT TO:<recipient@example.com>
785 To: recipient@example.com
786 From: sender28@example.com
788 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
792 ------- =_aaaaaaaaaa0
793 Content-Type: text/plain; charset="us-ascii"
795 See how easy it is to add an attachment!
797 ------- =_aaaaaaaaaa0
798 Content-Type: text/plain; name="attachment.txt"; charset="us-ascii"
799 Content-Description: attachment.txt
800 Content-Disposition: attachment; filename="attachment.txt"
802 The future disappears into memory, With only a moment between,
803 Forever dwells in that moment, hope is what remains to be seen
804 Forever dwells in that moment, hope is what remains to be seen.
806 ------- =_aaaaaaaaaa0--
811 test_mhmail
"$expected" \
812 "-from sender28@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
813 -b 'See how easy it is to add an attachment!'
815 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}