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 configured procs if available.
18 MIMETYPEPROC
=`mhparam mimetypeproc`
19 MIMEENCODINGPROC
=`mhparam mimeencodingproc`
20 content_type_string
() {
21 if test -z "$MIMETYPEPROC" -o -z "$MIMEENCODINGPROC"; then
22 #### This should be the order of name and charset.
23 echo "text/plain; name=\"`basename $1`\"; charset=\"us-ascii\""
25 #### Excise any leading filename followed by : and whitespace.
26 printf '%s; charset="%s"; name="%s"' \
27 `$MIMETYPEPROC $1 | sed -e 's/.*: *//'` \
28 `$MIMEENCODINGPROC $1 | sed -e 's/.*: *//'` `basename $1`
32 # Customize test_post () for use with mhmail.
33 # $1 is expected output file, provided by caller
34 # $2 is mhmail switches, except for -body
35 # $3 of -b signifies use -body switch, | signifies provide body on stdin
36 # $4 contains the message body.
39 pid
=`"${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport`
42 printf '%s' "$4" | mhmail recipient@example.com
$2 \
43 -server 127.0.0.1 -port $localport
45 mhmail recipient@example.com
$2 -body "$4" \
46 -server 127.0.0.1 -port $localport
50 # It's hard to calculate the exact Date: header post is going to
51 # use, so we'll just use sed to remove the actual date so we can easily
52 # compare it against our "correct" output. And same for
56 sed -e 's/^Date:.*/Date:/' \
57 -e 's/^Resent-Date:.*/Resent-Date:/' \
58 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
61 check
"$actual".nodate
"$1"
64 expected
=$MH_TEST_DIR/test-mhmail$$.expected
65 expected_err
=$MH_TEST_DIR/test-mhmail$$.expected_err
66 actual
=$MH_TEST_DIR/test-mhmail$$.actual
67 actual_err
=$MH_TEST_DIR/test-mhmail$$.actual_err
71 # Verified behavior consistent with compiled sendmail.
73 Usage: mhmail [-t(o)] addrs ... [switches]
75 -at(tach) file [-at(tach) file] ...
79 -hea(derfield) name:value [-hea(derfield) name:value] ...
87 and all post(8)/send(1) switches
88 mhmail with no arguments is equivalent to inc
91 mhmail
-help >$actual 2>&1
92 check
$expected $actual
96 # Verified same behavior as compiled mhmail.
99 * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2
100 failed
=`expr ${failed:-0} + 1`;;
103 # check for missing argument to switches that require them
104 for switch
in attach body cc from headerfield subject to
; do
105 run_test
"mhmail recipient -$switch" \
106 "mhmail: missing argument to -$switch"
108 for switch
in attach body cc from headerfield subject to
; do
109 run_test
"mhmail recipient -$switch -nosend" \
110 "mhmail: missing argument to -$switch"
112 for switch
in attach body cc from headerfield subject to
; do
113 run_test
"mhmail recipient -$switch -server 127.0.0.1" \
114 "mhmail: missing argument to -$switch"
118 # check with no switches
119 # That will just run inc, which we don't want to do anything,
120 # so tell inc to just display its version.
121 # Verified same behavior as compiled mhmail.
122 printf 'inc: -version\n' >> $MH
125 * ) echo "$0: mhmail generated unexpected output" >&2
126 failed
=`expr ${failed:-0} + 1`;;
131 # Not supported by compiled mhmail.
132 mhmail
-nosend recipient@example.com
-from sender1@localhost \
133 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
135 cat > "$expected" <<EOF
136 To: recipient@example.com
137 From: sender1@localhost
142 cat > "$expected_err" <<EOF
145 check
"$expected" "$actual"
146 check
"$expected_err" "$actual_err"
147 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
151 # Not supported by compiled mhmail.
152 cat > "$expected" <<EOF
153 EHLO nosuchhost.example.com
154 MAIL FROM:<sender2@localhost>
155 RCPT TO:<recipient@example.com>
157 To: recipient@example.com
158 From: sender2@localhost
166 test_mhmail
"$expected" "-from sender2@localhost -nosend -send" '|' message
167 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
171 # Verified same behavior as compiled mhmail.
172 cat > "$expected" <<EOF
173 EHLO nosuchhost.example.com
174 MAIL FROM:<sender3@localhost>
175 RCPT TO:<recipient@example.com>
177 To: recipient@example.com
178 From: sender3@localhost
186 test_mhmail
"$expected" "-from sender3@localhost" '|' message
187 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
190 # check -from and -body
191 # Verified same behavior as compiled mhmail.
192 cat > "$expected" <<EOF
193 EHLO nosuchhost.example.com
194 MAIL FROM:<sender4@localhost>
195 RCPT TO:<recipient@example.com>
197 To: recipient@example.com
198 From: sender4@localhost
206 test_mhmail
"$expected" "-from sender4@localhost" -b body
207 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
210 # check -from and -cc
211 # Verified same behavior as compiled mhmail.
212 cat > "$expected" <<EOF
213 EHLO nosuchhost.example.com
214 MAIL FROM:<sender5@localhost>
215 RCPT TO:<recipient@example.com>
216 RCPT TO:<recipient2@example.com>
218 To: recipient@example.com
219 Cc: recipient2@example.com
220 From: sender5@localhost
228 test_mhmail
"$expected" \
229 "-from sender5@localhost -cc recipient2@example.com" '|' message
230 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
233 # check -from and multiple -cc addresses
234 # Verified same behavior as compiled mhmail.
235 cat > "$expected" <<EOF
236 EHLO nosuchhost.example.com
237 MAIL FROM:<sender6@localhost>
238 RCPT TO:<recipient@example.com>
239 RCPT TO:<recipient2@example.com>
240 RCPT TO:<recipient3@example.com>
241 RCPT TO:<recipient4@example.com>
243 To: recipient@example.com
244 Cc: recipient2@example.com, recipient3@example.com,
245 recipient4@example.com
246 From: sender6@localhost
254 test_mhmail
"$expected" \
255 '-from sender6@localhost -cc recipient2@example.com '\
256 'recipient3@example.com recipient4@example.com' '|' message
257 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
260 # check -from and -subject
261 # Verified same behavior as compiled mhmail.
262 cat > "$expected" <<EOF
263 EHLO nosuchhost.example.com
264 MAIL FROM:<sender7@localhost>
265 RCPT TO:<recipient@example.com>
267 To: recipient@example.com
269 From: sender7@localhost
277 test_mhmail
"$expected" '-from sender7@localhost -subject Test' '|' message
278 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
281 # check -from and -profile
282 # Show that -profile causes mhmail to 1) read the profile and
283 # 2) use send(1) by added a send switch to the profile and
284 # verifying that it gets used.
285 # Not supported by compiled mhmail.
286 printf 'send: -msgid\n' >> $MH
288 cat > "$expected" <<EOF
289 EHLO nosuchhost.example.com
290 MAIL FROM:<sender8@localhost>
291 RCPT TO:<recipient@example.com>
293 To: recipient@example.com
294 From: sender8@localhost
296 Content-Type: text/plain; charset="us-ascii"
305 test_mhmail
"$expected" '-from sender8@localhost -profile' '|' message
306 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
309 # check repeated -from and -subject switches
310 # Verified same behavior as compiled mhmail.
311 cat > "$expected" <<EOF
312 EHLO nosuchhost.example.com
313 MAIL FROM:<sender9@localhost>
314 RCPT TO:<recipient@example.com>
316 To: recipient@example.com
318 From: sender9@localhost
326 test_mhmail
"$expected" '-from sender9@localhost -from sender9@localhost '\
327 '-subject Subject1 -subject Subject2' -b message
328 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
330 # check repeated -body switches
331 # Verified same behavior as compiled mhmail.
332 cat > "$expected" <<EOF
333 EHLO nosuchhost.example.com
334 MAIL FROM:<sender10@localhost>
335 RCPT TO:<recipient@example.com>
337 To: recipient@example.com
338 From: sender10@localhost
346 test_mhmail
"$expected" "-from sender10@localhost -body body1" -b body2
347 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
350 # check multiple -cc switches
351 # Verified same behavior as compiled mhmail.
352 cat > "$expected" <<EOF
353 EHLO nosuchhost.example.com
354 MAIL FROM:<sender11@localhost>
355 RCPT TO:<recipient@example.com>
356 RCPT TO:<cc1@example.com>
357 RCPT TO:<cc2@example.com>
359 To: recipient@example.com
360 Cc: cc1@example.com, cc2@example.com
361 From: sender11@localhost
369 test_mhmail
"$expected" \
370 '-from sender11@localhost -cc cc1@example.com -cc cc2@example.com' -b message
371 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
374 # check separated -cc arguments
375 # Verified same behavior as compiled mhmail.
376 cat > "$expected" <<EOF
377 EHLO nosuchhost.example.com
378 MAIL FROM:<sender12@localhost>
379 RCPT TO:<recipient@example.com>
380 RCPT TO:<cc1@example.com>
381 RCPT TO:<cc2@example.com>
383 To: recipient@example.com
384 Cc: cc1@example.com, cc2@example.com
386 From: sender12@localhost
394 test_mhmail
"$expected" \
395 '-from sender12@localhost -cc cc1@example.com -subject '\
396 'Test cc2@example.com' -b message
397 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
400 # check -cc switch followed by -to switch
401 # Verified same behavior as compiled mhmail.
402 cat > "$expected" <<EOF
403 EHLO nosuchhost.example.com
404 MAIL FROM:<sender13@localhost>
405 RCPT TO:<recipient@example.com>
406 RCPT TO:<recipient2@example.com>
407 RCPT TO:<cc1@example.com>
409 To: recipient@example.com, recipient2@example.com
412 From: sender13@localhost
420 test_mhmail
"$expected" \
421 "-from sender13@localhost -cc cc1@example.com -subject Test \
422 -to recipient2@example.com" \
424 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
427 # check with no newline on stdin
428 # Shows different behavior than compiled mhmail, which was silent in this case.
429 cat > "$expected" <<EOF
432 cat > "$expected_err" <<EOF
433 mhmail: empty message not sent, use -body '' to force.
437 printf '' | mhmail recipient@example.com
-server 127.0.0.1 -port $localport \
438 >"$actual" 2>"$actual_err"
441 check
"$expected" "$actual"
442 check
"$expected_err" "$actual_err"
443 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
446 # check with one newline on stdin
447 # Verified same behavior as compiled mhmail.
448 cat > "$expected" <<EOF
449 EHLO nosuchhost.example.com
450 MAIL FROM:<sender14@localhost>
451 RCPT TO:<recipient@example.com>
453 To: recipient@example.com
454 From: sender14@localhost
462 test_mhmail
"$expected" '-from sender14@localhost' '|' '
464 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
467 # check with multiple newlines on stdin
468 # Verified same behavior as compiled mhmail.
469 cat > "$expected" <<EOF
470 EHLO nosuchhost.example.com
471 MAIL FROM:<sender15@localhost>
472 RCPT TO:<recipient@example.com>
474 To: recipient@example.com
475 From: sender15@localhost
485 test_mhmail
"$expected" '-from sender15@localhost' '|' '
489 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
492 # check with text and no trailing newline on stdin
493 # Verified same behavior as compiled mhmail.
494 cat > "$expected" <<EOF
495 EHLO nosuchhost.example.com
496 MAIL FROM:<sender16@localhost>
497 RCPT TO:<recipient@example.com>
499 To: recipient@example.com
500 From: sender16@localhost
508 test_mhmail
"$expected" '-from sender16@localhost' '|' 'no newline in input'
509 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
512 # check with text and multiple trailing blank lines on stdin
513 # Verified same behavior as compiled mhmail.
514 cat > "$expected" <<EOF
515 EHLO nosuchhost.example.com
516 MAIL FROM:<sender17@localhost>
517 RCPT TO:<recipient@example.com>
519 To: recipient@example.com
520 From: sender17@localhost
530 test_mhmail
"$expected" '-from sender17@localhost' '|' "here's some text
534 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
537 # check with no newline to -body
538 # Verified same behavior as compiled mhmail.
539 cat > "$expected" <<EOF
540 EHLO nosuchhost.example.com
541 MAIL FROM:<sender18@localhost>
542 RCPT TO:<recipient@example.com>
544 To: recipient@example.com
545 From: sender18@localhost
553 test_mhmail
"$expected" '-from sender18@localhost' -b ''
554 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
557 # check with one newline to -body
558 # Shows different behavior than compiled mhmail, which suppressed the newline.
559 cat > "$expected" <<EOF
560 EHLO nosuchhost.example.com
561 MAIL FROM:<sender19@localhost>
562 RCPT TO:<recipient@example.com>
564 To: recipient@example.com
565 From: sender19@localhost
574 test_mhmail
"$expected" '-from sender19@localhost' -b '
576 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
579 # check with multiple newlines to -body
580 # Shows different behavior than compiled mhmail, which suppressed one
582 cat > "$expected" <<EOF
583 EHLO nosuchhost.example.com
584 MAIL FROM:<sender20@localhost>
585 RCPT TO:<recipient@example.com>
587 To: recipient@example.com
588 From: sender20@localhost
599 test_mhmail
"$expected" '-from sender20@localhost' -b '
603 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
606 # check with text and no trailing newline to -body
607 # Verified same behavior as compiled mhmail.
608 cat > "$expected" <<EOF
609 EHLO nosuchhost.example.com
610 MAIL FROM:<sender21@localhost>
611 RCPT TO:<recipient@example.com>
613 To: recipient@example.com
614 From: sender21@localhost
622 test_mhmail
"$expected" '-from sender21@localhost' -b 'no newline in input'
623 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
626 # check with text and multiple trailing blank lines to -body
627 # Shows different behavior than compiled mhmail, which suppressed one
629 cat > "$expected" <<EOF
630 EHLO nosuchhost.example.com
631 MAIL FROM:<sender22@localhost>
632 RCPT TO:<recipient@example.com>
634 To: recipient@example.com
635 From: sender22@localhost
645 test_mhmail
"$expected" '-from sender22@localhost' -b "here's some text
648 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
652 # Verified same behavior as compiled mhmail.
653 cat > "$expected" <<EOF
654 EHLO nosuchhost.example.com
655 MAIL FROM:<orig_recipient@example.com>
656 RCPT TO:<recipient@example.com>
658 Resent-To: recipient@example.com
659 Resent-From: orig_recipient@example.com
660 To: recipient@example.com
661 From: sender23@localhost
665 please resend this message, 1
670 test_mhmail
"$expected" '-from orig_recipient@example.com -resent' \
671 -b 'To: recipient@example.com
672 From: sender23@localhost
673 Date: Sat Jun 16 18:35:15 -0500
675 please resend this message, 1'
677 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
679 # check -resent -profile, using stdin
680 # Not supported by compiled mhmail.
681 cat > "$expected" <<EOF
682 EHLO nosuchhost.example.com
683 MAIL FROM:<orig_recipient@example.com>
684 RCPT TO:<recipient@example.com>
686 To: recipient@example.com
687 From: sender24@localhost
689 Resent-To: recipient@example.com
690 Resent-From: orig_recipient@example.com
693 please resend this message, 2
698 test_mhmail
"$expected" \
699 '-from orig_recipient@example.com -resent -profile -nomsgid' \
700 '|' 'To: recipient@example.com
701 From: sender24@localhost
702 Date: Sat Jun 16 18:35:15 -0500
704 please resend this message, 2'
706 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
709 # check -resent -profile, using -b
710 # Not supported by compiled mhmail.
711 cat > "$expected" <<EOF
712 EHLO nosuchhost.example.com
713 MAIL FROM:<orig_recipient@example.com>
714 RCPT TO:<recipient@example.com>
716 To: recipient@example.com
717 From: sender25@localhost
719 Resent-To: recipient@example.com
720 Resent-From: orig_recipient@example.com
723 please resend this message, 3
728 test_mhmail
"$expected" \
729 '-from orig_recipient@example.com -resent -profile -nomsgid' \
730 -b 'To: recipient@example.com
731 From: sender25@localhost
732 Date: Sat Jun 16 18:35:15 -0500
734 please resend this message, 3'
736 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
739 # check -headerfield.
740 # Not supported by compiled mhmail.
741 cat > "$expected" <<EOF
742 EHLO nosuchhost.example.com
743 MAIL FROM:<sender26@example.com>
744 RCPT TO:<recipient@example.com>
746 To: recipient@example.com
747 From: sender26@example.com
751 with added header field
756 test_mhmail
"$expected" \
757 '-from sender26@example.com -headerfield User-Agent:nmh' \
758 -b 'with added header field'
760 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
763 # check multiple -headerfields.
764 # Not supported by compiled mhmail.
765 cat > "$expected" <<EOF
766 EHLO nosuchhost.example.com
767 MAIL FROM:<sender27@example.com>
768 RCPT TO:<recipient@example.com>
770 To: recipient@example.com
771 From: sender27@example.com
773 Content-Type: text/plain;charset=utf-8
774 Content-Transfer-Encoding: 8bit
777 with added header fields
782 test_mhmail
"$expected" \
783 "-from sender27@example.com -headerfield MIME-Version:1.0 \
784 -headerfield Content-Type:text/plain;charset=utf-8 \
785 -headerfield Content-Transfer-Encoding:8bit" \
786 -b 'with added header fields'
788 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
792 # Not supported by compiled mhmail.
793 cat > "$expected" <<EOF
794 EHLO nosuchhost.example.com
795 MAIL FROM:<sender28@example.com>
796 RCPT TO:<recipient@example.com>
798 To: recipient@example.com
799 From: sender28@example.com
801 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
805 ------- =_aaaaaaaaaa0
806 Content-Type: text/plain; charset="us-ascii"
808 See how easy it is to add an attachment!
810 ------- =_aaaaaaaaaa0
811 Content-Type: `content_type_string ${srcdir}/test/mhmail/attachment.txt`
812 Content-Description: attachment.txt
813 Content-Disposition: attachment; filename="attachment.txt"
815 The future disappears into memory, With only a moment between,
816 Forever dwells in that moment, hope is what remains to be seen
817 Forever dwells in that moment, hope is what remains to be seen.
819 ------- =_aaaaaaaaaa0--
824 test_mhmail
"$expected" \
825 "-from sender28@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
826 -b 'See how easy it is to add an attachment!'
828 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}