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
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 #### Skip nmh intro text.
93 mhmail
-help 2>&1 | sed '/^$/,$d' >"$actual"
94 check
"$expected" "$actual"
99 # Verified same behavior as compiled mhmail.
102 * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2
103 failed
=`expr ${failed:-0} + 1`;;
106 # check for missing argument to switches that require them
107 start_test
"for missing argument to switches that require them"
108 for switch
in attach body cc from headerfield subject to
; do
109 run_test
"mhmail recipient -$switch" \
110 "mhmail: missing argument to -$switch"
112 for switch
in attach body cc from headerfield subject to
; do
113 run_test
"mhmail recipient -$switch -nosend" \
114 "mhmail: missing argument to -$switch"
116 for switch
in attach body cc from headerfield subject to
; do
117 run_test
"mhmail recipient -$switch -server 127.0.0.1" \
118 "mhmail: missing argument to -$switch"
122 # check with no switches
123 start_test
"with no switches"
124 # That will just run inc, which we don't want to do anything,
125 # so tell inc to just display its version.
126 # Verified same behavior as compiled mhmail.
127 printf 'inc: -version\n' >> $MH
130 * ) echo "$0: mhmail generated unexpected output" >&2
131 failed
=`expr ${failed:-0} + 1`;;
137 # Not supported by compiled mhmail.
138 mhmail
-nosend recipient@example.com
-from sender1@localhost \
139 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
141 cat > "$expected" <<EOF
142 To: recipient@example.com
143 From: sender1@localhost
148 cat > "$expected_err" <<EOF
151 check
"$expected" "$actual"
152 check
"$expected_err" "$actual_err"
153 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
158 # Not supported by compiled mhmail.
159 cat > "$expected" <<EOF
160 EHLO nosuchhost.example.com
161 MAIL FROM:<sender2@localhost>
162 RCPT TO:<recipient@example.com>
164 To: recipient@example.com
165 From: sender2@localhost
173 test_mhmail
"$expected" "-from sender2@localhost -nosend -send" '|' message
174 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
179 # Verified same behavior as compiled mhmail.
180 cat > "$expected" <<EOF
181 EHLO nosuchhost.example.com
182 MAIL FROM:<sender3@localhost>
183 RCPT TO:<recipient@example.com>
185 To: recipient@example.com
186 From: sender3@localhost
194 test_mhmail
"$expected" "-from sender3@localhost" '|' message
195 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
198 # check -from and -body
199 start_test
"-from and -body"
200 # Verified same behavior as compiled mhmail.
201 cat > "$expected" <<EOF
202 EHLO nosuchhost.example.com
203 MAIL FROM:<sender4@localhost>
204 RCPT TO:<recipient@example.com>
206 To: recipient@example.com
207 From: sender4@localhost
215 test_mhmail
"$expected" "-from sender4@localhost" -b body
216 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
219 # check -from and -cc
220 start_test
"-from and -cc"
221 # Verified same behavior as compiled mhmail.
222 cat > "$expected" <<EOF
223 EHLO nosuchhost.example.com
224 MAIL FROM:<sender5@localhost>
225 RCPT TO:<recipient@example.com>
226 RCPT TO:<recipient2@example.com>
228 To: recipient@example.com
229 Cc: recipient2@example.com
230 From: sender5@localhost
238 test_mhmail
"$expected" \
239 "-from sender5@localhost -cc recipient2@example.com" '|' message
240 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
243 # check -from and multiple -cc addresses
244 start_test
"-from and multiple -cc addresses"
245 # Verified same behavior as compiled mhmail.
246 cat > "$expected" <<EOF
247 EHLO nosuchhost.example.com
248 MAIL FROM:<sender6@localhost>
249 RCPT TO:<recipient@example.com>
250 RCPT TO:<recipient2@example.com>
251 RCPT TO:<recipient3@example.com>
252 RCPT TO:<recipient4@example.com>
254 To: recipient@example.com
255 Cc: recipient2@example.com, recipient3@example.com,
256 recipient4@example.com
257 From: sender6@localhost
265 test_mhmail
"$expected" \
266 '-from sender6@localhost -cc recipient2@example.com '\
267 'recipient3@example.com recipient4@example.com' '|' message
268 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
271 # check -from and -subject
272 start_test
"-from and -subject"
273 # Verified same behavior as compiled mhmail.
274 cat > "$expected" <<EOF
275 EHLO nosuchhost.example.com
276 MAIL FROM:<sender7@localhost>
277 RCPT TO:<recipient@example.com>
279 To: recipient@example.com
281 From: sender7@localhost
289 test_mhmail
"$expected" '-from sender7@localhost -subject Test' '|' message
290 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
293 # check -from and -profile
294 start_test
"-from and -profile"
295 # Show that -profile causes mhmail to 1) read the profile and
296 # 2) use send(1) by added a send switch to the profile and
297 # verifying that it gets used.
298 # Not supported by compiled mhmail.
299 printf 'send: -msgid\n' >> $MH
301 cat > "$expected" <<EOF
302 EHLO nosuchhost.example.com
303 MAIL FROM:<sender8@localhost>
304 RCPT TO:<recipient@example.com>
306 To: recipient@example.com
307 From: sender8@localhost
309 Content-Type: text/plain; charset="us-ascii"
318 test_mhmail
"$expected" '-from sender8@localhost -profile' '|' message
319 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
322 # check repeated -from and -subject switches
323 start_test
"repeated -from and -subject switches"
324 # Verified same behavior as compiled mhmail.
325 cat > "$expected" <<EOF
326 EHLO nosuchhost.example.com
327 MAIL FROM:<sender9@localhost>
328 RCPT TO:<recipient@example.com>
330 To: recipient@example.com
332 From: sender9@localhost
340 test_mhmail
"$expected" '-from sender9@localhost -from sender9@localhost '\
341 '-subject Subject1 -subject Subject2' -b message
342 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
344 # check repeated -body switches
345 start_test
"repeated -body switches"
346 # Verified same behavior as compiled mhmail.
347 cat > "$expected" <<EOF
348 EHLO nosuchhost.example.com
349 MAIL FROM:<sender10@localhost>
350 RCPT TO:<recipient@example.com>
352 To: recipient@example.com
353 From: sender10@localhost
361 test_mhmail
"$expected" "-from sender10@localhost -body body1" -b body2
362 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
365 # check multiple -cc switches
366 start_test
"multiple -cc switches"
367 # Verified same behavior as compiled mhmail.
368 cat > "$expected" <<EOF
369 EHLO nosuchhost.example.com
370 MAIL FROM:<sender11@localhost>
371 RCPT TO:<recipient@example.com>
372 RCPT TO:<cc1@example.com>
373 RCPT TO:<cc2@example.com>
375 To: recipient@example.com
376 Cc: cc1@example.com, cc2@example.com
377 From: sender11@localhost
385 test_mhmail
"$expected" \
386 '-from sender11@localhost -cc cc1@example.com -cc cc2@example.com' -b message
387 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
390 # check separated -cc arguments
391 start_test
"separated -cc arguments"
392 # Verified same behavior as compiled mhmail.
393 cat > "$expected" <<EOF
394 EHLO nosuchhost.example.com
395 MAIL FROM:<sender12@localhost>
396 RCPT TO:<recipient@example.com>
397 RCPT TO:<cc1@example.com>
398 RCPT TO:<cc2@example.com>
400 To: recipient@example.com
401 Cc: cc1@example.com, cc2@example.com
403 From: sender12@localhost
411 test_mhmail
"$expected" \
412 '-from sender12@localhost -cc cc1@example.com -subject '\
413 'Test cc2@example.com' -b message
414 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
417 # check -cc switch followed by -to switch
418 start_test
"-cc switch followed by -to switch"
419 # Verified same behavior as compiled mhmail.
420 cat > "$expected" <<EOF
421 EHLO nosuchhost.example.com
422 MAIL FROM:<sender13@localhost>
423 RCPT TO:<recipient@example.com>
424 RCPT TO:<recipient2@example.com>
425 RCPT TO:<cc1@example.com>
427 To: recipient@example.com, recipient2@example.com
430 From: sender13@localhost
438 test_mhmail
"$expected" \
439 "-from sender13@localhost -cc cc1@example.com -subject Test \
440 -to recipient2@example.com" \
442 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
445 # check with no newline on stdin
446 start_test
"with no newline on stdin"
447 # Shows different behavior than compiled mhmail, which was silent in this case.
448 cat > "$expected" <<EOF
451 cat > "$expected_err" <<EOF
452 mhmail: empty message not sent, use -body '' to force.
456 printf '' | mhmail recipient@example.com
-server 127.0.0.1 -port $localport \
457 >"$actual" 2>"$actual_err"
460 check
"$expected" "$actual"
461 check
"$expected_err" "$actual_err"
462 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
465 # check with one newline on stdin
466 start_test
"with one newline on stdin"
467 # Verified same behavior as compiled mhmail.
468 cat > "$expected" <<EOF
469 EHLO nosuchhost.example.com
470 MAIL FROM:<sender14@localhost>
471 RCPT TO:<recipient@example.com>
473 To: recipient@example.com
474 From: sender14@localhost
482 test_mhmail
"$expected" '-from sender14@localhost' '|' '
484 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
487 # check with multiple newlines on stdin
488 start_test
"with multiple newlines on stdin"
489 # Verified same behavior as compiled mhmail.
490 cat > "$expected" <<EOF
491 EHLO nosuchhost.example.com
492 MAIL FROM:<sender15@localhost>
493 RCPT TO:<recipient@example.com>
495 To: recipient@example.com
496 From: sender15@localhost
506 test_mhmail
"$expected" '-from sender15@localhost' '|' '
510 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
513 # check with text and no trailing newline on stdin
514 start_test
"with text and no trailing newline on stdin"
515 # Verified same behavior as compiled mhmail.
516 cat > "$expected" <<EOF
517 EHLO nosuchhost.example.com
518 MAIL FROM:<sender16@localhost>
519 RCPT TO:<recipient@example.com>
521 To: recipient@example.com
522 From: sender16@localhost
530 test_mhmail
"$expected" '-from sender16@localhost' '|' 'no newline in input'
531 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
534 # check with text and multiple trailing blank lines on stdin
535 start_test
"with text and multiple trailing blank lines on stdin"
536 # Verified same behavior as compiled mhmail.
537 cat > "$expected" <<EOF
538 EHLO nosuchhost.example.com
539 MAIL FROM:<sender17@localhost>
540 RCPT TO:<recipient@example.com>
542 To: recipient@example.com
543 From: sender17@localhost
553 test_mhmail
"$expected" '-from sender17@localhost' '|' "here's some text
557 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
560 # check with no newline to -body
561 start_test
"with no newline to -body"
562 # Verified same behavior as compiled mhmail.
563 cat > "$expected" <<EOF
564 EHLO nosuchhost.example.com
565 MAIL FROM:<sender18@localhost>
566 RCPT TO:<recipient@example.com>
568 To: recipient@example.com
569 From: sender18@localhost
577 test_mhmail
"$expected" '-from sender18@localhost' -b ''
578 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
581 # check with one newline to -body
582 start_test
"with one newline to -body"
583 # Shows different behavior than compiled mhmail, which suppressed the newline.
584 cat > "$expected" <<EOF
585 EHLO nosuchhost.example.com
586 MAIL FROM:<sender19@localhost>
587 RCPT TO:<recipient@example.com>
589 To: recipient@example.com
590 From: sender19@localhost
599 test_mhmail
"$expected" '-from sender19@localhost' -b '
601 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
604 # check with multiple newlines to -body
605 start_test
"with multiple newlines to -body"
606 # Shows different behavior than compiled mhmail, which suppressed one
608 cat > "$expected" <<EOF
609 EHLO nosuchhost.example.com
610 MAIL FROM:<sender20@localhost>
611 RCPT TO:<recipient@example.com>
613 To: recipient@example.com
614 From: sender20@localhost
625 test_mhmail
"$expected" '-from sender20@localhost' -b '
629 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
632 # check with text and no trailing newline to -body
633 start_test
"with text and no trailing newline to -body"
634 # Verified same behavior as compiled mhmail.
635 cat > "$expected" <<EOF
636 EHLO nosuchhost.example.com
637 MAIL FROM:<sender21@localhost>
638 RCPT TO:<recipient@example.com>
640 To: recipient@example.com
641 From: sender21@localhost
649 test_mhmail
"$expected" '-from sender21@localhost' -b 'no newline in input'
650 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
653 # check with text and multiple trailing blank lines to -body
654 start_test
"with text and multiple trailing blank lines to -body"
655 # Shows different behavior than compiled mhmail, which suppressed one
657 cat > "$expected" <<EOF
658 EHLO nosuchhost.example.com
659 MAIL FROM:<sender22@localhost>
660 RCPT TO:<recipient@example.com>
662 To: recipient@example.com
663 From: sender22@localhost
673 test_mhmail
"$expected" '-from sender22@localhost' -b "here's some text
676 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
681 # Verified same behavior as 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 Resent-To: recipient@example.com
688 Resent-From: orig_recipient@example.com
689 To: recipient@example.com
690 From: sender23@localhost
694 please resend this message, 1
699 test_mhmail
"$expected" '-from orig_recipient@example.com -resent' \
700 -b 'To: recipient@example.com
701 From: sender23@localhost
702 Date: Sat Jun 16 18:35:15 -0500
704 please resend this message, 1'
706 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
708 # check -resent -profile, using stdin
709 start_test
"-resent -profile, using stdin"
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: sender24@localhost
719 Resent-To: recipient@example.com
720 Resent-From: orig_recipient@example.com
723 please resend this message, 2
728 test_mhmail
"$expected" \
729 '-from orig_recipient@example.com -resent -profile -nomsgid' \
730 '|' 'To: recipient@example.com
731 From: sender24@localhost
732 Date: Sat Jun 16 18:35:15 -0500
734 please resend this message, 2'
736 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
739 # check -resent -profile, using -b
740 start_test
"-resent -profile, using -b"
741 # Not supported by compiled mhmail.
742 cat > "$expected" <<EOF
743 EHLO nosuchhost.example.com
744 MAIL FROM:<orig_recipient@example.com>
745 RCPT TO:<recipient@example.com>
747 To: recipient@example.com
748 From: sender25@localhost
750 Resent-To: recipient@example.com
751 Resent-From: orig_recipient@example.com
754 please resend this message, 3
759 test_mhmail
"$expected" \
760 '-from orig_recipient@example.com -resent -profile -nomsgid' \
761 -b 'To: recipient@example.com
762 From: sender25@localhost
763 Date: Sat Jun 16 18:35:15 -0500
765 please resend this message, 3'
767 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
770 # check -headerfield.
771 start_test
"-headerfield."
772 # Not supported by compiled mhmail.
773 cat > "$expected" <<EOF
774 EHLO nosuchhost.example.com
775 MAIL FROM:<sender26@example.com>
776 RCPT TO:<recipient@example.com>
778 To: recipient@example.com
779 From: sender26@example.com
783 with added header field
788 test_mhmail
"$expected" \
789 '-from sender26@example.com -headerfield User-Agent:nmh' \
790 -b 'with added header field'
792 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
795 # check multiple -headerfields.
796 start_test
"multiple -headerfields."
797 # Not supported by compiled mhmail.
798 cat > "$expected" <<EOF
799 EHLO nosuchhost.example.com
800 MAIL FROM:<sender27@example.com>
801 RCPT TO:<recipient@example.com>
803 To: recipient@example.com
804 From: sender27@example.com
806 Content-Type: text/plain;charset=utf-8
807 Content-Transfer-Encoding: 7bit
810 with added header fields
815 test_mhmail
"$expected" \
816 "-from sender27@example.com -headerfield MIME-Version:1.0 \
817 -headerfield Content-Type:text/plain;charset=utf-8 \
818 -headerfield Content-Transfer-Encoding:7bit" \
819 -b 'with added header fields'
821 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
826 # Not supported by compiled mhmail.
827 cat > "$expected" <<EOF
828 EHLO nosuchhost.example.com
829 MAIL FROM:<sender28@example.com>
830 RCPT TO:<recipient@example.com>
832 To: recipient@example.com
833 From: sender28@example.com
835 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
839 ------- =_aaaaaaaaaa0
840 Content-Type: text/plain; charset="us-ascii"
842 See how easy it is to add an attachment!
844 ------- =_aaaaaaaaaa0
845 Content-Type: `content_type_string ${srcdir}/test/mhmail/attachment.txt`
846 Content-Description: attachment.txt
847 Content-Disposition: attachment; filename="attachment.txt"
849 The future disappears into memory, With only a moment between,
850 Forever dwells in that moment, hope is what remains to be seen
851 Forever dwells in that moment, hope is what remains to be seen.
853 ------- =_aaaaaaaaaa0--
858 test_mhmail
"$expected" \
859 "-from sender28@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
860 -b 'See how easy it is to add an attachment!'
862 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}