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 # Find MIME type string, using mimetypeproc if configured with it.
18 MIMETYPEPROC
=`mhparam mimetypeproc`
19 content_type_string
() {
20 if test -z "$MIMETYPEPROC"; then
21 echo "text/plain; name=\"`basename $1`\"; charset=\"us-ascii\""
23 # 1) Excise leading filename followed by : and any whitespace.
24 # 2) Wrap charset value in double quotes. Assume that it isn't already.
26 `$MIMETYPEPROC $1` "; name=\"`basename $1`\"; charset=\"us-ascii\""
30 # Customize test_post () for use with mhmail.
31 # $1 is expected output file, provided by caller
32 # $2 is mhmail switches, except for -body
33 # $3 of -b signifies use -body switch, | signifies provide body on stdin
34 # $4 contains the message body.
37 pid
=`"${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport`
40 printf '%s' "$4" | mhmail recipient@example.com
$2 \
41 -server 127.0.0.1 -port $localport
43 mhmail recipient@example.com
$2 -body "$4" \
44 -server 127.0.0.1 -port $localport
48 # It's hard to calculate the exact Date: header post is going to
49 # use, so we'll just use sed to remove the actual date so we can easily
50 # compare it against our "correct" output. And same for
54 sed -e 's/^Date:.*/Date:/' \
55 -e 's/^Resent-Date:.*/Resent-Date:/' \
56 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
59 check
"$actual".nodate
"$1"
62 expected
=$MH_TEST_DIR/test-mhmail$$.expected
63 expected_err
=$MH_TEST_DIR/test-mhmail$$.expected_err
64 actual
=$MH_TEST_DIR/test-mhmail$$.actual
65 actual_err
=$MH_TEST_DIR/test-mhmail$$.actual_err
69 # Verified behavior consistent with compiled sendmail.
71 Usage: mhmail [-t(o)] addrs ... [switches]
73 -at(tach) file [-at(tach) file] ...
77 -hea(derfield) name:value [-hea(derfield) name:value] ...
85 and all post(8)/send(1) switches
86 mhmail with no arguments is equivalent to inc
89 mhmail
-help >$actual 2>&1
90 check
$expected $actual
94 # Verified same behavior as compiled mhmail.
97 * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2
98 failed
=`expr ${failed:-0} + 1`;;
101 # check for missing argument to switches that require them
102 for switch
in attach body cc from headerfield subject to
; do
103 run_test
"mhmail recipient -$switch" \
104 "mhmail: missing argument to -$switch"
106 for switch
in attach body cc from headerfield subject to
; do
107 run_test
"mhmail recipient -$switch -nosend" \
108 "mhmail: missing argument to -$switch"
110 for switch
in attach body cc from headerfield subject to
; do
111 run_test
"mhmail recipient -$switch -server 127.0.0.1" \
112 "mhmail: missing argument to -$switch"
116 # check with no switches
117 # That will just run inc, which we don't want to do anything,
118 # so tell inc to just display its version.
119 # Verified same behavior as compiled mhmail.
120 printf 'inc: -version\n' >> $MH
123 * ) echo "$0: mhmail generated unexpected output" >&2
124 failed
=`expr ${failed:-0} + 1`;;
129 # Not supported by compiled mhmail.
130 mhmail
-nosend recipient@example.com
-from sender1@localhost \
131 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
133 cat > "$expected" <<EOF
134 To: recipient@example.com
135 From: sender1@localhost
140 cat > "$expected_err" <<EOF
143 check
"$expected" "$actual"
144 check
"$expected_err" "$actual_err"
145 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
149 # Not supported by compiled mhmail.
150 cat > "$expected" <<EOF
151 EHLO nosuchhost.example.com
152 MAIL FROM:<sender2@localhost>
153 RCPT TO:<recipient@example.com>
155 To: recipient@example.com
156 From: sender2@localhost
164 test_mhmail
"$expected" "-from sender2@localhost -nosend -send" '|' message
165 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
169 # Verified same behavior as compiled mhmail.
170 cat > "$expected" <<EOF
171 EHLO nosuchhost.example.com
172 MAIL FROM:<sender3@localhost>
173 RCPT TO:<recipient@example.com>
175 To: recipient@example.com
176 From: sender3@localhost
184 test_mhmail
"$expected" "-from sender3@localhost" '|' message
185 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
188 # check -from and -body
189 # Verified same behavior as compiled mhmail.
190 cat > "$expected" <<EOF
191 EHLO nosuchhost.example.com
192 MAIL FROM:<sender4@localhost>
193 RCPT TO:<recipient@example.com>
195 To: recipient@example.com
196 From: sender4@localhost
204 test_mhmail
"$expected" "-from sender4@localhost" -b body
205 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
208 # check -from and -cc
209 # Verified same behavior as compiled mhmail.
210 cat > "$expected" <<EOF
211 EHLO nosuchhost.example.com
212 MAIL FROM:<sender5@localhost>
213 RCPT TO:<recipient@example.com>
214 RCPT TO:<recipient2@example.com>
216 To: recipient@example.com
217 Cc: recipient2@example.com
218 From: sender5@localhost
226 test_mhmail
"$expected" \
227 "-from sender5@localhost -cc recipient2@example.com" '|' message
228 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
231 # check -from and multiple -cc addresses
232 # Verified same behavior as compiled mhmail.
233 cat > "$expected" <<EOF
234 EHLO nosuchhost.example.com
235 MAIL FROM:<sender6@localhost>
236 RCPT TO:<recipient@example.com>
237 RCPT TO:<recipient2@example.com>
238 RCPT TO:<recipient3@example.com>
239 RCPT TO:<recipient4@example.com>
241 To: recipient@example.com
242 Cc: recipient2@example.com, recipient3@example.com,
243 recipient4@example.com
244 From: sender6@localhost
252 test_mhmail
"$expected" \
253 '-from sender6@localhost -cc recipient2@example.com '\
254 'recipient3@example.com recipient4@example.com' '|' message
255 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
258 # check -from and -subject
259 # Verified same behavior as compiled mhmail.
260 cat > "$expected" <<EOF
261 EHLO nosuchhost.example.com
262 MAIL FROM:<sender7@localhost>
263 RCPT TO:<recipient@example.com>
265 To: recipient@example.com
267 From: sender7@localhost
275 test_mhmail
"$expected" '-from sender7@localhost -subject Test' '|' message
276 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
279 # check -from and -profile
280 # Show that -profile causes mhmail to 1) read the profile and
281 # 2) use send(1) by added a send switch to the profile and
282 # verifying that it gets used.
283 # Not supported by compiled mhmail.
284 printf 'send: -msgid\n' >> $MH
286 cat > "$expected" <<EOF
287 EHLO nosuchhost.example.com
288 MAIL FROM:<sender8@localhost>
289 RCPT TO:<recipient@example.com>
291 To: recipient@example.com
292 From: sender8@localhost
301 test_mhmail
"$expected" '-from sender8@localhost -profile' '|' message
302 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
305 # check repeated -from and -subject switches
306 # Verified same behavior as compiled mhmail.
307 cat > "$expected" <<EOF
308 EHLO nosuchhost.example.com
309 MAIL FROM:<sender9@localhost>
310 RCPT TO:<recipient@example.com>
312 To: recipient@example.com
314 From: sender9@localhost
322 test_mhmail
"$expected" '-from sender9@localhost -from sender9@localhost '\
323 '-subject Subject1 -subject Subject2' -b message
324 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
326 # check repeated -body switches
327 # Verified same behavior as compiled mhmail.
328 cat > "$expected" <<EOF
329 EHLO nosuchhost.example.com
330 MAIL FROM:<sender10@localhost>
331 RCPT TO:<recipient@example.com>
333 To: recipient@example.com
334 From: sender10@localhost
342 test_mhmail
"$expected" "-from sender10@localhost -body body1" -b body2
343 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
346 # check multiple -cc switches
347 # Verified same behavior as compiled mhmail.
348 cat > "$expected" <<EOF
349 EHLO nosuchhost.example.com
350 MAIL FROM:<sender11@localhost>
351 RCPT TO:<recipient@example.com>
352 RCPT TO:<cc1@example.com>
353 RCPT TO:<cc2@example.com>
355 To: recipient@example.com
356 Cc: cc1@example.com, cc2@example.com
357 From: sender11@localhost
365 test_mhmail
"$expected" \
366 '-from sender11@localhost -cc cc1@example.com -cc cc2@example.com' -b message
367 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
370 # check separated -cc arguments
371 # Verified same behavior as compiled mhmail.
372 cat > "$expected" <<EOF
373 EHLO nosuchhost.example.com
374 MAIL FROM:<sender12@localhost>
375 RCPT TO:<recipient@example.com>
376 RCPT TO:<cc1@example.com>
377 RCPT TO:<cc2@example.com>
379 To: recipient@example.com
380 Cc: cc1@example.com, cc2@example.com
382 From: sender12@localhost
390 test_mhmail
"$expected" \
391 '-from sender12@localhost -cc cc1@example.com -subject '\
392 'Test cc2@example.com' -b message
393 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
396 # check -cc switch followed by -to switch
397 # Verified same behavior as compiled mhmail.
398 cat > "$expected" <<EOF
399 EHLO nosuchhost.example.com
400 MAIL FROM:<sender13@localhost>
401 RCPT TO:<recipient@example.com>
402 RCPT TO:<recipient2@example.com>
403 RCPT TO:<cc1@example.com>
405 To: recipient@example.com, recipient2@example.com
408 From: sender13@localhost
416 test_mhmail
"$expected" \
417 "-from sender13@localhost -cc cc1@example.com -subject Test \
418 -to recipient2@example.com" \
420 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
423 # check with no newline on stdin
424 # Shows different behavior than compiled mhmail, which was silent in this case.
425 cat > "$expected" <<EOF
428 cat > "$expected_err" <<EOF
429 mhmail: empty message not sent, use -body '' to force.
433 printf '' | mhmail recipient@example.com
-server 127.0.0.1 -port $localport \
434 >"$actual" 2>"$actual_err"
437 check
"$expected" "$actual"
438 check
"$expected_err" "$actual_err"
439 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
442 # check with one newline on stdin
443 # Verified same behavior as compiled mhmail.
444 cat > "$expected" <<EOF
445 EHLO nosuchhost.example.com
446 MAIL FROM:<sender14@localhost>
447 RCPT TO:<recipient@example.com>
449 To: recipient@example.com
450 From: sender14@localhost
458 test_mhmail
"$expected" '-from sender14@localhost' '|' '
460 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
463 # check with multiple newlines on stdin
464 # Verified same behavior as compiled mhmail.
465 cat > "$expected" <<EOF
466 EHLO nosuchhost.example.com
467 MAIL FROM:<sender15@localhost>
468 RCPT TO:<recipient@example.com>
470 To: recipient@example.com
471 From: sender15@localhost
481 test_mhmail
"$expected" '-from sender15@localhost' '|' '
485 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
488 # check with text and no trailing newline on stdin
489 # Verified same behavior as compiled mhmail.
490 cat > "$expected" <<EOF
491 EHLO nosuchhost.example.com
492 MAIL FROM:<sender16@localhost>
493 RCPT TO:<recipient@example.com>
495 To: recipient@example.com
496 From: sender16@localhost
504 test_mhmail
"$expected" '-from sender16@localhost' '|' 'no newline in input'
505 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
508 # check with text and multiple trailing blank lines on stdin
509 # Verified same behavior as compiled mhmail.
510 cat > "$expected" <<EOF
511 EHLO nosuchhost.example.com
512 MAIL FROM:<sender17@localhost>
513 RCPT TO:<recipient@example.com>
515 To: recipient@example.com
516 From: sender17@localhost
526 test_mhmail
"$expected" '-from sender17@localhost' '|' "here's some text
530 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
533 # check with no newline to -body
534 # Verified same behavior as compiled mhmail.
535 cat > "$expected" <<EOF
536 EHLO nosuchhost.example.com
537 MAIL FROM:<sender18@localhost>
538 RCPT TO:<recipient@example.com>
540 To: recipient@example.com
541 From: sender18@localhost
549 test_mhmail
"$expected" '-from sender18@localhost' -b ''
550 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
553 # check with one newline to -body
554 # Shows different behavior than compiled mhmail, which suppressed the newline.
555 cat > "$expected" <<EOF
556 EHLO nosuchhost.example.com
557 MAIL FROM:<sender19@localhost>
558 RCPT TO:<recipient@example.com>
560 To: recipient@example.com
561 From: sender19@localhost
570 test_mhmail
"$expected" '-from sender19@localhost' -b '
572 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
575 # check with multiple newlines to -body
576 # Shows different behavior than compiled mhmail, which suppressed one
578 cat > "$expected" <<EOF
579 EHLO nosuchhost.example.com
580 MAIL FROM:<sender20@localhost>
581 RCPT TO:<recipient@example.com>
583 To: recipient@example.com
584 From: sender20@localhost
595 test_mhmail
"$expected" '-from sender20@localhost' -b '
599 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
602 # check with text and no trailing newline to -body
603 # Verified same behavior as compiled mhmail.
604 cat > "$expected" <<EOF
605 EHLO nosuchhost.example.com
606 MAIL FROM:<sender21@localhost>
607 RCPT TO:<recipient@example.com>
609 To: recipient@example.com
610 From: sender21@localhost
618 test_mhmail
"$expected" '-from sender21@localhost' -b 'no newline in input'
619 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
622 # check with text and multiple trailing blank lines to -body
623 # Shows different behavior than compiled mhmail, which suppressed one
625 cat > "$expected" <<EOF
626 EHLO nosuchhost.example.com
627 MAIL FROM:<sender22@localhost>
628 RCPT TO:<recipient@example.com>
630 To: recipient@example.com
631 From: sender22@localhost
641 test_mhmail
"$expected" '-from sender22@localhost' -b "here's some text
644 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
648 # Verified same behavior as compiled mhmail.
649 cat > "$expected" <<EOF
650 EHLO nosuchhost.example.com
651 MAIL FROM:<orig_recipient@example.com>
652 RCPT TO:<recipient@example.com>
654 Resent-To: recipient@example.com
655 Resent-From: orig_recipient@example.com
656 To: recipient@example.com
657 From: sender23@localhost
661 please resend this message, 1
666 test_mhmail
"$expected" '-from orig_recipient@example.com -resent' \
667 -b 'To: recipient@example.com
668 From: sender23@localhost
669 Date: Sat Jun 16 18:35:15 -0500
671 please resend this message, 1'
673 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
675 # check -resent -profile, using stdin
676 # Not supported by compiled mhmail.
677 cat > "$expected" <<EOF
678 EHLO nosuchhost.example.com
679 MAIL FROM:<orig_recipient@example.com>
680 RCPT TO:<recipient@example.com>
682 To: recipient@example.com
683 From: sender24@localhost
685 Resent-To: recipient@example.com
686 Resent-From: orig_recipient@example.com
689 please resend this message, 2
694 test_mhmail
"$expected" \
695 '-from orig_recipient@example.com -resent -profile -nomsgid' \
696 '|' 'To: recipient@example.com
697 From: sender24@localhost
698 Date: Sat Jun 16 18:35:15 -0500
700 please resend this message, 2'
702 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
705 # check -resent -profile, using -b
706 # Not supported by compiled mhmail.
707 cat > "$expected" <<EOF
708 EHLO nosuchhost.example.com
709 MAIL FROM:<orig_recipient@example.com>
710 RCPT TO:<recipient@example.com>
712 To: recipient@example.com
713 From: sender25@localhost
715 Resent-To: recipient@example.com
716 Resent-From: orig_recipient@example.com
719 please resend this message, 3
724 test_mhmail
"$expected" \
725 '-from orig_recipient@example.com -resent -profile -nomsgid' \
726 -b 'To: recipient@example.com
727 From: sender25@localhost
728 Date: Sat Jun 16 18:35:15 -0500
730 please resend this message, 3'
732 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
735 # check -headerfield.
736 # Not supported by compiled mhmail.
737 cat > "$expected" <<EOF
738 EHLO nosuchhost.example.com
739 MAIL FROM:<sender26@example.com>
740 RCPT TO:<recipient@example.com>
742 To: recipient@example.com
743 From: sender26@example.com
747 with added header field
752 test_mhmail
"$expected" \
753 '-from sender26@example.com -headerfield User-Agent:nmh' \
754 -b 'with added header field'
756 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
759 # check multiple -headerfields.
760 # Not supported by compiled mhmail.
761 cat > "$expected" <<EOF
762 EHLO nosuchhost.example.com
763 MAIL FROM:<sender27@example.com>
764 RCPT TO:<recipient@example.com>
766 To: recipient@example.com
767 From: sender27@example.com
769 Content-Type: text/plain;charset=utf-8
770 Content-Transfer-Encoding: 8bit
773 with added header fields
778 test_mhmail
"$expected" \
779 "-from sender27@example.com -headerfield MIME-Version:1.0 \
780 -headerfield Content-Type:text/plain;charset=utf-8 \
781 -headerfield Content-Transfer-Encoding:8bit" \
782 -b 'with added header fields'
784 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
788 # Not supported by compiled mhmail.
789 cat > "$expected" <<EOF
790 EHLO nosuchhost.example.com
791 MAIL FROM:<sender28@example.com>
792 RCPT TO:<recipient@example.com>
794 To: recipient@example.com
795 From: sender28@example.com
797 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
801 ------- =_aaaaaaaaaa0
802 Content-Type: text/plain; charset="us-ascii"
804 See how easy it is to add an attachment!
806 ------- =_aaaaaaaaaa0
807 Content-Type: `content_type_string ${srcdir}/test/mhmail/attachment.txt`
808 Content-Description: attachment.txt
809 Content-Disposition: attachment; filename="attachment.txt"
811 The future disappears into memory, With only a moment between,
812 Forever dwells in that moment, hope is what remains to be seen
813 Forever dwells in that moment, hope is what remains to be seen.
815 ------- =_aaaaaaaaaa0--
820 test_mhmail
"$expected" \
821 "-from sender28@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
822 -b 'See how easy it is to add an attachment!'
824 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}