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
303 test_mhmail
"$expected" '-from sender8@localhost -profile' '|' message
304 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
307 # check repeated -from and -subject switches
308 # Verified same behavior as compiled mhmail.
309 cat > "$expected" <<EOF
310 EHLO nosuchhost.example.com
311 MAIL FROM:<sender9@localhost>
312 RCPT TO:<recipient@example.com>
314 To: recipient@example.com
316 From: sender9@localhost
324 test_mhmail
"$expected" '-from sender9@localhost -from sender9@localhost '\
325 '-subject Subject1 -subject Subject2' -b message
326 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
328 # check repeated -body switches
329 # Verified same behavior as compiled mhmail.
330 cat > "$expected" <<EOF
331 EHLO nosuchhost.example.com
332 MAIL FROM:<sender10@localhost>
333 RCPT TO:<recipient@example.com>
335 To: recipient@example.com
336 From: sender10@localhost
344 test_mhmail
"$expected" "-from sender10@localhost -body body1" -b body2
345 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
348 # check multiple -cc switches
349 # Verified same behavior as compiled mhmail.
350 cat > "$expected" <<EOF
351 EHLO nosuchhost.example.com
352 MAIL FROM:<sender11@localhost>
353 RCPT TO:<recipient@example.com>
354 RCPT TO:<cc1@example.com>
355 RCPT TO:<cc2@example.com>
357 To: recipient@example.com
358 Cc: cc1@example.com, cc2@example.com
359 From: sender11@localhost
367 test_mhmail
"$expected" \
368 '-from sender11@localhost -cc cc1@example.com -cc cc2@example.com' -b message
369 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
372 # check separated -cc arguments
373 # Verified same behavior as compiled mhmail.
374 cat > "$expected" <<EOF
375 EHLO nosuchhost.example.com
376 MAIL FROM:<sender12@localhost>
377 RCPT TO:<recipient@example.com>
378 RCPT TO:<cc1@example.com>
379 RCPT TO:<cc2@example.com>
381 To: recipient@example.com
382 Cc: cc1@example.com, cc2@example.com
384 From: sender12@localhost
392 test_mhmail
"$expected" \
393 '-from sender12@localhost -cc cc1@example.com -subject '\
394 'Test cc2@example.com' -b message
395 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
398 # check -cc switch followed by -to switch
399 # Verified same behavior as compiled mhmail.
400 cat > "$expected" <<EOF
401 EHLO nosuchhost.example.com
402 MAIL FROM:<sender13@localhost>
403 RCPT TO:<recipient@example.com>
404 RCPT TO:<recipient2@example.com>
405 RCPT TO:<cc1@example.com>
407 To: recipient@example.com, recipient2@example.com
410 From: sender13@localhost
418 test_mhmail
"$expected" \
419 "-from sender13@localhost -cc cc1@example.com -subject Test \
420 -to recipient2@example.com" \
422 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
425 # check with no newline on stdin
426 # Shows different behavior than compiled mhmail, which was silent in this case.
427 cat > "$expected" <<EOF
430 cat > "$expected_err" <<EOF
431 mhmail: empty message not sent, use -body '' to force.
435 printf '' | mhmail recipient@example.com
-server 127.0.0.1 -port $localport \
436 >"$actual" 2>"$actual_err"
439 check
"$expected" "$actual"
440 check
"$expected_err" "$actual_err"
441 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
444 # check with one newline on stdin
445 # Verified same behavior as compiled mhmail.
446 cat > "$expected" <<EOF
447 EHLO nosuchhost.example.com
448 MAIL FROM:<sender14@localhost>
449 RCPT TO:<recipient@example.com>
451 To: recipient@example.com
452 From: sender14@localhost
460 test_mhmail
"$expected" '-from sender14@localhost' '|' '
462 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
465 # check with multiple newlines on stdin
466 # Verified same behavior as compiled mhmail.
467 cat > "$expected" <<EOF
468 EHLO nosuchhost.example.com
469 MAIL FROM:<sender15@localhost>
470 RCPT TO:<recipient@example.com>
472 To: recipient@example.com
473 From: sender15@localhost
483 test_mhmail
"$expected" '-from sender15@localhost' '|' '
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:<sender16@localhost>
495 RCPT TO:<recipient@example.com>
497 To: recipient@example.com
498 From: sender16@localhost
506 test_mhmail
"$expected" '-from sender16@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:<sender17@localhost>
515 RCPT TO:<recipient@example.com>
517 To: recipient@example.com
518 From: sender17@localhost
528 test_mhmail
"$expected" '-from sender17@localhost' '|' "here's some text
532 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
535 # check with no newline to -body
536 # Verified same behavior as compiled mhmail.
537 cat > "$expected" <<EOF
538 EHLO nosuchhost.example.com
539 MAIL FROM:<sender18@localhost>
540 RCPT TO:<recipient@example.com>
542 To: recipient@example.com
543 From: sender18@localhost
551 test_mhmail
"$expected" '-from sender18@localhost' -b ''
552 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
555 # check with one newline to -body
556 # Shows different behavior than compiled mhmail, which suppressed the newline.
557 cat > "$expected" <<EOF
558 EHLO nosuchhost.example.com
559 MAIL FROM:<sender19@localhost>
560 RCPT TO:<recipient@example.com>
562 To: recipient@example.com
563 From: sender19@localhost
572 test_mhmail
"$expected" '-from sender19@localhost' -b '
574 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
577 # check with multiple newlines to -body
578 # Shows different behavior than compiled mhmail, which suppressed one
580 cat > "$expected" <<EOF
581 EHLO nosuchhost.example.com
582 MAIL FROM:<sender20@localhost>
583 RCPT TO:<recipient@example.com>
585 To: recipient@example.com
586 From: sender20@localhost
597 test_mhmail
"$expected" '-from sender20@localhost' -b '
601 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
604 # check with text and no trailing newline to -body
605 # Verified same behavior as compiled mhmail.
606 cat > "$expected" <<EOF
607 EHLO nosuchhost.example.com
608 MAIL FROM:<sender21@localhost>
609 RCPT TO:<recipient@example.com>
611 To: recipient@example.com
612 From: sender21@localhost
620 test_mhmail
"$expected" '-from sender21@localhost' -b 'no newline in input'
621 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
624 # check with text and multiple trailing blank lines to -body
625 # Shows different behavior than compiled mhmail, which suppressed one
627 cat > "$expected" <<EOF
628 EHLO nosuchhost.example.com
629 MAIL FROM:<sender22@localhost>
630 RCPT TO:<recipient@example.com>
632 To: recipient@example.com
633 From: sender22@localhost
643 test_mhmail
"$expected" '-from sender22@localhost' -b "here's some text
646 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
650 # Verified same behavior as compiled mhmail.
651 cat > "$expected" <<EOF
652 EHLO nosuchhost.example.com
653 MAIL FROM:<orig_recipient@example.com>
654 RCPT TO:<recipient@example.com>
656 Resent-To: recipient@example.com
657 Resent-From: orig_recipient@example.com
658 To: recipient@example.com
659 From: sender23@localhost
663 please resend this message, 1
668 test_mhmail
"$expected" '-from orig_recipient@example.com -resent' \
669 -b 'To: recipient@example.com
670 From: sender23@localhost
671 Date: Sat Jun 16 18:35:15 -0500
673 please resend this message, 1'
675 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
677 # check -resent -profile, using stdin
678 # Not supported by compiled mhmail.
679 cat > "$expected" <<EOF
680 EHLO nosuchhost.example.com
681 MAIL FROM:<orig_recipient@example.com>
682 RCPT TO:<recipient@example.com>
684 To: recipient@example.com
685 From: sender24@localhost
687 Resent-To: recipient@example.com
688 Resent-From: orig_recipient@example.com
691 please resend this message, 2
696 test_mhmail
"$expected" \
697 '-from orig_recipient@example.com -resent -profile -nomsgid' \
698 '|' 'To: recipient@example.com
699 From: sender24@localhost
700 Date: Sat Jun 16 18:35:15 -0500
702 please resend this message, 2'
704 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
707 # check -resent -profile, using -b
708 # Not supported by compiled mhmail.
709 cat > "$expected" <<EOF
710 EHLO nosuchhost.example.com
711 MAIL FROM:<orig_recipient@example.com>
712 RCPT TO:<recipient@example.com>
714 To: recipient@example.com
715 From: sender25@localhost
717 Resent-To: recipient@example.com
718 Resent-From: orig_recipient@example.com
721 please resend this message, 3
726 test_mhmail
"$expected" \
727 '-from orig_recipient@example.com -resent -profile -nomsgid' \
728 -b 'To: recipient@example.com
729 From: sender25@localhost
730 Date: Sat Jun 16 18:35:15 -0500
732 please resend this message, 3'
734 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
737 # check -headerfield.
738 # Not supported by compiled mhmail.
739 cat > "$expected" <<EOF
740 EHLO nosuchhost.example.com
741 MAIL FROM:<sender26@example.com>
742 RCPT TO:<recipient@example.com>
744 To: recipient@example.com
745 From: sender26@example.com
749 with added header field
754 test_mhmail
"$expected" \
755 '-from sender26@example.com -headerfield User-Agent:nmh' \
756 -b 'with added header field'
758 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
761 # check multiple -headerfields.
762 # Not supported by compiled mhmail.
763 cat > "$expected" <<EOF
764 EHLO nosuchhost.example.com
765 MAIL FROM:<sender27@example.com>
766 RCPT TO:<recipient@example.com>
768 To: recipient@example.com
769 From: sender27@example.com
771 Content-Type: text/plain;charset=utf-8
772 Content-Transfer-Encoding: 8bit
775 with added header fields
780 test_mhmail
"$expected" \
781 "-from sender27@example.com -headerfield MIME-Version:1.0 \
782 -headerfield Content-Type:text/plain;charset=utf-8 \
783 -headerfield Content-Transfer-Encoding:8bit" \
784 -b 'with added header fields'
786 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
790 # Not supported by compiled mhmail.
791 cat > "$expected" <<EOF
792 EHLO nosuchhost.example.com
793 MAIL FROM:<sender28@example.com>
794 RCPT TO:<recipient@example.com>
796 To: recipient@example.com
797 From: sender28@example.com
799 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
803 ------- =_aaaaaaaaaa0
804 Content-Type: text/plain; charset="us-ascii"
806 See how easy it is to add an attachment!
808 ------- =_aaaaaaaaaa0
809 Content-Type: `content_type_string ${srcdir}/test/mhmail/attachment.txt`
810 Content-Description: attachment.txt
811 Content-Disposition: attachment; filename="attachment.txt"
813 The future disappears into memory, With only a moment between,
814 Forever dwells in that moment, hope is what remains to be seen
815 Forever dwells in that moment, hope is what remains to be seen.
817 ------- =_aaaaaaaaaa0--
822 test_mhmail
"$expected" \
823 "-from sender28@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
824 -b 'See how easy it is to add an attachment!'
826 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}