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 echo $MIMETYPEPROC; $MIMETYPEPROC $1 # temporary, for debugging on OpenBSD
21 ls -l dead.letter
; /bin
/rm -f dead.letter
# temporary, for debugging on OpenBSD
23 if test -z "$MIMETYPEPROC"; then
24 echo "text/plain; name=\"`basename $1`\"; charset=\"us-ascii\""
26 # 1) Excise leading filename followed by : and any whitespace.
27 # 2) Wrap charset value in double quotes. Assume that it isn't already.
29 `$MIMETYPEPROC $1 | sed -e 's/.*: *//' -e 's/\(charset=\)\(.*\)/\1"\2"/'`\
30 "; name=\"`basename $1`\""
34 # Customize test_post () for use with mhmail.
35 # $1 is expected output file, provided by caller
36 # $2 is mhmail switches, except for -body
37 # $3 of -b signifies use -body switch, | signifies provide body on stdin
38 # $4 contains the message body.
41 pid
=`"${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport`
44 printf '%s' "$4" | mhmail recipient@example.com
$2 \
45 -server 127.0.0.1 -port $localport
47 mhmail recipient@example.com
$2 -body "$4" \
48 -server 127.0.0.1 -port $localport
52 # It's hard to calculate the exact Date: header post is going to
53 # use, so we'll just use sed to remove the actual date so we can easily
54 # compare it against our "correct" output. And same for
58 sed -e 's/^Date:.*/Date:/' \
59 -e 's/^Resent-Date:.*/Resent-Date:/' \
60 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
63 check
"$actual".nodate
"$1"
66 expected
=$MH_TEST_DIR/test-mhmail$$.expected
67 expected_err
=$MH_TEST_DIR/test-mhmail$$.expected_err
68 actual
=$MH_TEST_DIR/test-mhmail$$.actual
69 actual_err
=$MH_TEST_DIR/test-mhmail$$.actual_err
73 # Verified behavior consistent with compiled sendmail.
75 Usage: mhmail [-t(o)] addrs ... [switches]
77 -at(tach) file [-at(tach) file] ...
81 -hea(derfield) name:value [-hea(derfield) name:value] ...
89 and all post(8)/send(1) switches
90 mhmail with no arguments is equivalent to inc
93 mhmail
-help >$actual 2>&1
94 check
$expected $actual
98 # Verified same behavior as compiled mhmail.
101 * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2
102 failed
=`expr ${failed:-0} + 1`;;
105 # check for missing argument to switches that require them
106 for switch
in attach body cc from headerfield subject to
; do
107 run_test
"mhmail recipient -$switch" \
108 "mhmail: missing argument to -$switch"
110 for switch
in attach body cc from headerfield subject to
; do
111 run_test
"mhmail recipient -$switch -nosend" \
112 "mhmail: missing argument to -$switch"
114 for switch
in attach body cc from headerfield subject to
; do
115 run_test
"mhmail recipient -$switch -server 127.0.0.1" \
116 "mhmail: missing argument to -$switch"
120 # check with no switches
121 # That will just run inc, which we don't want to do anything,
122 # so tell inc to just display its version.
123 # Verified same behavior as compiled mhmail.
124 printf 'inc: -version\n' >> $MH
127 * ) echo "$0: mhmail generated unexpected output" >&2
128 failed
=`expr ${failed:-0} + 1`;;
133 # Not supported by compiled mhmail.
134 mhmail
-nosend recipient@example.com
-from sender1@localhost \
135 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
137 cat > "$expected" <<EOF
138 To: recipient@example.com
139 From: sender1@localhost
144 cat > "$expected_err" <<EOF
147 check
"$expected" "$actual"
148 check
"$expected_err" "$actual_err"
149 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
153 # Not supported by compiled mhmail.
154 cat > "$expected" <<EOF
155 EHLO nosuchhost.example.com
156 MAIL FROM:<sender2@localhost>
157 RCPT TO:<recipient@example.com>
159 To: recipient@example.com
160 From: sender2@localhost
168 test_mhmail
"$expected" "-from sender2@localhost -nosend -send" '|' message
169 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
173 # Verified same behavior as compiled mhmail.
174 cat > "$expected" <<EOF
175 EHLO nosuchhost.example.com
176 MAIL FROM:<sender3@localhost>
177 RCPT TO:<recipient@example.com>
179 To: recipient@example.com
180 From: sender3@localhost
188 test_mhmail
"$expected" "-from sender3@localhost" '|' message
189 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
192 # check -from and -body
193 # Verified same behavior as compiled mhmail.
194 cat > "$expected" <<EOF
195 EHLO nosuchhost.example.com
196 MAIL FROM:<sender4@localhost>
197 RCPT TO:<recipient@example.com>
199 To: recipient@example.com
200 From: sender4@localhost
208 test_mhmail
"$expected" "-from sender4@localhost" -b body
209 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
212 # check -from and -cc
213 # Verified same behavior as compiled mhmail.
214 cat > "$expected" <<EOF
215 EHLO nosuchhost.example.com
216 MAIL FROM:<sender5@localhost>
217 RCPT TO:<recipient@example.com>
218 RCPT TO:<recipient2@example.com>
220 To: recipient@example.com
221 Cc: recipient2@example.com
222 From: sender5@localhost
230 test_mhmail
"$expected" \
231 "-from sender5@localhost -cc recipient2@example.com" '|' message
232 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
235 # check -from and multiple -cc addresses
236 # Verified same behavior as compiled mhmail.
237 cat > "$expected" <<EOF
238 EHLO nosuchhost.example.com
239 MAIL FROM:<sender6@localhost>
240 RCPT TO:<recipient@example.com>
241 RCPT TO:<recipient2@example.com>
242 RCPT TO:<recipient3@example.com>
243 RCPT TO:<recipient4@example.com>
245 To: recipient@example.com
246 Cc: recipient2@example.com, recipient3@example.com,
247 recipient4@example.com
248 From: sender6@localhost
256 test_mhmail
"$expected" \
257 '-from sender6@localhost -cc recipient2@example.com '\
258 'recipient3@example.com recipient4@example.com' '|' message
259 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
262 # check -from and -subject
263 # Verified same behavior as compiled mhmail.
264 cat > "$expected" <<EOF
265 EHLO nosuchhost.example.com
266 MAIL FROM:<sender7@localhost>
267 RCPT TO:<recipient@example.com>
269 To: recipient@example.com
271 From: sender7@localhost
279 test_mhmail
"$expected" '-from sender7@localhost -subject Test' '|' message
280 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
283 # check -from and -profile
284 # Show that -profile causes mhmail to 1) read the profile and
285 # 2) use send(1) by added a send switch to the profile and
286 # verifying that it gets used.
287 # Not supported by compiled mhmail.
288 printf 'send: -msgid\n' >> $MH
290 cat > "$expected" <<EOF
291 EHLO nosuchhost.example.com
292 MAIL FROM:<sender8@localhost>
293 RCPT TO:<recipient@example.com>
295 To: recipient@example.com
296 From: sender8@localhost
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}