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(derfield) name:value [-hea(derfield) name:value] ...
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`;;
105 # check for missing argument to switches that require them
106 for switch in attach body cc from headerfield subject; do
107 run_test "mhmail recipient -$switch" \
108 "mhmail: missing argument to -$switch"
110 for switch in attach body cc from headerfield subject; do
111 run_test "mhmail recipient -$switch -nosend" \
112 "mhmail: missing argument to -$switch"
114 for switch in attach body cc from headerfield subject; do
115 run_test "mhmail recipient -$switch -server 127.0.0.1" \
116 "mhmail: missing argument to -$switch"
120 # check with no arguments
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" 1>&2
128 failed=`expr ${failed:-0} + 1`;;
133 # Not supported by compiled mhmail.
134 mhmail -nosend recipient@example.com -from sender@localhost \
135 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
137 tmpfil=`head -1 $actual | sed -e 's/://'`
139 cat > "$expected" <<EOF
140 To: recipient@example.com
141 From: sender@localhost
146 cat > "$expected_err" <<EOF
149 check "$expected" "$actual"
150 check "$expected_err" "$actual_err"
151 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
155 # Not supported by compiled mhmail.
156 cat > "$expected" <<EOF
157 EHLO nosuchhost.example.com
158 MAIL FROM:<sender@localhost>
159 RCPT TO:<recipient@example.com>
161 To: recipient@example.com
162 From: sender@localhost
170 test_mhmail "$expected" "-from sender@localhost -nosend -send" '|' message
171 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
175 # Verified same behavior as compiled mhmail.
176 cat > "$expected" <<EOF
177 EHLO nosuchhost.example.com
178 MAIL FROM:<sender@localhost>
179 RCPT TO:<recipient@example.com>
181 To: recipient@example.com
182 From: sender@localhost
190 test_mhmail "$expected" "-from sender@localhost" '|' message
191 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
194 # check -from and -body
195 # Verified same behavior as compiled mhmail.
196 cat > "$expected" <<EOF
197 EHLO nosuchhost.example.com
198 MAIL FROM:<sender@localhost>
199 RCPT TO:<recipient@example.com>
201 To: recipient@example.com
202 From: sender@localhost
210 test_mhmail "$expected" "-from sender@localhost" -b body
211 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
214 # check -from and -cc
215 # Verified same behavior as compiled mhmail.
216 cat > "$expected" <<EOF
217 EHLO nosuchhost.example.com
218 MAIL FROM:<sender@localhost>
219 RCPT TO:<recipient@example.com>
220 RCPT TO:<recipient2@example.com>
222 To: recipient@example.com
223 Cc: recipient2@example.com
224 From: sender@localhost
232 test_mhmail "$expected" \
233 "-from sender@localhost -cc recipient2@example.com" '|' message
234 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
237 # check -from and multiple -cc addresses
238 # Verified same behavior as compiled mhmail.
239 cat > "$expected" <<EOF
240 EHLO nosuchhost.example.com
241 MAIL FROM:<sender@localhost>
242 RCPT TO:<recipient@example.com>
243 RCPT TO:<recipient2@example.com>
244 RCPT TO:<recipient3@example.com>
245 RCPT TO:<recipient4@example.com>
247 To: recipient@example.com
248 Cc: recipient2@example.com, recipient3@example.com,
249 recipient4@example.com
250 From: sender@localhost
258 test_mhmail "$expected" \
259 '-from sender@localhost -cc recipient2@example.com recipient3@example.com '\
260 'recipient4@example.com' '|' message
261 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
264 # check -from and -subject
265 # Verified same behavior as compiled mhmail.
266 cat > "$expected" <<EOF
267 EHLO nosuchhost.example.com
268 MAIL FROM:<sender@localhost>
269 RCPT TO:<recipient@example.com>
271 To: recipient@example.com
273 From: sender@localhost
281 test_mhmail "$expected" '-from sender@localhost -subject Test' '|' message
282 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
285 # check -from and -profile
286 # Show that -profile causes mhmail to 1) read the profile and
287 # 2) use send(1) by added a send switch to the profile and
288 # verifying that it gets used.
289 # Not supported by compiled mhmail.
290 printf "send: -msgid\n" >> $MH
292 cat > "$expected" <<EOF
293 EHLO nosuchhost.example.com
294 MAIL FROM:<sender@localhost>
295 RCPT TO:<recipient@example.com>
297 To: recipient@example.com
298 From: sender@localhost
307 test_mhmail "$expected" '-from sender@localhost -profile' '|' message
308 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
311 # check repeated -from and -subject arguments
312 # Verified same behavior as compiled mhmail.
313 cat > "$expected" <<EOF
314 EHLO nosuchhost.example.com
315 MAIL FROM:<sender2@localhost>
316 RCPT TO:<recipient@example.com>
318 To: recipient@example.com
320 From: sender2@localhost
328 test_mhmail "$expected" '-from sender@localhost -from sender2@localhost '\
329 '-subject Subject1 -subject Subject2' -b message
330 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
332 # check repeated -body arguments
333 # Verified same behavior as compiled mhmail.
334 cat > "$expected" <<EOF
335 EHLO nosuchhost.example.com
336 MAIL FROM:<sender@localhost>
337 RCPT TO:<recipient@example.com>
339 To: recipient@example.com
340 From: sender@localhost
348 test_mhmail "$expected" "-from sender@localhost -body body1" -b body2
349 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
352 # check multiple -cc arguments
353 # Verified same behavior as compiled mhmail.
354 cat > "$expected" <<EOF
355 EHLO nosuchhost.example.com
356 MAIL FROM:<sender@localhost>
357 RCPT TO:<recipient@example.com>
358 RCPT TO:<cc1@example.com>
359 RCPT TO:<cc2@example.com>
361 To: recipient@example.com
362 Cc: cc1@example.com, cc2@example.com
363 From: sender@localhost
371 test_mhmail "$expected" \
372 '-from sender@localhost -cc cc1@example.com -cc cc2@example.com' -b message
373 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
376 # check separated -cc arguments
377 # Verified same behavior as compiled mhmail.
378 cat > "$expected" <<EOF
379 EHLO nosuchhost.example.com
380 MAIL FROM:<sender@localhost>
381 RCPT TO:<recipient@example.com>
382 RCPT TO:<cc1@example.com>
383 RCPT TO:<cc2@example.com>
385 To: recipient@example.com
386 Cc: cc1@example.com, cc2@example.com
388 From: sender@localhost
396 test_mhmail "$expected" \
397 '-from sender@localhost -cc cc1@example.com -subject Test cc2@example.com' \
399 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
402 # check with no newline on stdin
403 # Shows different behavior than compiled mhmail, which was silent in this case.
404 cat > "$expected" <<EOF
407 cat > "$expected_err" <<EOF
408 mhmail: empty message not sent, use -body '' to force.
412 printf '' | mhmail recipient@example.com -server 127.0.0.1 -port $localport \
413 >"$actual" 2>"$actual_err"
416 check "$expected" "$actual"
417 check "$expected_err" "$actual_err"
418 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
421 # check with one newline on stdin
422 # Verified same behavior as compiled mhmail.
423 cat > "$expected" <<EOF
424 EHLO nosuchhost.example.com
425 MAIL FROM:<sender@localhost>
426 RCPT TO:<recipient@example.com>
428 To: recipient@example.com
429 From: sender@localhost
437 test_mhmail "$expected" '-from sender@localhost' '|' '\n'
438 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
441 # check with multiple newlines on stdin
442 # Verified same behavior as compiled mhmail.
443 cat > "$expected" <<EOF
444 EHLO nosuchhost.example.com
445 MAIL FROM:<sender@localhost>
446 RCPT TO:<recipient@example.com>
448 To: recipient@example.com
449 From: sender@localhost
459 test_mhmail "$expected" '-from sender@localhost' '|' '\n\n\n'
460 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
463 # check with text and no trailing newline on stdin
464 # Verified same behavior as compiled mhmail.
465 cat > "$expected" <<EOF
466 EHLO nosuchhost.example.com
467 MAIL FROM:<sender@localhost>
468 RCPT TO:<recipient@example.com>
470 To: recipient@example.com
471 From: sender@localhost
479 test_mhmail "$expected" '-from sender@localhost' '|' 'no newline in input'
480 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
483 # check with text and multiple trailing blank lines on stdin
484 # Verified same behavior as compiled mhmail.
485 cat > "$expected" <<EOF
486 EHLO nosuchhost.example.com
487 MAIL FROM:<sender@localhost>
488 RCPT TO:<recipient@example.com>
490 To: recipient@example.com
491 From: sender@localhost
501 test_mhmail "$expected" '-from sender@localhost' '|' "here's some text\n\n\n"
502 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
505 # check with no newline to -body
506 # Verified same behavior as compiled mhmail.
507 cat > "$expected" <<EOF
508 EHLO nosuchhost.example.com
509 MAIL FROM:<sender@localhost>
510 RCPT TO:<recipient@example.com>
512 To: recipient@example.com
513 From: sender@localhost
521 test_mhmail "$expected" '-from sender@localhost' -b ''
522 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
525 # check with one newline to -body
526 # Shows different behavior than compiled mhmail, which suppressed the newline.
527 cat > "$expected" <<EOF
528 EHLO nosuchhost.example.com
529 MAIL FROM:<sender@localhost>
530 RCPT TO:<recipient@example.com>
532 To: recipient@example.com
533 From: sender@localhost
542 test_mhmail "$expected" '-from sender@localhost' -b '
544 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
547 # check with multiple newlines to -body
548 # Shows different behavior than compiled mhmail, which suppressed one
550 cat > "$expected" <<EOF
551 EHLO nosuchhost.example.com
552 MAIL FROM:<sender@localhost>
553 RCPT TO:<recipient@example.com>
555 To: recipient@example.com
556 From: sender@localhost
567 test_mhmail "$expected" '-from sender@localhost' -b '
571 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
574 # check with text and no trailing newline to -body
575 # Verified same behavior as compiled mhmail.
576 cat > "$expected" <<EOF
577 EHLO nosuchhost.example.com
578 MAIL FROM:<sender@localhost>
579 RCPT TO:<recipient@example.com>
581 To: recipient@example.com
582 From: sender@localhost
590 test_mhmail "$expected" '-from sender@localhost' -b 'no newline in input'
591 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
594 # check with text and multiple trailing blank lines to -body
595 # Shows different behavior than compiled mhmail, which suppressed one
597 cat > "$expected" <<EOF
598 EHLO nosuchhost.example.com
599 MAIL FROM:<sender@localhost>
600 RCPT TO:<recipient@example.com>
602 To: recipient@example.com
603 From: sender@localhost
613 test_mhmail "$expected" '-from sender@localhost' -b "here's some text
616 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
620 # Verified same behavior as compiled mhmail.
621 cat > "$expected" <<EOF
622 EHLO nosuchhost.example.com
623 MAIL FROM:<orig_recipient@example.com>
624 RCPT TO:<recipient@example.com>
626 Resent-To: recipient@example.com
627 Resent-From: orig_recipient@example.com
628 To: recipient@example.com
629 From: sender@localhost
633 please resend this message, 1
638 test_mhmail "$expected" '-from orig_recipient@example.com -resent' \
639 -b 'To: recipient@example.com
640 From: sender@localhost
641 Date: Sat Jun 16 18:35:15 -0500
643 please resend this message, 1'
645 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
647 # check -resent -profile, using stdin
648 # Not supported by compiled mhmail.
649 cat > "$expected" <<EOF
650 EHLO nosuchhost.example.com
651 MAIL FROM:<orig_recipient@example.com>
652 RCPT TO:<recipient@example.com>
654 To: recipient@example.com
655 From: sender@localhost
657 Resent-To: recipient@example.com
658 Resent-From: orig_recipient@example.com
661 please resend this message, 2
666 test_mhmail "$expected" \
667 '-from orig_recipient@example.com -resent -profile -nomsgid' \
668 '|' 'To: recipient@example.com
669 From: sender@localhost
670 Date: Sat Jun 16 18:35:15 -0500
672 please resend this message, 2'
674 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
677 # check -resent -profile, using -b
678 # Not supported by compiled mhmail.
679 cat > "$expected" <<EOF
680 EHLO nosuchhost.example.com
681 MAIL FROM:<orig_recipient@example.com>
682 RCPT TO:<recipient@example.com>
684 To: recipient@example.com
685 From: sender@localhost
687 Resent-To: recipient@example.com
688 Resent-From: orig_recipient@example.com
691 please resend this message, 3
696 test_mhmail "$expected" \
697 '-from orig_recipient@example.com -resent -profile -nomsgid' \
698 -b 'To: recipient@example.com
699 From: sender@localhost
700 Date: Sat Jun 16 18:35:15 -0500
702 please resend this message, 3'
704 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
707 # check -headerfield.
708 # Not supported by compiled mhmail.
709 cat > "$expected" <<EOF
710 EHLO nosuchhost.example.com
711 MAIL FROM:<sender@example.com>
712 RCPT TO:<recipient@example.com>
714 To: recipient@example.com
715 From: sender@example.com
719 with added header field
724 test_mhmail "$expected" \
725 '-from sender@example.com -headerfield User-Agent:nmh' \
726 -b 'with added header field'
728 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
731 # check multiple -headerfields.
732 # Not supported by compiled mhmail.
733 cat > "$expected" <<EOF
734 EHLO nosuchhost.example.com
735 MAIL FROM:<sender@example.com>
736 RCPT TO:<recipient@example.com>
738 To: recipient@example.com
739 From: sender@example.com
741 Content-Type: text/plain;charset=utf-8
742 Content-Transfer-Encoding: 8bit
745 with added header fields
750 test_mhmail "$expected" \
751 "-from sender@example.com -headerfield MIME-Version:1.0 \
752 -headerfield Content-Type:text/plain;charset=utf-8 \
753 -headerfield Content-Transfer-Encoding:8bit" \
754 -b 'with added header fields'
756 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
760 # Not supported by compiled mhmail.
761 cat > "$expected" <<EOF
762 EHLO nosuchhost.example.com
763 MAIL FROM:<sender@example.com>
764 RCPT TO:<recipient@example.com>
766 To: recipient@example.com
767 From: sender@example.com
769 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
774 ------- =_aaaaaaaaaa0
775 Content-Type: text/plain; charset="us-ascii"
777 See how easy it is to add an attachment!
779 ------- =_aaaaaaaaaa0
780 Content-Type: text/plain; name="attachment.txt"; charset="us-ascii"
781 Content-Description: attachment.txt
782 Content-Disposition: attachment; filename="attachment.txt"
784 The future disappears into memory, With only a moment between,
785 Forever dwells in that moment, hope is what remains to be seen
786 Forever dwells in that moment, hope is what remains to be seen.
788 ------- =_aaaaaaaaaa0--
793 test_mhmail "$expected" \
794 "-from sender@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
795 -b 'See how easy it is to add an attachment!'
797 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}