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) Insert semicolon if there isn't one before the first space.
25 # OpenBSD file --mime spits out things like "text/plain charset=...".
26 # 3) Wrap charset value in double quotes. Assume that it isn't already.
28 `$MIMETYPEPROC $1 | sed -e 's/.*: *//' -e 's/\([^;]\) /\1; /' \
29 -e 's/\(charset=\)\(.*\)/\1"\2"/'` "; name=\"`basename $1`\""
33 # Customize test_post () for use with mhmail.
34 # $1 is expected output file, provided by caller
35 # $2 is mhmail switches, except for -body
36 # $3 of -b signifies use -body switch, | signifies provide body on stdin
37 # $4 contains the message body.
40 pid
=`"${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport`
43 printf '%s' "$4" | mhmail recipient@example.com
$2 \
44 -server 127.0.0.1 -port $localport
46 mhmail recipient@example.com
$2 -body "$4" \
47 -server 127.0.0.1 -port $localport
51 # It's hard to calculate the exact Date: header post is going to
52 # use, so we'll just use sed to remove the actual date so we can easily
53 # compare it against our "correct" output. And same for
57 sed -e 's/^Date:.*/Date:/' \
58 -e 's/^Resent-Date:.*/Resent-Date:/' \
59 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
62 check
"$actual".nodate
"$1"
65 expected
=$MH_TEST_DIR/test-mhmail$$.expected
66 expected_err
=$MH_TEST_DIR/test-mhmail$$.expected_err
67 actual
=$MH_TEST_DIR/test-mhmail$$.actual
68 actual_err
=$MH_TEST_DIR/test-mhmail$$.actual_err
72 # Verified behavior consistent with compiled sendmail.
74 Usage: mhmail [-t(o)] addrs ... [switches]
76 -at(tach) file [-at(tach) file] ...
80 -hea(derfield) name:value [-hea(derfield) name:value] ...
88 and all post(8)/send(1) switches
89 mhmail with no arguments is equivalent to inc
92 mhmail
-help >$actual 2>&1
93 check
$expected $actual
97 # Verified same behavior as compiled mhmail.
100 * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2
101 failed
=`expr ${failed:-0} + 1`;;
104 # check for missing argument to switches that require them
105 for switch
in attach body cc from headerfield subject to
; do
106 run_test
"mhmail recipient -$switch" \
107 "mhmail: missing argument to -$switch"
109 for switch
in attach body cc from headerfield subject to
; do
110 run_test
"mhmail recipient -$switch -nosend" \
111 "mhmail: missing argument to -$switch"
113 for switch
in attach body cc from headerfield subject to
; do
114 run_test
"mhmail recipient -$switch -server 127.0.0.1" \
115 "mhmail: missing argument to -$switch"
119 # check with no switches
120 # That will just run inc, which we don't want to do anything,
121 # so tell inc to just display its version.
122 # Verified same behavior as compiled mhmail.
123 printf 'inc: -version\n' >> $MH
126 * ) echo "$0: mhmail generated unexpected output" >&2
127 failed
=`expr ${failed:-0} + 1`;;
132 # Not supported by compiled mhmail.
133 mhmail
-nosend recipient@example.com
-from sender1@localhost \
134 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
136 cat > "$expected" <<EOF
137 To: recipient@example.com
138 From: sender1@localhost
143 cat > "$expected_err" <<EOF
146 check
"$expected" "$actual"
147 check
"$expected_err" "$actual_err"
148 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
152 # Not supported by compiled mhmail.
153 cat > "$expected" <<EOF
154 EHLO nosuchhost.example.com
155 MAIL FROM:<sender2@localhost>
156 RCPT TO:<recipient@example.com>
158 To: recipient@example.com
159 From: sender2@localhost
167 test_mhmail
"$expected" "-from sender2@localhost -nosend -send" '|' message
168 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
172 # Verified same behavior as compiled mhmail.
173 cat > "$expected" <<EOF
174 EHLO nosuchhost.example.com
175 MAIL FROM:<sender3@localhost>
176 RCPT TO:<recipient@example.com>
178 To: recipient@example.com
179 From: sender3@localhost
187 test_mhmail
"$expected" "-from sender3@localhost" '|' message
188 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
191 # check -from and -body
192 # Verified same behavior as compiled mhmail.
193 cat > "$expected" <<EOF
194 EHLO nosuchhost.example.com
195 MAIL FROM:<sender4@localhost>
196 RCPT TO:<recipient@example.com>
198 To: recipient@example.com
199 From: sender4@localhost
207 test_mhmail
"$expected" "-from sender4@localhost" -b body
208 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
211 # check -from and -cc
212 # Verified same behavior as compiled mhmail.
213 cat > "$expected" <<EOF
214 EHLO nosuchhost.example.com
215 MAIL FROM:<sender5@localhost>
216 RCPT TO:<recipient@example.com>
217 RCPT TO:<recipient2@example.com>
219 To: recipient@example.com
220 Cc: recipient2@example.com
221 From: sender5@localhost
229 test_mhmail
"$expected" \
230 "-from sender5@localhost -cc recipient2@example.com" '|' message
231 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
234 # check -from and multiple -cc addresses
235 # Verified same behavior as compiled mhmail.
236 cat > "$expected" <<EOF
237 EHLO nosuchhost.example.com
238 MAIL FROM:<sender6@localhost>
239 RCPT TO:<recipient@example.com>
240 RCPT TO:<recipient2@example.com>
241 RCPT TO:<recipient3@example.com>
242 RCPT TO:<recipient4@example.com>
244 To: recipient@example.com
245 Cc: recipient2@example.com, recipient3@example.com,
246 recipient4@example.com
247 From: sender6@localhost
255 test_mhmail
"$expected" \
256 '-from sender6@localhost -cc recipient2@example.com '\
257 'recipient3@example.com recipient4@example.com' '|' message
258 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
261 # check -from and -subject
262 # Verified same behavior as compiled mhmail.
263 cat > "$expected" <<EOF
264 EHLO nosuchhost.example.com
265 MAIL FROM:<sender7@localhost>
266 RCPT TO:<recipient@example.com>
268 To: recipient@example.com
270 From: sender7@localhost
278 test_mhmail
"$expected" '-from sender7@localhost -subject Test' '|' message
279 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
282 # check -from and -profile
283 # Show that -profile causes mhmail to 1) read the profile and
284 # 2) use send(1) by added a send switch to the profile and
285 # verifying that it gets used.
286 # Not supported by compiled mhmail.
287 printf 'send: -msgid\n' >> $MH
289 cat > "$expected" <<EOF
290 EHLO nosuchhost.example.com
291 MAIL FROM:<sender8@localhost>
292 RCPT TO:<recipient@example.com>
294 To: recipient@example.com
295 From: sender8@localhost
304 test_mhmail
"$expected" '-from sender8@localhost -profile' '|' message
305 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
308 # check repeated -from and -subject switches
309 # Verified same behavior as compiled mhmail.
310 cat > "$expected" <<EOF
311 EHLO nosuchhost.example.com
312 MAIL FROM:<sender9@localhost>
313 RCPT TO:<recipient@example.com>
315 To: recipient@example.com
317 From: sender9@localhost
325 test_mhmail
"$expected" '-from sender9@localhost -from sender9@localhost '\
326 '-subject Subject1 -subject Subject2' -b message
327 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
329 # check repeated -body switches
330 # Verified same behavior as compiled mhmail.
331 cat > "$expected" <<EOF
332 EHLO nosuchhost.example.com
333 MAIL FROM:<sender10@localhost>
334 RCPT TO:<recipient@example.com>
336 To: recipient@example.com
337 From: sender10@localhost
345 test_mhmail
"$expected" "-from sender10@localhost -body body1" -b body2
346 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
349 # check multiple -cc switches
350 # Verified same behavior as compiled mhmail.
351 cat > "$expected" <<EOF
352 EHLO nosuchhost.example.com
353 MAIL FROM:<sender11@localhost>
354 RCPT TO:<recipient@example.com>
355 RCPT TO:<cc1@example.com>
356 RCPT TO:<cc2@example.com>
358 To: recipient@example.com
359 Cc: cc1@example.com, cc2@example.com
360 From: sender11@localhost
368 test_mhmail
"$expected" \
369 '-from sender11@localhost -cc cc1@example.com -cc cc2@example.com' -b message
370 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
373 # check separated -cc arguments
374 # Verified same behavior as compiled mhmail.
375 cat > "$expected" <<EOF
376 EHLO nosuchhost.example.com
377 MAIL FROM:<sender12@localhost>
378 RCPT TO:<recipient@example.com>
379 RCPT TO:<cc1@example.com>
380 RCPT TO:<cc2@example.com>
382 To: recipient@example.com
383 Cc: cc1@example.com, cc2@example.com
385 From: sender12@localhost
393 test_mhmail
"$expected" \
394 '-from sender12@localhost -cc cc1@example.com -subject '\
395 'Test cc2@example.com' -b message
396 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
399 # check -cc switch followed by -to switch
400 # Verified same behavior as compiled mhmail.
401 cat > "$expected" <<EOF
402 EHLO nosuchhost.example.com
403 MAIL FROM:<sender13@localhost>
404 RCPT TO:<recipient@example.com>
405 RCPT TO:<recipient2@example.com>
406 RCPT TO:<cc1@example.com>
408 To: recipient@example.com, recipient2@example.com
411 From: sender13@localhost
419 test_mhmail
"$expected" \
420 "-from sender13@localhost -cc cc1@example.com -subject Test \
421 -to recipient2@example.com" \
423 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
426 # check with no newline on stdin
427 # Shows different behavior than compiled mhmail, which was silent in this case.
428 cat > "$expected" <<EOF
431 cat > "$expected_err" <<EOF
432 mhmail: empty message not sent, use -body '' to force.
436 printf '' | mhmail recipient@example.com
-server 127.0.0.1 -port $localport \
437 >"$actual" 2>"$actual_err"
440 check
"$expected" "$actual"
441 check
"$expected_err" "$actual_err"
442 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
445 # check with one newline on stdin
446 # Verified same behavior as compiled mhmail.
447 cat > "$expected" <<EOF
448 EHLO nosuchhost.example.com
449 MAIL FROM:<sender14@localhost>
450 RCPT TO:<recipient@example.com>
452 To: recipient@example.com
453 From: sender14@localhost
461 test_mhmail
"$expected" '-from sender14@localhost' '|' '
463 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
466 # check with multiple newlines on stdin
467 # Verified same behavior as compiled mhmail.
468 cat > "$expected" <<EOF
469 EHLO nosuchhost.example.com
470 MAIL FROM:<sender15@localhost>
471 RCPT TO:<recipient@example.com>
473 To: recipient@example.com
474 From: sender15@localhost
484 test_mhmail
"$expected" '-from sender15@localhost' '|' '
488 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
491 # check with text and no trailing newline on stdin
492 # Verified same behavior as compiled mhmail.
493 cat > "$expected" <<EOF
494 EHLO nosuchhost.example.com
495 MAIL FROM:<sender16@localhost>
496 RCPT TO:<recipient@example.com>
498 To: recipient@example.com
499 From: sender16@localhost
507 test_mhmail
"$expected" '-from sender16@localhost' '|' 'no newline in input'
508 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
511 # check with text and multiple trailing blank lines on stdin
512 # Verified same behavior as compiled mhmail.
513 cat > "$expected" <<EOF
514 EHLO nosuchhost.example.com
515 MAIL FROM:<sender17@localhost>
516 RCPT TO:<recipient@example.com>
518 To: recipient@example.com
519 From: sender17@localhost
529 test_mhmail
"$expected" '-from sender17@localhost' '|' "here's some text
533 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
536 # check with no newline to -body
537 # Verified same behavior as compiled mhmail.
538 cat > "$expected" <<EOF
539 EHLO nosuchhost.example.com
540 MAIL FROM:<sender18@localhost>
541 RCPT TO:<recipient@example.com>
543 To: recipient@example.com
544 From: sender18@localhost
552 test_mhmail
"$expected" '-from sender18@localhost' -b ''
553 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
556 # check with one newline to -body
557 # Shows different behavior than compiled mhmail, which suppressed the newline.
558 cat > "$expected" <<EOF
559 EHLO nosuchhost.example.com
560 MAIL FROM:<sender19@localhost>
561 RCPT TO:<recipient@example.com>
563 To: recipient@example.com
564 From: sender19@localhost
573 test_mhmail
"$expected" '-from sender19@localhost' -b '
575 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
578 # check with multiple newlines to -body
579 # Shows different behavior than compiled mhmail, which suppressed one
581 cat > "$expected" <<EOF
582 EHLO nosuchhost.example.com
583 MAIL FROM:<sender20@localhost>
584 RCPT TO:<recipient@example.com>
586 To: recipient@example.com
587 From: sender20@localhost
598 test_mhmail
"$expected" '-from sender20@localhost' -b '
602 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
605 # check with text and no trailing newline to -body
606 # Verified same behavior as compiled mhmail.
607 cat > "$expected" <<EOF
608 EHLO nosuchhost.example.com
609 MAIL FROM:<sender21@localhost>
610 RCPT TO:<recipient@example.com>
612 To: recipient@example.com
613 From: sender21@localhost
621 test_mhmail
"$expected" '-from sender21@localhost' -b 'no newline in input'
622 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
625 # check with text and multiple trailing blank lines to -body
626 # Shows different behavior than compiled mhmail, which suppressed one
628 cat > "$expected" <<EOF
629 EHLO nosuchhost.example.com
630 MAIL FROM:<sender22@localhost>
631 RCPT TO:<recipient@example.com>
633 To: recipient@example.com
634 From: sender22@localhost
644 test_mhmail
"$expected" '-from sender22@localhost' -b "here's some text
647 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
651 # Verified same behavior as compiled mhmail.
652 cat > "$expected" <<EOF
653 EHLO nosuchhost.example.com
654 MAIL FROM:<orig_recipient@example.com>
655 RCPT TO:<recipient@example.com>
657 Resent-To: recipient@example.com
658 Resent-From: orig_recipient@example.com
659 To: recipient@example.com
660 From: sender23@localhost
664 please resend this message, 1
669 test_mhmail
"$expected" '-from orig_recipient@example.com -resent' \
670 -b 'To: recipient@example.com
671 From: sender23@localhost
672 Date: Sat Jun 16 18:35:15 -0500
674 please resend this message, 1'
676 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
678 # check -resent -profile, using stdin
679 # Not supported by compiled mhmail.
680 cat > "$expected" <<EOF
681 EHLO nosuchhost.example.com
682 MAIL FROM:<orig_recipient@example.com>
683 RCPT TO:<recipient@example.com>
685 To: recipient@example.com
686 From: sender24@localhost
688 Resent-To: recipient@example.com
689 Resent-From: orig_recipient@example.com
692 please resend this message, 2
697 test_mhmail
"$expected" \
698 '-from orig_recipient@example.com -resent -profile -nomsgid' \
699 '|' 'To: recipient@example.com
700 From: sender24@localhost
701 Date: Sat Jun 16 18:35:15 -0500
703 please resend this message, 2'
705 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
708 # check -resent -profile, using -b
709 # Not supported by compiled mhmail.
710 cat > "$expected" <<EOF
711 EHLO nosuchhost.example.com
712 MAIL FROM:<orig_recipient@example.com>
713 RCPT TO:<recipient@example.com>
715 To: recipient@example.com
716 From: sender25@localhost
718 Resent-To: recipient@example.com
719 Resent-From: orig_recipient@example.com
722 please resend this message, 3
727 test_mhmail
"$expected" \
728 '-from orig_recipient@example.com -resent -profile -nomsgid' \
729 -b 'To: recipient@example.com
730 From: sender25@localhost
731 Date: Sat Jun 16 18:35:15 -0500
733 please resend this message, 3'
735 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
738 # check -headerfield.
739 # Not supported by compiled mhmail.
740 cat > "$expected" <<EOF
741 EHLO nosuchhost.example.com
742 MAIL FROM:<sender26@example.com>
743 RCPT TO:<recipient@example.com>
745 To: recipient@example.com
746 From: sender26@example.com
750 with added header field
755 test_mhmail
"$expected" \
756 '-from sender26@example.com -headerfield User-Agent:nmh' \
757 -b 'with added header field'
759 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
762 # check multiple -headerfields.
763 # Not supported by compiled mhmail.
764 cat > "$expected" <<EOF
765 EHLO nosuchhost.example.com
766 MAIL FROM:<sender27@example.com>
767 RCPT TO:<recipient@example.com>
769 To: recipient@example.com
770 From: sender27@example.com
772 Content-Type: text/plain;charset=utf-8
773 Content-Transfer-Encoding: 8bit
776 with added header fields
781 test_mhmail
"$expected" \
782 "-from sender27@example.com -headerfield MIME-Version:1.0 \
783 -headerfield Content-Type:text/plain;charset=utf-8 \
784 -headerfield Content-Transfer-Encoding:8bit" \
785 -b 'with added header fields'
787 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
791 # Not supported by compiled mhmail.
792 cat > "$expected" <<EOF
793 EHLO nosuchhost.example.com
794 MAIL FROM:<sender28@example.com>
795 RCPT TO:<recipient@example.com>
797 To: recipient@example.com
798 From: sender28@example.com
800 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
804 ------- =_aaaaaaaaaa0
805 Content-Type: text/plain; charset="us-ascii"
807 See how easy it is to add an attachment!
809 ------- =_aaaaaaaaaa0
810 Content-Type: `content_type_string ${srcdir}/test/mhmail/attachment.txt`
811 Content-Description: attachment.txt
812 Content-Disposition: attachment; filename="attachment.txt"
814 The future disappears into memory, With only a moment between,
815 Forever dwells in that moment, hope is what remains to be seen
816 Forever dwells in that moment, hope is what remains to be seen.
818 ------- =_aaaaaaaaaa0--
823 test_mhmail
"$expected" \
824 "-from sender28@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
825 -b 'See how easy it is to add an attachment!'
827 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}