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 the message body.
24 pid=`"${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport`
27 printf '%s' "$4" | mhmail recipient@example.com $2 \
28 -server 127.0.0.1 -port $localport
30 mhmail recipient@example.com $2 -body "$4" \
31 -server 127.0.0.1 -port $localport
35 # It's hard to calculate the exact Date: header post is going to
36 # use, so we'll just use sed to remove the actual date so we can easily
37 # compare it against our "correct" output. And same for
41 sed -e 's/^Date:.*/Date:/' \
42 -e 's/^Resent-Date:.*/Resent-Date:/' \
43 -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate
46 check "$actual".nodate "$1"
49 expected=$MH_TEST_DIR/test-mhmail$$.expected
50 expected_err=$MH_TEST_DIR/test-mhmail$$.expected_err
51 actual=$MH_TEST_DIR/test-mhmail$$.actual
52 actual_err=$MH_TEST_DIR/test-mhmail$$.actual_err
56 # Verified behavior consistent with compiled sendmail.
58 Usage: mhmail [-t(o)] addrs ... [switches]
60 -at(tach) file [-at(tach) file] ...
64 -hea(derfield) name:value [-hea(derfield) name:value] ...
72 and all post(8)/send(1) switches
73 mhmail with no arguments is equivalent to inc
76 mhmail -help >$actual 2>&1
77 check $expected $actual
81 # Verified same behavior as compiled mhmail.
84 * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2
85 failed=`expr ${failed:-0} + 1`;;
88 # check for missing argument to switches that require them
89 for switch in attach body cc from headerfield subject to; do
90 run_test "mhmail recipient -$switch" \
91 "mhmail: missing argument to -$switch"
93 for switch in attach body cc from headerfield subject to; do
94 run_test "mhmail recipient -$switch -nosend" \
95 "mhmail: missing argument to -$switch"
97 for switch in attach body cc from headerfield subject to; do
98 run_test "mhmail recipient -$switch -server 127.0.0.1" \
99 "mhmail: missing argument to -$switch"
103 # check with no switches
104 # That will just run inc, which we don't want to do anything,
105 # so tell inc to just display its version.
106 # Verified same behavior as compiled mhmail.
107 printf 'inc: -version\n' >> $MH
110 * ) echo "$0: mhmail generated unexpected output" >&2
111 failed=`expr ${failed:-0} + 1`;;
116 # Not supported by compiled mhmail.
117 mhmail -nosend recipient@example.com -from sender@localhost \
118 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
120 tmpfil=`head -1 $actual | sed -e 's/://'`
122 cat > "$expected" <<EOF
123 To: recipient@example.com
124 From: sender@localhost
129 cat > "$expected_err" <<EOF
132 check "$expected" "$actual"
133 check "$expected_err" "$actual_err"
134 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
138 # Not supported by compiled mhmail.
139 cat > "$expected" <<EOF
140 EHLO nosuchhost.example.com
141 MAIL FROM:<sender@localhost>
142 RCPT TO:<recipient@example.com>
144 To: recipient@example.com
145 From: sender@localhost
153 test_mhmail "$expected" "-from sender@localhost -nosend -send" '|' message
154 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
158 # Verified same behavior as compiled mhmail.
159 cat > "$expected" <<EOF
160 EHLO nosuchhost.example.com
161 MAIL FROM:<sender@localhost>
162 RCPT TO:<recipient@example.com>
164 To: recipient@example.com
165 From: sender@localhost
173 test_mhmail "$expected" "-from sender@localhost" '|' message
174 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
177 # check -from and -body
178 # Verified same behavior as compiled mhmail.
179 cat > "$expected" <<EOF
180 EHLO nosuchhost.example.com
181 MAIL FROM:<sender@localhost>
182 RCPT TO:<recipient@example.com>
184 To: recipient@example.com
185 From: sender@localhost
193 test_mhmail "$expected" "-from sender@localhost" -b body
194 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
197 # check -from and -cc
198 # Verified same behavior as compiled mhmail.
199 cat > "$expected" <<EOF
200 EHLO nosuchhost.example.com
201 MAIL FROM:<sender@localhost>
202 RCPT TO:<recipient@example.com>
203 RCPT TO:<recipient2@example.com>
205 To: recipient@example.com
206 Cc: recipient2@example.com
207 From: sender@localhost
215 test_mhmail "$expected" \
216 "-from sender@localhost -cc recipient2@example.com" '|' message
217 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
220 # check -from and multiple -cc addresses
221 # Verified same behavior as compiled mhmail.
222 cat > "$expected" <<EOF
223 EHLO nosuchhost.example.com
224 MAIL FROM:<sender@localhost>
225 RCPT TO:<recipient@example.com>
226 RCPT TO:<recipient2@example.com>
227 RCPT TO:<recipient3@example.com>
228 RCPT TO:<recipient4@example.com>
230 To: recipient@example.com
231 Cc: recipient2@example.com, recipient3@example.com,
232 recipient4@example.com
233 From: sender@localhost
241 test_mhmail "$expected" \
242 '-from sender@localhost -cc recipient2@example.com recipient3@example.com '\
243 'recipient4@example.com' '|' message
244 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
247 # check -from and -subject
248 # Verified same behavior as compiled mhmail.
249 cat > "$expected" <<EOF
250 EHLO nosuchhost.example.com
251 MAIL FROM:<sender@localhost>
252 RCPT TO:<recipient@example.com>
254 To: recipient@example.com
256 From: sender@localhost
264 test_mhmail "$expected" '-from sender@localhost -subject Test' '|' message
265 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
268 # check -from and -profile
269 # Show that -profile causes mhmail to 1) read the profile and
270 # 2) use send(1) by added a send switch to the profile and
271 # verifying that it gets used.
272 # Not supported by compiled mhmail.
273 printf 'send: -msgid\n' >> $MH
275 cat > "$expected" <<EOF
276 EHLO nosuchhost.example.com
277 MAIL FROM:<sender@localhost>
278 RCPT TO:<recipient@example.com>
280 To: recipient@example.com
281 From: sender@localhost
290 test_mhmail "$expected" '-from sender@localhost -profile' '|' message
291 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
294 # check repeated -from and -subject switches
295 # Verified same behavior as compiled mhmail.
296 cat > "$expected" <<EOF
297 EHLO nosuchhost.example.com
298 MAIL FROM:<sender2@localhost>
299 RCPT TO:<recipient@example.com>
301 To: recipient@example.com
303 From: sender2@localhost
311 test_mhmail "$expected" '-from sender@localhost -from sender2@localhost '\
312 '-subject Subject1 -subject Subject2' -b message
313 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
315 # check repeated -body switches
316 # Verified same behavior as compiled mhmail.
317 cat > "$expected" <<EOF
318 EHLO nosuchhost.example.com
319 MAIL FROM:<sender@localhost>
320 RCPT TO:<recipient@example.com>
322 To: recipient@example.com
323 From: sender@localhost
331 test_mhmail "$expected" "-from sender@localhost -body body1" -b body2
332 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
335 # check multiple -cc switches
336 # Verified same behavior as compiled mhmail.
337 cat > "$expected" <<EOF
338 EHLO nosuchhost.example.com
339 MAIL FROM:<sender@localhost>
340 RCPT TO:<recipient@example.com>
341 RCPT TO:<cc1@example.com>
342 RCPT TO:<cc2@example.com>
344 To: recipient@example.com
345 Cc: cc1@example.com, cc2@example.com
346 From: sender@localhost
354 test_mhmail "$expected" \
355 '-from sender@localhost -cc cc1@example.com -cc cc2@example.com' -b message
356 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
359 # check separated -cc arguments
360 # Verified same behavior as compiled mhmail.
361 cat > "$expected" <<EOF
362 EHLO nosuchhost.example.com
363 MAIL FROM:<sender@localhost>
364 RCPT TO:<recipient@example.com>
365 RCPT TO:<cc1@example.com>
366 RCPT TO:<cc2@example.com>
368 To: recipient@example.com
369 Cc: cc1@example.com, cc2@example.com
371 From: sender@localhost
379 test_mhmail "$expected" \
380 '-from sender@localhost -cc cc1@example.com -subject Test cc2@example.com' \
382 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
385 # check -cc switch followed by -to switch
386 # Verified same behavior as compiled mhmail.
387 cat > "$expected" <<EOF
388 EHLO nosuchhost.example.com
389 MAIL FROM:<sender@localhost>
390 RCPT TO:<recipient@example.com>
391 RCPT TO:<recipient2@example.com>
392 RCPT TO:<cc1@example.com>
394 To: recipient@example.com, recipient2@example.com
397 From: sender@localhost
405 test_mhmail "$expected" \
406 "-from sender@localhost -cc cc1@example.com -subject Test \
407 -to recipient2@example.com" \
409 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
412 # check with no newline on stdin
413 # Shows different behavior than compiled mhmail, which was silent in this case.
414 cat > "$expected" <<EOF
417 cat > "$expected_err" <<EOF
418 mhmail: empty message not sent, use -body '' to force.
422 printf '' | mhmail recipient@example.com -server 127.0.0.1 -port $localport \
423 >"$actual" 2>"$actual_err"
426 check "$expected" "$actual"
427 check "$expected_err" "$actual_err"
428 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
431 # check with one newline on stdin
432 # Verified same behavior as compiled mhmail.
433 cat > "$expected" <<EOF
434 EHLO nosuchhost.example.com
435 MAIL FROM:<sender@localhost>
436 RCPT TO:<recipient@example.com>
438 To: recipient@example.com
439 From: sender@localhost
447 test_mhmail "$expected" '-from sender@localhost' '|' '
449 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
452 # check with multiple newlines on stdin
453 # Verified same behavior as compiled mhmail.
454 cat > "$expected" <<EOF
455 EHLO nosuchhost.example.com
456 MAIL FROM:<sender@localhost>
457 RCPT TO:<recipient@example.com>
459 To: recipient@example.com
460 From: sender@localhost
470 test_mhmail "$expected" '-from sender@localhost' '|' '
474 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
477 # check with text and no trailing newline on stdin
478 # Verified same behavior as compiled mhmail.
479 cat > "$expected" <<EOF
480 EHLO nosuchhost.example.com
481 MAIL FROM:<sender@localhost>
482 RCPT TO:<recipient@example.com>
484 To: recipient@example.com
485 From: sender@localhost
493 test_mhmail "$expected" '-from sender@localhost' '|' 'no newline in input'
494 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
497 # check with text and multiple trailing blank lines on stdin
498 # Verified same behavior as compiled mhmail.
499 cat > "$expected" <<EOF
500 EHLO nosuchhost.example.com
501 MAIL FROM:<sender@localhost>
502 RCPT TO:<recipient@example.com>
504 To: recipient@example.com
505 From: sender@localhost
515 test_mhmail "$expected" '-from sender@localhost' '|' "here's some text
519 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
522 # check with no newline to -body
523 # Verified same behavior as compiled mhmail.
524 cat > "$expected" <<EOF
525 EHLO nosuchhost.example.com
526 MAIL FROM:<sender@localhost>
527 RCPT TO:<recipient@example.com>
529 To: recipient@example.com
530 From: sender@localhost
538 test_mhmail "$expected" '-from sender@localhost' -b ''
539 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
542 # check with one newline to -body
543 # Shows different behavior than compiled mhmail, which suppressed the newline.
544 cat > "$expected" <<EOF
545 EHLO nosuchhost.example.com
546 MAIL FROM:<sender@localhost>
547 RCPT TO:<recipient@example.com>
549 To: recipient@example.com
550 From: sender@localhost
559 test_mhmail "$expected" '-from sender@localhost' -b '
561 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
564 # check with multiple newlines to -body
565 # Shows different behavior than compiled mhmail, which suppressed one
567 cat > "$expected" <<EOF
568 EHLO nosuchhost.example.com
569 MAIL FROM:<sender@localhost>
570 RCPT TO:<recipient@example.com>
572 To: recipient@example.com
573 From: sender@localhost
584 test_mhmail "$expected" '-from sender@localhost' -b '
588 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
591 # check with text and no trailing newline to -body
592 # Verified same behavior as compiled mhmail.
593 cat > "$expected" <<EOF
594 EHLO nosuchhost.example.com
595 MAIL FROM:<sender@localhost>
596 RCPT TO:<recipient@example.com>
598 To: recipient@example.com
599 From: sender@localhost
607 test_mhmail "$expected" '-from sender@localhost' -b 'no newline in input'
608 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
611 # check with text and multiple trailing blank lines to -body
612 # Shows different behavior than compiled mhmail, which suppressed one
614 cat > "$expected" <<EOF
615 EHLO nosuchhost.example.com
616 MAIL FROM:<sender@localhost>
617 RCPT TO:<recipient@example.com>
619 To: recipient@example.com
620 From: sender@localhost
630 test_mhmail "$expected" '-from sender@localhost' -b "here's some text
633 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
637 # Verified same behavior as compiled mhmail.
638 cat > "$expected" <<EOF
639 EHLO nosuchhost.example.com
640 MAIL FROM:<orig_recipient@example.com>
641 RCPT TO:<recipient@example.com>
643 Resent-To: recipient@example.com
644 Resent-From: orig_recipient@example.com
645 To: recipient@example.com
646 From: sender@localhost
650 please resend this message, 1
655 test_mhmail "$expected" '-from orig_recipient@example.com -resent' \
656 -b 'To: recipient@example.com
657 From: sender@localhost
658 Date: Sat Jun 16 18:35:15 -0500
660 please resend this message, 1'
662 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
664 # check -resent -profile, using stdin
665 # Not supported by compiled mhmail.
666 cat > "$expected" <<EOF
667 EHLO nosuchhost.example.com
668 MAIL FROM:<orig_recipient@example.com>
669 RCPT TO:<recipient@example.com>
671 To: recipient@example.com
672 From: sender@localhost
674 Resent-To: recipient@example.com
675 Resent-From: orig_recipient@example.com
678 please resend this message, 2
683 test_mhmail "$expected" \
684 '-from orig_recipient@example.com -resent -profile -nomsgid' \
685 '|' 'To: recipient@example.com
686 From: sender@localhost
687 Date: Sat Jun 16 18:35:15 -0500
689 please resend this message, 2'
691 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
694 # check -resent -profile, using -b
695 # Not supported by compiled mhmail.
696 cat > "$expected" <<EOF
697 EHLO nosuchhost.example.com
698 MAIL FROM:<orig_recipient@example.com>
699 RCPT TO:<recipient@example.com>
701 To: recipient@example.com
702 From: sender@localhost
704 Resent-To: recipient@example.com
705 Resent-From: orig_recipient@example.com
708 please resend this message, 3
713 test_mhmail "$expected" \
714 '-from orig_recipient@example.com -resent -profile -nomsgid' \
715 -b 'To: recipient@example.com
716 From: sender@localhost
717 Date: Sat Jun 16 18:35:15 -0500
719 please resend this message, 3'
721 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
724 # check -headerfield.
725 # Not supported by compiled mhmail.
726 cat > "$expected" <<EOF
727 EHLO nosuchhost.example.com
728 MAIL FROM:<sender@example.com>
729 RCPT TO:<recipient@example.com>
731 To: recipient@example.com
732 From: sender@example.com
736 with added header field
741 test_mhmail "$expected" \
742 '-from sender@example.com -headerfield User-Agent:nmh' \
743 -b 'with added header field'
745 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
748 # check multiple -headerfields.
749 # Not supported by compiled mhmail.
750 cat > "$expected" <<EOF
751 EHLO nosuchhost.example.com
752 MAIL FROM:<sender@example.com>
753 RCPT TO:<recipient@example.com>
755 To: recipient@example.com
756 From: sender@example.com
758 Content-Type: text/plain;charset=utf-8
759 Content-Transfer-Encoding: 8bit
762 with added header fields
767 test_mhmail "$expected" \
768 "-from sender@example.com -headerfield MIME-Version:1.0 \
769 -headerfield Content-Type:text/plain;charset=utf-8 \
770 -headerfield Content-Transfer-Encoding:8bit" \
771 -b 'with added header fields'
773 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
777 # Not supported by compiled mhmail.
778 cat > "$expected" <<EOF
779 EHLO nosuchhost.example.com
780 MAIL FROM:<sender@example.com>
781 RCPT TO:<recipient@example.com>
783 To: recipient@example.com
784 From: sender@example.com
786 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
790 ------- =_aaaaaaaaaa0
791 Content-Type: text/plain; charset="us-ascii"
793 See how easy it is to add an attachment!
795 ------- =_aaaaaaaaaa0
796 Content-Type: text/plain; name="attachment.txt"; charset="us-ascii"
797 Content-Description: attachment.txt
798 Content-Disposition: attachment; filename="attachment.txt"
800 The future disappears into memory, With only a moment between,
801 Forever dwells in that moment, hope is what remains to be seen
802 Forever dwells in that moment, hope is what remains to be seen.
804 ------- =_aaaaaaaaaa0--
809 test_mhmail "$expected" \
810 "-from sender@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
811 -b 'See how easy it is to add an attachment!'
813 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}