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 #### Skip nmh intro text.
92 mhmail
-help | sed '/^$/Q' >"$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
297 Content-Type: text/plain; charset="us-ascii"
306 test_mhmail
"$expected" '-from sender8@localhost -profile' '|' message
307 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
310 # check repeated -from and -subject switches
311 # Verified same behavior as compiled mhmail.
312 cat > "$expected" <<EOF
313 EHLO nosuchhost.example.com
314 MAIL FROM:<sender9@localhost>
315 RCPT TO:<recipient@example.com>
317 To: recipient@example.com
319 From: sender9@localhost
327 test_mhmail
"$expected" '-from sender9@localhost -from sender9@localhost '\
328 '-subject Subject1 -subject Subject2' -b message
329 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
331 # check repeated -body switches
332 # Verified same behavior as compiled mhmail.
333 cat > "$expected" <<EOF
334 EHLO nosuchhost.example.com
335 MAIL FROM:<sender10@localhost>
336 RCPT TO:<recipient@example.com>
338 To: recipient@example.com
339 From: sender10@localhost
347 test_mhmail
"$expected" "-from sender10@localhost -body body1" -b body2
348 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
351 # check multiple -cc switches
352 # Verified same behavior as compiled mhmail.
353 cat > "$expected" <<EOF
354 EHLO nosuchhost.example.com
355 MAIL FROM:<sender11@localhost>
356 RCPT TO:<recipient@example.com>
357 RCPT TO:<cc1@example.com>
358 RCPT TO:<cc2@example.com>
360 To: recipient@example.com
361 Cc: cc1@example.com, cc2@example.com
362 From: sender11@localhost
370 test_mhmail
"$expected" \
371 '-from sender11@localhost -cc cc1@example.com -cc cc2@example.com' -b message
372 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
375 # check separated -cc arguments
376 # Verified same behavior as compiled mhmail.
377 cat > "$expected" <<EOF
378 EHLO nosuchhost.example.com
379 MAIL FROM:<sender12@localhost>
380 RCPT TO:<recipient@example.com>
381 RCPT TO:<cc1@example.com>
382 RCPT TO:<cc2@example.com>
384 To: recipient@example.com
385 Cc: cc1@example.com, cc2@example.com
387 From: sender12@localhost
395 test_mhmail
"$expected" \
396 '-from sender12@localhost -cc cc1@example.com -subject '\
397 'Test cc2@example.com' -b message
398 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
401 # check -cc switch followed by -to switch
402 # Verified same behavior as compiled mhmail.
403 cat > "$expected" <<EOF
404 EHLO nosuchhost.example.com
405 MAIL FROM:<sender13@localhost>
406 RCPT TO:<recipient@example.com>
407 RCPT TO:<recipient2@example.com>
408 RCPT TO:<cc1@example.com>
410 To: recipient@example.com, recipient2@example.com
413 From: sender13@localhost
421 test_mhmail
"$expected" \
422 "-from sender13@localhost -cc cc1@example.com -subject Test \
423 -to recipient2@example.com" \
425 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
428 # check with no newline on stdin
429 # Shows different behavior than compiled mhmail, which was silent in this case.
430 cat > "$expected" <<EOF
433 cat > "$expected_err" <<EOF
434 mhmail: empty message not sent, use -body '' to force.
438 printf '' | mhmail recipient@example.com
-server 127.0.0.1 -port $localport \
439 >"$actual" 2>"$actual_err"
442 check
"$expected" "$actual"
443 check
"$expected_err" "$actual_err"
444 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
447 # check with one newline on stdin
448 # Verified same behavior as compiled mhmail.
449 cat > "$expected" <<EOF
450 EHLO nosuchhost.example.com
451 MAIL FROM:<sender14@localhost>
452 RCPT TO:<recipient@example.com>
454 To: recipient@example.com
455 From: sender14@localhost
463 test_mhmail
"$expected" '-from sender14@localhost' '|' '
465 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
468 # check with multiple newlines on stdin
469 # Verified same behavior as compiled mhmail.
470 cat > "$expected" <<EOF
471 EHLO nosuchhost.example.com
472 MAIL FROM:<sender15@localhost>
473 RCPT TO:<recipient@example.com>
475 To: recipient@example.com
476 From: sender15@localhost
486 test_mhmail
"$expected" '-from sender15@localhost' '|' '
490 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
493 # check with text and no trailing newline on stdin
494 # Verified same behavior as compiled mhmail.
495 cat > "$expected" <<EOF
496 EHLO nosuchhost.example.com
497 MAIL FROM:<sender16@localhost>
498 RCPT TO:<recipient@example.com>
500 To: recipient@example.com
501 From: sender16@localhost
509 test_mhmail
"$expected" '-from sender16@localhost' '|' 'no newline in input'
510 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
513 # check with text and multiple trailing blank lines on stdin
514 # Verified same behavior as compiled mhmail.
515 cat > "$expected" <<EOF
516 EHLO nosuchhost.example.com
517 MAIL FROM:<sender17@localhost>
518 RCPT TO:<recipient@example.com>
520 To: recipient@example.com
521 From: sender17@localhost
531 test_mhmail
"$expected" '-from sender17@localhost' '|' "here's some text
535 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
538 # check with no newline to -body
539 # Verified same behavior as compiled mhmail.
540 cat > "$expected" <<EOF
541 EHLO nosuchhost.example.com
542 MAIL FROM:<sender18@localhost>
543 RCPT TO:<recipient@example.com>
545 To: recipient@example.com
546 From: sender18@localhost
554 test_mhmail
"$expected" '-from sender18@localhost' -b ''
555 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
558 # check with one newline to -body
559 # Shows different behavior than compiled mhmail, which suppressed the newline.
560 cat > "$expected" <<EOF
561 EHLO nosuchhost.example.com
562 MAIL FROM:<sender19@localhost>
563 RCPT TO:<recipient@example.com>
565 To: recipient@example.com
566 From: sender19@localhost
575 test_mhmail
"$expected" '-from sender19@localhost' -b '
577 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
580 # check with multiple newlines to -body
581 # Shows different behavior than compiled mhmail, which suppressed one
583 cat > "$expected" <<EOF
584 EHLO nosuchhost.example.com
585 MAIL FROM:<sender20@localhost>
586 RCPT TO:<recipient@example.com>
588 To: recipient@example.com
589 From: sender20@localhost
600 test_mhmail
"$expected" '-from sender20@localhost' -b '
604 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
607 # check with text and no trailing newline to -body
608 # Verified same behavior as compiled mhmail.
609 cat > "$expected" <<EOF
610 EHLO nosuchhost.example.com
611 MAIL FROM:<sender21@localhost>
612 RCPT TO:<recipient@example.com>
614 To: recipient@example.com
615 From: sender21@localhost
623 test_mhmail
"$expected" '-from sender21@localhost' -b 'no newline in input'
624 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
627 # check with text and multiple trailing blank lines to -body
628 # Shows different behavior than compiled mhmail, which suppressed one
630 cat > "$expected" <<EOF
631 EHLO nosuchhost.example.com
632 MAIL FROM:<sender22@localhost>
633 RCPT TO:<recipient@example.com>
635 To: recipient@example.com
636 From: sender22@localhost
646 test_mhmail
"$expected" '-from sender22@localhost' -b "here's some text
649 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
653 # Verified same behavior as compiled mhmail.
654 cat > "$expected" <<EOF
655 EHLO nosuchhost.example.com
656 MAIL FROM:<orig_recipient@example.com>
657 RCPT TO:<recipient@example.com>
659 Resent-To: recipient@example.com
660 Resent-From: orig_recipient@example.com
661 To: recipient@example.com
662 From: sender23@localhost
666 please resend this message, 1
671 test_mhmail
"$expected" '-from orig_recipient@example.com -resent' \
672 -b 'To: recipient@example.com
673 From: sender23@localhost
674 Date: Sat Jun 16 18:35:15 -0500
676 please resend this message, 1'
678 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
680 # check -resent -profile, using stdin
681 # Not supported by compiled mhmail.
682 cat > "$expected" <<EOF
683 EHLO nosuchhost.example.com
684 MAIL FROM:<orig_recipient@example.com>
685 RCPT TO:<recipient@example.com>
687 To: recipient@example.com
688 From: sender24@localhost
690 Resent-To: recipient@example.com
691 Resent-From: orig_recipient@example.com
694 please resend this message, 2
699 test_mhmail
"$expected" \
700 '-from orig_recipient@example.com -resent -profile -nomsgid' \
701 '|' 'To: recipient@example.com
702 From: sender24@localhost
703 Date: Sat Jun 16 18:35:15 -0500
705 please resend this message, 2'
707 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
710 # check -resent -profile, using -b
711 # Not supported by compiled mhmail.
712 cat > "$expected" <<EOF
713 EHLO nosuchhost.example.com
714 MAIL FROM:<orig_recipient@example.com>
715 RCPT TO:<recipient@example.com>
717 To: recipient@example.com
718 From: sender25@localhost
720 Resent-To: recipient@example.com
721 Resent-From: orig_recipient@example.com
724 please resend this message, 3
729 test_mhmail
"$expected" \
730 '-from orig_recipient@example.com -resent -profile -nomsgid' \
731 -b 'To: recipient@example.com
732 From: sender25@localhost
733 Date: Sat Jun 16 18:35:15 -0500
735 please resend this message, 3'
737 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
740 # check -headerfield.
741 # Not supported by compiled mhmail.
742 cat > "$expected" <<EOF
743 EHLO nosuchhost.example.com
744 MAIL FROM:<sender26@example.com>
745 RCPT TO:<recipient@example.com>
747 To: recipient@example.com
748 From: sender26@example.com
752 with added header field
757 test_mhmail
"$expected" \
758 '-from sender26@example.com -headerfield User-Agent:nmh' \
759 -b 'with added header field'
761 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
764 # check multiple -headerfields.
765 # Not supported by compiled mhmail.
766 cat > "$expected" <<EOF
767 EHLO nosuchhost.example.com
768 MAIL FROM:<sender27@example.com>
769 RCPT TO:<recipient@example.com>
771 To: recipient@example.com
772 From: sender27@example.com
774 Content-Type: text/plain;charset=utf-8
775 Content-Transfer-Encoding: 8bit
778 with added header fields
783 test_mhmail
"$expected" \
784 "-from sender27@example.com -headerfield MIME-Version:1.0 \
785 -headerfield Content-Type:text/plain;charset=utf-8 \
786 -headerfield Content-Transfer-Encoding:8bit" \
787 -b 'with added header fields'
789 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
793 # Not supported by compiled mhmail.
794 cat > "$expected" <<EOF
795 EHLO nosuchhost.example.com
796 MAIL FROM:<sender28@example.com>
797 RCPT TO:<recipient@example.com>
799 To: recipient@example.com
800 From: sender28@example.com
802 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
806 ------- =_aaaaaaaaaa0
807 Content-Type: text/plain; charset="us-ascii"
809 See how easy it is to add an attachment!
811 ------- =_aaaaaaaaaa0
812 Content-Type: `content_type_string ${srcdir}/test/mhmail/attachment.txt`
813 Content-Description: attachment.txt
814 Content-Disposition: attachment; filename="attachment.txt"
816 The future disappears into memory, With only a moment between,
817 Forever dwells in that moment, hope is what remains to be seen
818 Forever dwells in that moment, hope is what remains to be seen.
820 ------- =_aaaaaaaaaa0--
825 test_mhmail
"$expected" \
826 "-from sender28@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
827 -b 'See how easy it is to add an attachment!'
829 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}