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) Wrap charset value in double quotes. Assume that it isn't already.
26 `$MIMETYPEPROC $1 | sed -e 's/.*: *//' -e 's/\(charset=\)\(.*\)/\1"\2"/'`\
27 "; name=\"`basename $1`\""
31 # Customize test_post () for use with mhmail.
32 # $1 is expected output file, provided by caller
33 # $2 is mhmail switches, except for -body
34 # $3 of -b signifies use -body switch, | signifies provide body on stdin
35 # $4 contains the message body.
38 pid
=`"${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport`
41 printf '%s' "$4" | mhmail recipient@example.com
$2 \
42 -server 127.0.0.1 -port $localport
44 mhmail recipient@example.com
$2 -body "$4" \
45 -server 127.0.0.1 -port $localport
49 # It's hard to calculate the exact Date: header post is going to
50 # use, so we'll just use sed to remove the actual date so we can easily
51 # compare it against our "correct" output. And same for
55 sed -e 's/^Date:.*/Date:/' \
56 -e 's/^Resent-Date:.*/Resent-Date:/' \
57 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
60 check
"$actual".nodate
"$1"
63 expected
=$MH_TEST_DIR/test-mhmail$$.expected
64 expected_err
=$MH_TEST_DIR/test-mhmail$$.expected_err
65 actual
=$MH_TEST_DIR/test-mhmail$$.actual
66 actual_err
=$MH_TEST_DIR/test-mhmail$$.actual_err
70 # Verified behavior consistent with compiled sendmail.
72 Usage: mhmail [-t(o)] addrs ... [switches]
74 -at(tach) file [-at(tach) file] ...
78 -hea(derfield) name:value [-hea(derfield) name:value] ...
86 and all post(8)/send(1) switches
87 mhmail with no arguments is equivalent to inc
90 mhmail
-help >$actual 2>&1
91 check
$expected $actual
95 # Verified same behavior as compiled mhmail.
98 * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2
99 failed
=`expr ${failed:-0} + 1`;;
102 # check for missing argument to switches that require them
103 for switch
in attach body cc from headerfield subject to
; do
104 run_test
"mhmail recipient -$switch" \
105 "mhmail: missing argument to -$switch"
107 for switch
in attach body cc from headerfield subject to
; do
108 run_test
"mhmail recipient -$switch -nosend" \
109 "mhmail: missing argument to -$switch"
111 for switch
in attach body cc from headerfield subject to
; do
112 run_test
"mhmail recipient -$switch -server 127.0.0.1" \
113 "mhmail: missing argument to -$switch"
117 # check with no switches
118 # That will just run inc, which we don't want to do anything,
119 # so tell inc to just display its version.
120 # Verified same behavior as compiled mhmail.
121 printf 'inc: -version\n' >> $MH
124 * ) echo "$0: mhmail generated unexpected output" >&2
125 failed
=`expr ${failed:-0} + 1`;;
130 # Not supported by compiled mhmail.
131 mhmail
-nosend recipient@example.com
-from sender1@localhost \
132 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
134 cat > "$expected" <<EOF
135 To: recipient@example.com
136 From: sender1@localhost
141 cat > "$expected_err" <<EOF
144 check
"$expected" "$actual"
145 check
"$expected_err" "$actual_err"
146 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
150 # Not supported by compiled mhmail.
151 cat > "$expected" <<EOF
152 EHLO nosuchhost.example.com
153 MAIL FROM:<sender2@localhost>
154 RCPT TO:<recipient@example.com>
156 To: recipient@example.com
157 From: sender2@localhost
165 test_mhmail
"$expected" "-from sender2@localhost -nosend -send" '|' message
166 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
170 # Verified same behavior as compiled mhmail.
171 cat > "$expected" <<EOF
172 EHLO nosuchhost.example.com
173 MAIL FROM:<sender3@localhost>
174 RCPT TO:<recipient@example.com>
176 To: recipient@example.com
177 From: sender3@localhost
185 test_mhmail
"$expected" "-from sender3@localhost" '|' message
186 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
189 # check -from and -body
190 # Verified same behavior as compiled mhmail.
191 cat > "$expected" <<EOF
192 EHLO nosuchhost.example.com
193 MAIL FROM:<sender4@localhost>
194 RCPT TO:<recipient@example.com>
196 To: recipient@example.com
197 From: sender4@localhost
205 test_mhmail
"$expected" "-from sender4@localhost" -b body
206 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
209 # check -from and -cc
210 # Verified same behavior as compiled mhmail.
211 cat > "$expected" <<EOF
212 EHLO nosuchhost.example.com
213 MAIL FROM:<sender5@localhost>
214 RCPT TO:<recipient@example.com>
215 RCPT TO:<recipient2@example.com>
217 To: recipient@example.com
218 Cc: recipient2@example.com
219 From: sender5@localhost
227 test_mhmail
"$expected" \
228 "-from sender5@localhost -cc recipient2@example.com" '|' message
229 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
232 # check -from and multiple -cc addresses
233 # Verified same behavior as compiled mhmail.
234 cat > "$expected" <<EOF
235 EHLO nosuchhost.example.com
236 MAIL FROM:<sender6@localhost>
237 RCPT TO:<recipient@example.com>
238 RCPT TO:<recipient2@example.com>
239 RCPT TO:<recipient3@example.com>
240 RCPT TO:<recipient4@example.com>
242 To: recipient@example.com
243 Cc: recipient2@example.com, recipient3@example.com,
244 recipient4@example.com
245 From: sender6@localhost
253 test_mhmail
"$expected" \
254 '-from sender6@localhost -cc recipient2@example.com '\
255 'recipient3@example.com recipient4@example.com' '|' message
256 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
259 # check -from and -subject
260 # Verified same behavior as compiled mhmail.
261 cat > "$expected" <<EOF
262 EHLO nosuchhost.example.com
263 MAIL FROM:<sender7@localhost>
264 RCPT TO:<recipient@example.com>
266 To: recipient@example.com
268 From: sender7@localhost
276 test_mhmail
"$expected" '-from sender7@localhost -subject Test' '|' message
277 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
280 # check -from and -profile
281 # Show that -profile causes mhmail to 1) read the profile and
282 # 2) use send(1) by added a send switch to the profile and
283 # verifying that it gets used.
284 # Not supported by compiled mhmail.
285 printf 'send: -msgid\n' >> $MH
287 cat > "$expected" <<EOF
288 EHLO nosuchhost.example.com
289 MAIL FROM:<sender8@localhost>
290 RCPT TO:<recipient@example.com>
292 To: recipient@example.com
293 From: sender8@localhost
302 test_mhmail
"$expected" '-from sender8@localhost -profile' '|' message
303 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
306 # check repeated -from and -subject switches
307 # Verified same behavior as compiled mhmail.
308 cat > "$expected" <<EOF
309 EHLO nosuchhost.example.com
310 MAIL FROM:<sender9@localhost>
311 RCPT TO:<recipient@example.com>
313 To: recipient@example.com
315 From: sender9@localhost
323 test_mhmail
"$expected" '-from sender9@localhost -from sender9@localhost '\
324 '-subject Subject1 -subject Subject2' -b message
325 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
327 # check repeated -body switches
328 # Verified same behavior as compiled mhmail.
329 cat > "$expected" <<EOF
330 EHLO nosuchhost.example.com
331 MAIL FROM:<sender10@localhost>
332 RCPT TO:<recipient@example.com>
334 To: recipient@example.com
335 From: sender10@localhost
343 test_mhmail
"$expected" "-from sender10@localhost -body body1" -b body2
344 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
347 # check multiple -cc switches
348 # Verified same behavior as compiled mhmail.
349 cat > "$expected" <<EOF
350 EHLO nosuchhost.example.com
351 MAIL FROM:<sender11@localhost>
352 RCPT TO:<recipient@example.com>
353 RCPT TO:<cc1@example.com>
354 RCPT TO:<cc2@example.com>
356 To: recipient@example.com
357 Cc: cc1@example.com, cc2@example.com
358 From: sender11@localhost
366 test_mhmail
"$expected" \
367 '-from sender11@localhost -cc cc1@example.com -cc cc2@example.com' -b message
368 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
371 # check separated -cc arguments
372 # Verified same behavior as compiled mhmail.
373 cat > "$expected" <<EOF
374 EHLO nosuchhost.example.com
375 MAIL FROM:<sender12@localhost>
376 RCPT TO:<recipient@example.com>
377 RCPT TO:<cc1@example.com>
378 RCPT TO:<cc2@example.com>
380 To: recipient@example.com
381 Cc: cc1@example.com, cc2@example.com
383 From: sender12@localhost
391 test_mhmail
"$expected" \
392 '-from sender12@localhost -cc cc1@example.com -subject '\
393 'Test cc2@example.com' -b message
394 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
397 # check -cc switch followed by -to switch
398 # Verified same behavior as compiled mhmail.
399 cat > "$expected" <<EOF
400 EHLO nosuchhost.example.com
401 MAIL FROM:<sender13@localhost>
402 RCPT TO:<recipient@example.com>
403 RCPT TO:<recipient2@example.com>
404 RCPT TO:<cc1@example.com>
406 To: recipient@example.com, recipient2@example.com
409 From: sender13@localhost
417 test_mhmail
"$expected" \
418 "-from sender13@localhost -cc cc1@example.com -subject Test \
419 -to recipient2@example.com" \
421 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
424 # check with no newline on stdin
425 # Shows different behavior than compiled mhmail, which was silent in this case.
426 cat > "$expected" <<EOF
429 cat > "$expected_err" <<EOF
430 mhmail: empty message not sent, use -body '' to force.
434 printf '' | mhmail recipient@example.com
-server 127.0.0.1 -port $localport \
435 >"$actual" 2>"$actual_err"
438 check
"$expected" "$actual"
439 check
"$expected_err" "$actual_err"
440 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
443 # check with one newline on stdin
444 # Verified same behavior as compiled mhmail.
445 cat > "$expected" <<EOF
446 EHLO nosuchhost.example.com
447 MAIL FROM:<sender14@localhost>
448 RCPT TO:<recipient@example.com>
450 To: recipient@example.com
451 From: sender14@localhost
459 test_mhmail
"$expected" '-from sender14@localhost' '|' '
461 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
464 # check with multiple newlines on stdin
465 # Verified same behavior as compiled mhmail.
466 cat > "$expected" <<EOF
467 EHLO nosuchhost.example.com
468 MAIL FROM:<sender15@localhost>
469 RCPT TO:<recipient@example.com>
471 To: recipient@example.com
472 From: sender15@localhost
482 test_mhmail
"$expected" '-from sender15@localhost' '|' '
486 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
489 # check with text and no trailing newline on stdin
490 # Verified same behavior as compiled mhmail.
491 cat > "$expected" <<EOF
492 EHLO nosuchhost.example.com
493 MAIL FROM:<sender16@localhost>
494 RCPT TO:<recipient@example.com>
496 To: recipient@example.com
497 From: sender16@localhost
505 test_mhmail
"$expected" '-from sender16@localhost' '|' 'no newline in input'
506 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
509 # check with text and multiple trailing blank lines on stdin
510 # Verified same behavior as compiled mhmail.
511 cat > "$expected" <<EOF
512 EHLO nosuchhost.example.com
513 MAIL FROM:<sender17@localhost>
514 RCPT TO:<recipient@example.com>
516 To: recipient@example.com
517 From: sender17@localhost
527 test_mhmail
"$expected" '-from sender17@localhost' '|' "here's some text
531 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
534 # check with no newline to -body
535 # Verified same behavior as compiled mhmail.
536 cat > "$expected" <<EOF
537 EHLO nosuchhost.example.com
538 MAIL FROM:<sender18@localhost>
539 RCPT TO:<recipient@example.com>
541 To: recipient@example.com
542 From: sender18@localhost
550 test_mhmail
"$expected" '-from sender18@localhost' -b ''
551 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
554 # check with one newline to -body
555 # Shows different behavior than compiled mhmail, which suppressed the newline.
556 cat > "$expected" <<EOF
557 EHLO nosuchhost.example.com
558 MAIL FROM:<sender19@localhost>
559 RCPT TO:<recipient@example.com>
561 To: recipient@example.com
562 From: sender19@localhost
571 test_mhmail
"$expected" '-from sender19@localhost' -b '
573 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
576 # check with multiple newlines to -body
577 # Shows different behavior than compiled mhmail, which suppressed one
579 cat > "$expected" <<EOF
580 EHLO nosuchhost.example.com
581 MAIL FROM:<sender20@localhost>
582 RCPT TO:<recipient@example.com>
584 To: recipient@example.com
585 From: sender20@localhost
596 test_mhmail
"$expected" '-from sender20@localhost' -b '
600 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
603 # check with text and no trailing newline to -body
604 # Verified same behavior as compiled mhmail.
605 cat > "$expected" <<EOF
606 EHLO nosuchhost.example.com
607 MAIL FROM:<sender21@localhost>
608 RCPT TO:<recipient@example.com>
610 To: recipient@example.com
611 From: sender21@localhost
619 test_mhmail
"$expected" '-from sender21@localhost' -b 'no newline in input'
620 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
623 # check with text and multiple trailing blank lines to -body
624 # Shows different behavior than compiled mhmail, which suppressed one
626 cat > "$expected" <<EOF
627 EHLO nosuchhost.example.com
628 MAIL FROM:<sender22@localhost>
629 RCPT TO:<recipient@example.com>
631 To: recipient@example.com
632 From: sender22@localhost
642 test_mhmail
"$expected" '-from sender22@localhost' -b "here's some text
645 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
649 # Verified same behavior as compiled mhmail.
650 cat > "$expected" <<EOF
651 EHLO nosuchhost.example.com
652 MAIL FROM:<orig_recipient@example.com>
653 RCPT TO:<recipient@example.com>
655 Resent-To: recipient@example.com
656 Resent-From: orig_recipient@example.com
657 To: recipient@example.com
658 From: sender23@localhost
662 please resend this message, 1
667 test_mhmail
"$expected" '-from orig_recipient@example.com -resent' \
668 -b 'To: recipient@example.com
669 From: sender23@localhost
670 Date: Sat Jun 16 18:35:15 -0500
672 please resend this message, 1'
674 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
676 # check -resent -profile, using stdin
677 # Not supported by compiled mhmail.
678 cat > "$expected" <<EOF
679 EHLO nosuchhost.example.com
680 MAIL FROM:<orig_recipient@example.com>
681 RCPT TO:<recipient@example.com>
683 To: recipient@example.com
684 From: sender24@localhost
686 Resent-To: recipient@example.com
687 Resent-From: orig_recipient@example.com
690 please resend this message, 2
695 test_mhmail
"$expected" \
696 '-from orig_recipient@example.com -resent -profile -nomsgid' \
697 '|' 'To: recipient@example.com
698 From: sender24@localhost
699 Date: Sat Jun 16 18:35:15 -0500
701 please resend this message, 2'
703 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
706 # check -resent -profile, using -b
707 # Not supported by compiled mhmail.
708 cat > "$expected" <<EOF
709 EHLO nosuchhost.example.com
710 MAIL FROM:<orig_recipient@example.com>
711 RCPT TO:<recipient@example.com>
713 To: recipient@example.com
714 From: sender25@localhost
716 Resent-To: recipient@example.com
717 Resent-From: orig_recipient@example.com
720 please resend this message, 3
725 test_mhmail
"$expected" \
726 '-from orig_recipient@example.com -resent -profile -nomsgid' \
727 -b 'To: recipient@example.com
728 From: sender25@localhost
729 Date: Sat Jun 16 18:35:15 -0500
731 please resend this message, 3'
733 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
736 # check -headerfield.
737 # Not supported by compiled mhmail.
738 cat > "$expected" <<EOF
739 EHLO nosuchhost.example.com
740 MAIL FROM:<sender26@example.com>
741 RCPT TO:<recipient@example.com>
743 To: recipient@example.com
744 From: sender26@example.com
748 with added header field
753 test_mhmail
"$expected" \
754 '-from sender26@example.com -headerfield User-Agent:nmh' \
755 -b 'with added header field'
757 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
760 # check multiple -headerfields.
761 # Not supported by compiled mhmail.
762 cat > "$expected" <<EOF
763 EHLO nosuchhost.example.com
764 MAIL FROM:<sender27@example.com>
765 RCPT TO:<recipient@example.com>
767 To: recipient@example.com
768 From: sender27@example.com
770 Content-Type: text/plain;charset=utf-8
771 Content-Transfer-Encoding: 8bit
774 with added header fields
779 test_mhmail
"$expected" \
780 "-from sender27@example.com -headerfield MIME-Version:1.0 \
781 -headerfield Content-Type:text/plain;charset=utf-8 \
782 -headerfield Content-Transfer-Encoding:8bit" \
783 -b 'with added header fields'
785 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
789 # Not supported by compiled mhmail.
790 cat > "$expected" <<EOF
791 EHLO nosuchhost.example.com
792 MAIL FROM:<sender28@example.com>
793 RCPT TO:<recipient@example.com>
795 To: recipient@example.com
796 From: sender28@example.com
798 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
802 ------- =_aaaaaaaaaa0
803 Content-Type: text/plain; charset="us-ascii"
805 See how easy it is to add an attachment!
807 ------- =_aaaaaaaaaa0
808 Content-Type: `content_type_string ${srcdir}/test/mhmail/attachment.txt`
809 Content-Description: attachment.txt
810 Content-Disposition: attachment; filename="attachment.txt"
812 The future disappears into memory, With only a moment between,
813 Forever dwells in that moment, hope is what remains to be seen
814 Forever dwells in that moment, hope is what remains to be seen.
816 ------- =_aaaaaaaaaa0--
821 test_mhmail
"$expected" \
822 "-from sender28@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
823 -b 'See how easy it is to add an attachment!'
825 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}