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 # Customize test_post () for use with mhmail.
18 # $1 is expected output file, provided by caller
19 # $2 is mhmail switches, except for -body
20 # $3 of -b signifies use -body switch, | signifies provide body on stdin
21 # $4 contains message body. When using stdin, can contain printf(1) format
25 "${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport &
28 # The server doesn't always come up fast enough, so sleep and
29 # retry a few times if it fails...
31 for i in 0 1 2 3 4 5 6 7 8 9; do
33 if printf "$4" | mhmail recipient@example.com $2 \
34 -server 127.0.0.1 -port $localport; then
39 if mhmail recipient@example.com $2 -body "$4" \
40 -server 127.0.0.1 -port $localport; then
47 [ $status -eq 0 ] || exit 1
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:/' \
61 -e 's/^Content-ID:.*/Content-ID:/' "$actual" > "$actual".nodate
64 check "$actual".nodate "$1"
67 expected=$MH_TEST_DIR/test-mhmail$$.expected
68 expected_err=$MH_TEST_DIR/test-mhmail$$.expected_err
69 actual=$MH_TEST_DIR/test-mhmail$$.actual
70 actual_err=$MH_TEST_DIR/test-mhmail$$.actual_err
74 # Verified behavior consistent with compiled sendmail.
76 Usage: mhmail [addrs ... [switches]]
78 -at(tach) file [-at(tach) file] ...
82 -hea(der-field) name:field [-hea(der-field) name:field] ...
90 and all post(8)/send(1) switches
93 mhmail -help >$actual 2>&1
94 check $expected $actual
98 # Verified same behavior as compiled mhmail.
101 * ) echo "$0: mhmail -v generated unexpected output" 1>&2
102 failed=`expr ${failed:-0} + 1`;;
106 # check with no arguments
107 # That will just run inc, which we don't want to do anything,
108 # so tell inc to just display its version.
109 # Verified same behavior as compiled mhmail.
110 printf "inc: -version\n" >> $MH
113 * ) echo "$0: mhmail generated unexpected output" 1>&2
114 failed=`expr ${failed:-0} + 1`;;
119 # Not supported by compiled mhmail.
120 mhmail -nosend recipient@example.com -from sender@localhost \
121 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
123 tmpfil=`head -1 $actual | sed -e 's/://'`
125 cat > "$expected" <<EOF
126 To: recipient@example.com
127 From: sender@localhost
132 cat > "$expected_err" <<EOF
135 check "$expected" "$actual"
136 check "$expected_err" "$actual_err"
137 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
141 # Not supported by compiled mhmail.
142 cat > "$expected" <<EOF
143 EHLO nosuchhost.example.com
144 MAIL FROM:<sender@localhost>
145 RCPT TO:<recipient@example.com>
147 To: recipient@example.com
148 From: sender@localhost
156 test_mhmail "$expected" "-from sender@localhost -nosend -send" '|' message
157 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
161 # Verified same behavior as compiled mhmail.
162 cat > "$expected" <<EOF
163 EHLO nosuchhost.example.com
164 MAIL FROM:<sender@localhost>
165 RCPT TO:<recipient@example.com>
167 To: recipient@example.com
168 From: sender@localhost
176 test_mhmail "$expected" "-from sender@localhost" '|' message
177 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
180 # check -from and -body
181 # Verified same behavior as compiled mhmail.
182 cat > "$expected" <<EOF
183 EHLO nosuchhost.example.com
184 MAIL FROM:<sender@localhost>
185 RCPT TO:<recipient@example.com>
187 To: recipient@example.com
188 From: sender@localhost
196 test_mhmail "$expected" "-from sender@localhost" -b body
197 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
200 # check -from and -cc
201 # Verified same behavior as compiled mhmail.
202 cat > "$expected" <<EOF
203 EHLO nosuchhost.example.com
204 MAIL FROM:<sender@localhost>
205 RCPT TO:<recipient@example.com>
206 RCPT TO:<recipient2@example.com>
208 To: recipient@example.com
209 Cc: recipient2@example.com
210 From: sender@localhost
218 test_mhmail "$expected" \
219 "-from sender@localhost -cc recipient2@example.com" '|' message
220 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
223 # check -from and multiple -cc addresses
224 # Verified same behavior as compiled mhmail.
225 cat > "$expected" <<EOF
226 EHLO nosuchhost.example.com
227 MAIL FROM:<sender@localhost>
228 RCPT TO:<recipient@example.com>
229 RCPT TO:<recipient2@example.com>
230 RCPT TO:<recipient3@example.com>
231 RCPT TO:<recipient4@example.com>
233 To: recipient@example.com
234 Cc: recipient2@example.com, recipient3@example.com,
235 recipient4@example.com
236 From: sender@localhost
244 test_mhmail "$expected" \
245 '-from sender@localhost -cc recipient2@example.com recipient3@example.com '\
246 'recipient4@example.com' '|' message
247 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
250 # check -from and -subject
251 # Verified same behavior as compiled mhmail.
252 cat > "$expected" <<EOF
253 EHLO nosuchhost.example.com
254 MAIL FROM:<sender@localhost>
255 RCPT TO:<recipient@example.com>
257 To: recipient@example.com
259 From: sender@localhost
267 test_mhmail "$expected" '-from sender@localhost -subject Test' '|' message
268 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
271 # check -from and -profile
272 # Show that -profile causes mhmail to 1) read the profile and
273 # 2) use send(1) by added a send switch to the profile and
274 # verifying that it gets used.
275 # Not supported by compiled mhmail.
276 printf "send: -msgid\n" >> $MH
278 cat > "$expected" <<EOF
279 EHLO nosuchhost.example.com
280 MAIL FROM:<sender@localhost>
281 RCPT TO:<recipient@example.com>
283 To: recipient@example.com
284 From: sender@localhost
293 test_mhmail "$expected" '-from sender@localhost -profile' '|' message
294 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
297 # check repeated -from and -subject arguments
298 # Verified same behavior as compiled mhmail.
299 cat > "$expected" <<EOF
300 EHLO nosuchhost.example.com
301 MAIL FROM:<sender2@localhost>
302 RCPT TO:<recipient@example.com>
304 To: recipient@example.com
306 From: sender2@localhost
314 test_mhmail "$expected" '-from sender@localhost -from sender2@localhost '\
315 '-subject Subject1 -subject Subject2' -b message
316 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
318 # check repeated -body arguments
319 # Verified same behavior as compiled mhmail.
320 cat > "$expected" <<EOF
321 EHLO nosuchhost.example.com
322 MAIL FROM:<sender@localhost>
323 RCPT TO:<recipient@example.com>
325 To: recipient@example.com
326 From: sender@localhost
334 test_mhmail "$expected" "-from sender@localhost -body body1" -b body2
335 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
338 # check multiple -cc arguments
339 # Verified same behavior as compiled mhmail.
340 cat > "$expected" <<EOF
341 EHLO nosuchhost.example.com
342 MAIL FROM:<sender@localhost>
343 RCPT TO:<recipient@example.com>
344 RCPT TO:<cc1@example.com>
345 RCPT TO:<cc2@example.com>
347 To: recipient@example.com
348 Cc: cc1@example.com, cc2@example.com
349 From: sender@localhost
357 test_mhmail "$expected" \
358 '-from sender@localhost -cc cc1@example.com -cc cc2@example.com' -b message
359 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
362 # check separated -cc arguments
363 # Verified same behavior as compiled mhmail.
364 cat > "$expected" <<EOF
365 EHLO nosuchhost.example.com
366 MAIL FROM:<sender@localhost>
367 RCPT TO:<recipient@example.com>
368 RCPT TO:<cc1@example.com>
369 RCPT TO:<cc2@example.com>
371 To: recipient@example.com
372 Cc: cc1@example.com, cc2@example.com
374 From: sender@localhost
382 test_mhmail "$expected" \
383 '-from sender@localhost -cc cc1@example.com -subject Test cc2@example.com' \
385 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
388 # check with no newline on stdin
389 # Shows different behavior than compiled mhmail, which was silent in this case.
390 cat > "$expected" <<EOF
393 cat > "$expected_err" <<EOF
394 mhmail: empty message not sent, use -body '' to force.
398 printf '' | mhmail recipient@example.com -server 127.0.0.1 -port $localport \
399 >"$actual" 2>"$actual_err"
402 check "$expected" "$actual"
403 check "$expected_err" "$actual_err"
404 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
407 # check with one newline on stdin
408 # Verified same behavior as compiled mhmail.
409 cat > "$expected" <<EOF
410 EHLO nosuchhost.example.com
411 MAIL FROM:<sender@localhost>
412 RCPT TO:<recipient@example.com>
414 To: recipient@example.com
415 From: sender@localhost
423 test_mhmail "$expected" '-from sender@localhost' '|' '\n'
424 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
427 # check with multiple newlines on stdin
428 # Verified same behavior as compiled mhmail.
429 cat > "$expected" <<EOF
430 EHLO nosuchhost.example.com
431 MAIL FROM:<sender@localhost>
432 RCPT TO:<recipient@example.com>
434 To: recipient@example.com
435 From: sender@localhost
445 test_mhmail "$expected" '-from sender@localhost' '|' '\n\n\n'
446 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
449 # check with text and no trailing newline on stdin
450 # Verified same behavior as compiled mhmail.
451 cat > "$expected" <<EOF
452 EHLO nosuchhost.example.com
453 MAIL FROM:<sender@localhost>
454 RCPT TO:<recipient@example.com>
456 To: recipient@example.com
457 From: sender@localhost
465 test_mhmail "$expected" '-from sender@localhost' '|' 'no newline in input'
466 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
469 # check with text and multiple trailing blank lines on stdin
470 # Verified same behavior as compiled mhmail.
471 cat > "$expected" <<EOF
472 EHLO nosuchhost.example.com
473 MAIL FROM:<sender@localhost>
474 RCPT TO:<recipient@example.com>
476 To: recipient@example.com
477 From: sender@localhost
487 test_mhmail "$expected" '-from sender@localhost' '|' "here's some text\n\n\n"
488 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
491 # check with no newline to -body
492 # Verified same behavior as compiled mhmail.
493 cat > "$expected" <<EOF
494 EHLO nosuchhost.example.com
495 MAIL FROM:<sender@localhost>
496 RCPT TO:<recipient@example.com>
498 To: recipient@example.com
499 From: sender@localhost
507 test_mhmail "$expected" '-from sender@localhost' -b ''
508 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
511 # check with one newline to -body
512 # Shows different behavior than compiled mhmail, which suppressed the newline.
513 cat > "$expected" <<EOF
514 EHLO nosuchhost.example.com
515 MAIL FROM:<sender@localhost>
516 RCPT TO:<recipient@example.com>
518 To: recipient@example.com
519 From: sender@localhost
528 test_mhmail "$expected" '-from sender@localhost' -b '
530 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
533 # check with multiple newlines to -body
534 # Shows different behavior than compiled mhmail, which suppressed one
536 cat > "$expected" <<EOF
537 EHLO nosuchhost.example.com
538 MAIL FROM:<sender@localhost>
539 RCPT TO:<recipient@example.com>
541 To: recipient@example.com
542 From: sender@localhost
553 test_mhmail "$expected" '-from sender@localhost' -b '
557 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
560 # check with text and no trailing newline to -body
561 # Verified same behavior as compiled mhmail.
562 cat > "$expected" <<EOF
563 EHLO nosuchhost.example.com
564 MAIL FROM:<sender@localhost>
565 RCPT TO:<recipient@example.com>
567 To: recipient@example.com
568 From: sender@localhost
576 test_mhmail "$expected" '-from sender@localhost' -b 'no newline in input'
577 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
580 # check with text and multiple trailing blank lines to -body
581 # Shows different behavior than compiled mhmail, which suppressed one
583 cat > "$expected" <<EOF
584 EHLO nosuchhost.example.com
585 MAIL FROM:<sender@localhost>
586 RCPT TO:<recipient@example.com>
588 To: recipient@example.com
589 From: sender@localhost
599 test_mhmail "$expected" '-from sender@localhost' -b "here's some text
602 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
606 # Verified same behavior as compiled mhmail.
607 cat > "$expected" <<EOF
608 EHLO nosuchhost.example.com
609 MAIL FROM:<orig_recipient@example.com>
610 RCPT TO:<recipient@example.com>
612 Resent-To: recipient@example.com
613 Resent-From: orig_recipient@example.com
614 To: recipient@example.com
615 From: sender@localhost
619 please resend this message, 1
624 test_mhmail "$expected" '-from orig_recipient@example.com -resent' \
625 -b 'To: recipient@example.com
626 From: sender@localhost
627 Date: Sat Jun 16 18:35:15 -0500
629 please resend this message, 1'
631 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
633 # check -resent -profile, using stdin
634 # Not supported by compiled mhmail.
635 cat > "$expected" <<EOF
636 EHLO nosuchhost.example.com
637 MAIL FROM:<orig_recipient@example.com>
638 RCPT TO:<recipient@example.com>
640 To: recipient@example.com
641 From: sender@localhost
643 Resent-To: recipient@example.com
644 Resent-From: orig_recipient@example.com
647 please resend this message, 2
652 test_mhmail "$expected" \
653 '-from orig_recipient@example.com -resent -profile -nomsgid' \
654 '|' 'To: recipient@example.com
655 From: sender@localhost
656 Date: Sat Jun 16 18:35:15 -0500
658 please resend this message, 2'
660 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
663 # check -resent -profile, using -b
664 # Not supported by compiled mhmail.
665 cat > "$expected" <<EOF
666 EHLO nosuchhost.example.com
667 MAIL FROM:<orig_recipient@example.com>
668 RCPT TO:<recipient@example.com>
670 To: recipient@example.com
671 From: sender@localhost
673 Resent-To: recipient@example.com
674 Resent-From: orig_recipient@example.com
677 please resend this message, 3
682 test_mhmail "$expected" \
683 '-from orig_recipient@example.com -resent -profile -nomsgid' \
684 -b 'To: recipient@example.com
685 From: sender@localhost
686 Date: Sat Jun 16 18:35:15 -0500
688 please resend this message, 3'
690 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
693 # check -header-field.
694 # Not supported by compiled mhmail.
695 cat > "$expected" <<EOF
696 EHLO nosuchhost.example.com
697 MAIL FROM:<sender@example.com>
698 RCPT TO:<recipient@example.com>
700 To: recipient@example.com
701 From: sender@example.com
705 with added header field
710 test_mhmail "$expected" \
711 '-from sender@example.com -header-field User-Agent:nmh' \
712 -b 'with added header field'
714 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
717 # check multiple -header-fields.
718 # Not supported by compiled mhmail.
719 cat > "$expected" <<EOF
720 EHLO nosuchhost.example.com
721 MAIL FROM:<sender@example.com>
722 RCPT TO:<recipient@example.com>
724 To: recipient@example.com
725 From: sender@example.com
727 Content-Type: text/plain;charset=utf-8
728 Content-Transfer-Encoding: 8bit
731 with added header fields
736 test_mhmail "$expected" \
737 "-from sender@example.com -header-field MIME-Version:1.0 \
738 -header-field Content-Type:text/plain;charset=utf-8 \
739 -header-field Content-Transfer-Encoding:8bit" \
740 -b 'with added header fields'
742 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
746 # Not supported by compiled mhmail.
747 cat > "$expected" <<EOF
748 EHLO nosuchhost.example.com
749 MAIL FROM:<sender@example.com>
750 RCPT TO:<recipient@example.com>
752 To: recipient@example.com
753 From: sender@example.com
755 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
760 ------- =_aaaaaaaaaa0
761 Content-Type: text/plain; charset="us-ascii"
763 See how easy it is to add an attachment!
765 ------- =_aaaaaaaaaa0
766 Content-Type: text/plain; name="attachment.txt"; charset="us-ascii"
767 Content-Description: attachment.txt
768 Content-Disposition: attachment; filename="attachment.txt"
770 The future disappears into memory, With only a moment between,
771 Forever dwells in that moment, hope is what remains to be seen
772 Forever dwells in that moment, hope is what remains to be seen.
774 ------- =_aaaaaaaaaa0--
779 test_mhmail "$expected" \
780 "-from sender@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
781 -b 'See how easy it is to add an attachment!'
783 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}