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 sender1@localhost \
118 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
120 cat > "$expected" <<EOF
121 To: recipient@example.com
122 From: sender1@localhost
127 cat > "$expected_err" <<EOF
130 check
"$expected" "$actual"
131 check
"$expected_err" "$actual_err"
132 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
136 # Not supported by compiled mhmail.
137 cat > "$expected" <<EOF
138 EHLO nosuchhost.example.com
139 MAIL FROM:<sender2@localhost>
140 RCPT TO:<recipient@example.com>
142 To: recipient@example.com
143 From: sender2@localhost
151 test_mhmail
"$expected" "-from sender2@localhost -nosend -send" '|' message
152 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
156 # Verified same behavior as compiled mhmail.
157 cat > "$expected" <<EOF
158 EHLO nosuchhost.example.com
159 MAIL FROM:<sender3@localhost>
160 RCPT TO:<recipient@example.com>
162 To: recipient@example.com
163 From: sender3@localhost
171 test_mhmail
"$expected" "-from sender3@localhost" '|' message
172 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
175 # check -from and -body
176 # Verified same behavior as compiled mhmail.
177 cat > "$expected" <<EOF
178 EHLO nosuchhost.example.com
179 MAIL FROM:<sender4@localhost>
180 RCPT TO:<recipient@example.com>
182 To: recipient@example.com
183 From: sender4@localhost
191 test_mhmail
"$expected" "-from sender4@localhost" -b body
192 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
195 # check -from and -cc
196 # Verified same behavior as compiled mhmail.
197 cat > "$expected" <<EOF
198 EHLO nosuchhost.example.com
199 MAIL FROM:<sender5@localhost>
200 RCPT TO:<recipient@example.com>
201 RCPT TO:<recipient2@example.com>
203 To: recipient@example.com
204 Cc: recipient2@example.com
205 From: sender5@localhost
213 test_mhmail
"$expected" \
214 "-from sender5@localhost -cc recipient2@example.com" '|' message
215 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
218 # check -from and multiple -cc addresses
219 # Verified same behavior as compiled mhmail.
220 cat > "$expected" <<EOF
221 EHLO nosuchhost.example.com
222 MAIL FROM:<sender6@localhost>
223 RCPT TO:<recipient@example.com>
224 RCPT TO:<recipient2@example.com>
225 RCPT TO:<recipient3@example.com>
226 RCPT TO:<recipient4@example.com>
228 To: recipient@example.com
229 Cc: recipient2@example.com, recipient3@example.com,
230 recipient4@example.com
231 From: sender6@localhost
239 test_mhmail
"$expected" \
240 '-from sender6@localhost -cc recipient2@example.com '\
241 'recipient3@example.com recipient4@example.com' '|' message
242 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
245 # check -from and -subject
246 # Verified same behavior as compiled mhmail.
247 cat > "$expected" <<EOF
248 EHLO nosuchhost.example.com
249 MAIL FROM:<sender7@localhost>
250 RCPT TO:<recipient@example.com>
252 To: recipient@example.com
254 From: sender7@localhost
262 test_mhmail
"$expected" '-from sender7@localhost -subject Test' '|' message
263 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
266 # check -from and -profile
267 # Show that -profile causes mhmail to 1) read the profile and
268 # 2) use send(1) by added a send switch to the profile and
269 # verifying that it gets used.
270 # Not supported by compiled mhmail.
271 printf 'send: -msgid\n' >> $MH
273 cat > "$expected" <<EOF
274 EHLO nosuchhost.example.com
275 MAIL FROM:<sender8@localhost>
276 RCPT TO:<recipient@example.com>
278 To: recipient@example.com
279 From: sender8@localhost
288 test_mhmail
"$expected" '-from sender8@localhost -profile' '|' message
289 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
292 # check repeated -from and -subject switches
293 # Verified same behavior as compiled mhmail.
294 cat > "$expected" <<EOF
295 EHLO nosuchhost.example.com
296 MAIL FROM:<sender9@localhost>
297 RCPT TO:<recipient@example.com>
299 To: recipient@example.com
301 From: sender9@localhost
309 test_mhmail
"$expected" '-from sender9@localhost -from sender9@localhost '\
310 '-subject Subject1 -subject Subject2' -b message
311 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
313 # check repeated -body switches
314 # Verified same behavior as compiled mhmail.
315 cat > "$expected" <<EOF
316 EHLO nosuchhost.example.com
317 MAIL FROM:<sender10@localhost>
318 RCPT TO:<recipient@example.com>
320 To: recipient@example.com
321 From: sender10@localhost
329 test_mhmail
"$expected" "-from sender10@localhost -body body1" -b body2
330 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
333 # check multiple -cc switches
334 # Verified same behavior as compiled mhmail.
335 cat > "$expected" <<EOF
336 EHLO nosuchhost.example.com
337 MAIL FROM:<sender11@localhost>
338 RCPT TO:<recipient@example.com>
339 RCPT TO:<cc1@example.com>
340 RCPT TO:<cc2@example.com>
342 To: recipient@example.com
343 Cc: cc1@example.com, cc2@example.com
344 From: sender11@localhost
352 test_mhmail
"$expected" \
353 '-from sender11@localhost -cc cc1@example.com -cc cc2@example.com' -b message
354 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
357 # check separated -cc arguments
358 # Verified same behavior as compiled mhmail.
359 cat > "$expected" <<EOF
360 EHLO nosuchhost.example.com
361 MAIL FROM:<sender12@localhost>
362 RCPT TO:<recipient@example.com>
363 RCPT TO:<cc1@example.com>
364 RCPT TO:<cc2@example.com>
366 To: recipient@example.com
367 Cc: cc1@example.com, cc2@example.com
369 From: sender12@localhost
377 test_mhmail
"$expected" \
378 '-from sender12@localhost -cc cc1@example.com -subject '\
379 'Test cc2@example.com' -b message
380 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
383 # check -cc switch followed by -to switch
384 # Verified same behavior as compiled mhmail.
385 cat > "$expected" <<EOF
386 EHLO nosuchhost.example.com
387 MAIL FROM:<sender13@localhost>
388 RCPT TO:<recipient@example.com>
389 RCPT TO:<recipient2@example.com>
390 RCPT TO:<cc1@example.com>
392 To: recipient@example.com, recipient2@example.com
395 From: sender13@localhost
403 test_mhmail
"$expected" \
404 "-from sender13@localhost -cc cc1@example.com -subject Test \
405 -to recipient2@example.com" \
407 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
410 # check with no newline on stdin
411 # Shows different behavior than compiled mhmail, which was silent in this case.
412 cat > "$expected" <<EOF
415 cat > "$expected_err" <<EOF
416 mhmail: empty message not sent, use -body '' to force.
420 printf '' | mhmail recipient@example.com
-server 127.0.0.1 -port $localport \
421 >"$actual" 2>"$actual_err"
424 check
"$expected" "$actual"
425 check
"$expected_err" "$actual_err"
426 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
429 # check with one newline on stdin
430 # Verified same behavior as compiled mhmail.
431 cat > "$expected" <<EOF
432 EHLO nosuchhost.example.com
433 MAIL FROM:<sender14@localhost>
434 RCPT TO:<recipient@example.com>
436 To: recipient@example.com
437 From: sender14@localhost
445 test_mhmail
"$expected" '-from sender14@localhost' '|' '
447 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
450 # check with multiple newlines on stdin
451 # Verified same behavior as compiled mhmail.
452 cat > "$expected" <<EOF
453 EHLO nosuchhost.example.com
454 MAIL FROM:<sender15@localhost>
455 RCPT TO:<recipient@example.com>
457 To: recipient@example.com
458 From: sender15@localhost
468 test_mhmail
"$expected" '-from sender15@localhost' '|' '
472 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
475 # check with text and no trailing newline on stdin
476 # Verified same behavior as compiled mhmail.
477 cat > "$expected" <<EOF
478 EHLO nosuchhost.example.com
479 MAIL FROM:<sender16@localhost>
480 RCPT TO:<recipient@example.com>
482 To: recipient@example.com
483 From: sender16@localhost
491 test_mhmail
"$expected" '-from sender16@localhost' '|' 'no newline in input'
492 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
495 # check with text and multiple trailing blank lines on stdin
496 # Verified same behavior as compiled mhmail.
497 cat > "$expected" <<EOF
498 EHLO nosuchhost.example.com
499 MAIL FROM:<sender17@localhost>
500 RCPT TO:<recipient@example.com>
502 To: recipient@example.com
503 From: sender17@localhost
513 test_mhmail
"$expected" '-from sender17@localhost' '|' "here's some text
517 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
520 # check with no newline to -body
521 # Verified same behavior as compiled mhmail.
522 cat > "$expected" <<EOF
523 EHLO nosuchhost.example.com
524 MAIL FROM:<sender18@localhost>
525 RCPT TO:<recipient@example.com>
527 To: recipient@example.com
528 From: sender18@localhost
536 test_mhmail
"$expected" '-from sender18@localhost' -b ''
537 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
540 # check with one newline to -body
541 # Shows different behavior than compiled mhmail, which suppressed the newline.
542 cat > "$expected" <<EOF
543 EHLO nosuchhost.example.com
544 MAIL FROM:<sender19@localhost>
545 RCPT TO:<recipient@example.com>
547 To: recipient@example.com
548 From: sender19@localhost
557 test_mhmail
"$expected" '-from sender19@localhost' -b '
559 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
562 # check with multiple newlines to -body
563 # Shows different behavior than compiled mhmail, which suppressed one
565 cat > "$expected" <<EOF
566 EHLO nosuchhost.example.com
567 MAIL FROM:<sender20@localhost>
568 RCPT TO:<recipient@example.com>
570 To: recipient@example.com
571 From: sender20@localhost
582 test_mhmail
"$expected" '-from sender20@localhost' -b '
586 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
589 # check with text and no trailing newline to -body
590 # Verified same behavior as compiled mhmail.
591 cat > "$expected" <<EOF
592 EHLO nosuchhost.example.com
593 MAIL FROM:<sender21@localhost>
594 RCPT TO:<recipient@example.com>
596 To: recipient@example.com
597 From: sender21@localhost
605 test_mhmail
"$expected" '-from sender21@localhost' -b 'no newline in input'
606 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
609 # check with text and multiple trailing blank lines to -body
610 # Shows different behavior than compiled mhmail, which suppressed one
612 cat > "$expected" <<EOF
613 EHLO nosuchhost.example.com
614 MAIL FROM:<sender22@localhost>
615 RCPT TO:<recipient@example.com>
617 To: recipient@example.com
618 From: sender22@localhost
628 test_mhmail
"$expected" '-from sender22@localhost' -b "here's some text
631 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
635 # Verified same behavior as compiled mhmail.
636 cat > "$expected" <<EOF
637 EHLO nosuchhost.example.com
638 MAIL FROM:<orig_recipient@example.com>
639 RCPT TO:<recipient@example.com>
641 Resent-To: recipient@example.com
642 Resent-From: orig_recipient@example.com
643 To: recipient@example.com
644 From: sender23@localhost
648 please resend this message, 1
653 test_mhmail
"$expected" '-from orig_recipient@example.com -resent' \
654 -b 'To: recipient@example.com
655 From: sender23@localhost
656 Date: Sat Jun 16 18:35:15 -0500
658 please resend this message, 1'
660 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
662 # check -resent -profile, using stdin
663 # Not supported by compiled mhmail.
664 cat > "$expected" <<EOF
665 EHLO nosuchhost.example.com
666 MAIL FROM:<orig_recipient@example.com>
667 RCPT TO:<recipient@example.com>
669 To: recipient@example.com
670 From: sender24@localhost
672 Resent-To: recipient@example.com
673 Resent-From: orig_recipient@example.com
676 please resend this message, 2
681 test_mhmail
"$expected" \
682 '-from orig_recipient@example.com -resent -profile -nomsgid' \
683 '|' 'To: recipient@example.com
684 From: sender24@localhost
685 Date: Sat Jun 16 18:35:15 -0500
687 please resend this message, 2'
689 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
692 # check -resent -profile, using -b
693 # Not supported by compiled mhmail.
694 cat > "$expected" <<EOF
695 EHLO nosuchhost.example.com
696 MAIL FROM:<orig_recipient@example.com>
697 RCPT TO:<recipient@example.com>
699 To: recipient@example.com
700 From: sender25@localhost
702 Resent-To: recipient@example.com
703 Resent-From: orig_recipient@example.com
706 please resend this message, 3
711 test_mhmail
"$expected" \
712 '-from orig_recipient@example.com -resent -profile -nomsgid' \
713 -b 'To: recipient@example.com
714 From: sender25@localhost
715 Date: Sat Jun 16 18:35:15 -0500
717 please resend this message, 3'
719 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
722 # check -headerfield.
723 # Not supported by compiled mhmail.
724 cat > "$expected" <<EOF
725 EHLO nosuchhost.example.com
726 MAIL FROM:<sender26@example.com>
727 RCPT TO:<recipient@example.com>
729 To: recipient@example.com
730 From: sender26@example.com
734 with added header field
739 test_mhmail
"$expected" \
740 '-from sender26@example.com -headerfield User-Agent:nmh' \
741 -b 'with added header field'
743 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
746 # check multiple -headerfields.
747 # Not supported by compiled mhmail.
748 cat > "$expected" <<EOF
749 EHLO nosuchhost.example.com
750 MAIL FROM:<sender27@example.com>
751 RCPT TO:<recipient@example.com>
753 To: recipient@example.com
754 From: sender27@example.com
756 Content-Type: text/plain;charset=utf-8
757 Content-Transfer-Encoding: 8bit
760 with added header fields
765 test_mhmail
"$expected" \
766 "-from sender27@example.com -headerfield MIME-Version:1.0 \
767 -headerfield Content-Type:text/plain;charset=utf-8 \
768 -headerfield Content-Transfer-Encoding:8bit" \
769 -b 'with added header fields'
771 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
775 # Not supported by compiled mhmail.
776 cat > "$expected" <<EOF
777 EHLO nosuchhost.example.com
778 MAIL FROM:<sender28@example.com>
779 RCPT TO:<recipient@example.com>
781 To: recipient@example.com
782 From: sender28@example.com
784 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
788 ------- =_aaaaaaaaaa0
789 Content-Type: text/plain; charset="us-ascii"
791 See how easy it is to add an attachment!
793 ------- =_aaaaaaaaaa0
794 Content-Type: text/plain; name="attachment.txt"; charset="us-ascii"
795 Content-Description: attachment.txt
796 Content-Disposition: attachment; filename="attachment.txt"
798 The future disappears into memory, With only a moment between,
799 Forever dwells in that moment, hope is what remains to be seen
800 Forever dwells in that moment, hope is what remains to be seen.
802 ------- =_aaaaaaaaaa0--
807 test_mhmail
"$expected" \
808 "-from sender28@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \
809 -b 'See how easy it is to add an attachment!'
811 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}