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:/' "$actual" > "$actual".nodate
63 check "$actual".nodate "$1"
66 expected=$MH_TEST_DIR/test-mhmail$$.expected
67 expected_err=$MH_TEST_DIR/test-mhmail$$.expected_err
68 actual=$MH_TEST_DIR/test-mhmail$$.actual
69 actual_err=$MH_TEST_DIR/test-mhmail$$.actual_err
73 # Verified behavior consistent with compiled sendmail.
75 Usage: mhmail [addrs ... [switches]]
80 -hea(der-field) name:field [-hea(der-field) name:field] ...
88 and all post(8)/send(1) switches
91 mhmail -help >$actual 2>&1
92 check $expected $actual
96 # Verified same behavior as compiled mhmail.
99 * ) echo "$0: mhmail -v generated unexpected output" 1>&2
100 failed=`expr ${failed:-0} + 1`;;
104 # check with no arguments
105 # That will just run inc, which we don't want to do anything,
106 # so tell inc to just display its version.
107 # Verified same behavior as compiled mhmail.
108 printf "inc: -version\n" >> $MH
111 * ) echo "$0: mhmail generated unexpected output" 1>&2
112 failed=`expr ${failed:-0} + 1`;;
117 # Not supported by compiled mhmail.
118 mhmail -nosend recipient@example.com -from sender@localhost \
119 -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err"
121 tmpfil=`head -1 $actual | sed -e 's/://'`
123 cat > "$expected" <<EOF
124 To: recipient@example.com
125 From: sender@localhost
130 cat > "$expected_err" <<EOF
133 check "$expected" "$actual"
134 check "$expected_err" "$actual_err"
135 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
139 # Not supported by compiled mhmail.
140 cat > "$expected" <<EOF
141 EHLO nosuchhost.example.com
142 MAIL FROM:<sender@localhost>
143 RCPT TO:<recipient@example.com>
145 To: recipient@example.com
146 From: sender@localhost
154 test_mhmail "$expected" "-from sender@localhost -nosend -send" '|' message
155 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
159 # Verified same behavior as compiled mhmail.
160 cat > "$expected" <<EOF
161 EHLO nosuchhost.example.com
162 MAIL FROM:<sender@localhost>
163 RCPT TO:<recipient@example.com>
165 To: recipient@example.com
166 From: sender@localhost
174 test_mhmail "$expected" "-from sender@localhost" '|' message
175 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
178 # check -from and -body
179 # Verified same behavior as compiled mhmail.
180 cat > "$expected" <<EOF
181 EHLO nosuchhost.example.com
182 MAIL FROM:<sender@localhost>
183 RCPT TO:<recipient@example.com>
185 To: recipient@example.com
186 From: sender@localhost
194 test_mhmail "$expected" "-from sender@localhost" -b body
195 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
198 # check -from and -cc
199 # Verified same behavior as compiled mhmail.
200 cat > "$expected" <<EOF
201 EHLO nosuchhost.example.com
202 MAIL FROM:<sender@localhost>
203 RCPT TO:<recipient@example.com>
204 RCPT TO:<recipient2@example.com>
206 To: recipient@example.com
207 Cc: recipient2@example.com
208 From: sender@localhost
216 test_mhmail "$expected" \
217 "-from sender@localhost -cc recipient2@example.com" '|' message
218 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
221 # check -from and multiple -cc addresses
222 # Verified same behavior as compiled mhmail.
223 cat > "$expected" <<EOF
224 EHLO nosuchhost.example.com
225 MAIL FROM:<sender@localhost>
226 RCPT TO:<recipient@example.com>
227 RCPT TO:<recipient2@example.com>
228 RCPT TO:<recipient3@example.com>
229 RCPT TO:<recipient4@example.com>
231 To: recipient@example.com
232 Cc: recipient2@example.com, recipient3@example.com,
233 recipient4@example.com
234 From: sender@localhost
242 test_mhmail "$expected" \
243 '-from sender@localhost -cc recipient2@example.com recipient3@example.com '\
244 'recipient4@example.com' '|' message
245 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
248 # check -from and -subject
249 # Verified same behavior as compiled mhmail.
250 cat > "$expected" <<EOF
251 EHLO nosuchhost.example.com
252 MAIL FROM:<sender@localhost>
253 RCPT TO:<recipient@example.com>
255 To: recipient@example.com
257 From: sender@localhost
265 test_mhmail "$expected" '-from sender@localhost -subject Test' '|' message
266 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
269 # check -from and -profile
270 # Show that -profile causes mhmail to 1) read the profile and
271 # 2) use send(1) by added a send switch to the profile and
272 # verifying that it gets used.
273 # Not supported by compiled mhmail.
274 printf "send: -msgid\n" >> $MH
276 cat > "$expected" <<EOF
277 EHLO nosuchhost.example.com
278 MAIL FROM:<sender@localhost>
279 RCPT TO:<recipient@example.com>
281 To: recipient@example.com
282 From: sender@localhost
291 test_mhmail "$expected" '-from sender@localhost -profile' '|' message
292 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
295 # check repeated -from and -subject arguments
296 # Verified same behavior as compiled mhmail.
297 cat > "$expected" <<EOF
298 EHLO nosuchhost.example.com
299 MAIL FROM:<sender2@localhost>
300 RCPT TO:<recipient@example.com>
302 To: recipient@example.com
304 From: sender2@localhost
312 test_mhmail "$expected" '-from sender@localhost -from sender2@localhost '\
313 '-subject Subject1 -subject Subject2' -b message
314 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
316 # check repeated -body arguments
317 # Verified same behavior as compiled mhmail.
318 cat > "$expected" <<EOF
319 EHLO nosuchhost.example.com
320 MAIL FROM:<sender@localhost>
321 RCPT TO:<recipient@example.com>
323 To: recipient@example.com
324 From: sender@localhost
332 test_mhmail "$expected" "-from sender@localhost -body body1" -b body2
333 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
336 # check multiple -cc arguments
337 # Verified same behavior as compiled mhmail.
338 cat > "$expected" <<EOF
339 EHLO nosuchhost.example.com
340 MAIL FROM:<sender@localhost>
341 RCPT TO:<recipient@example.com>
342 RCPT TO:<cc1@example.com>
343 RCPT TO:<cc2@example.com>
345 To: recipient@example.com
346 Cc: cc1@example.com, cc2@example.com
347 From: sender@localhost
355 test_mhmail "$expected" \
356 '-from sender@localhost -cc cc1@example.com -cc cc2@example.com' -b message
357 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
360 # check separated -cc arguments
361 # Verified same behavior as compiled mhmail.
362 cat > "$expected" <<EOF
363 EHLO nosuchhost.example.com
364 MAIL FROM:<sender@localhost>
365 RCPT TO:<recipient@example.com>
366 RCPT TO:<cc1@example.com>
367 RCPT TO:<cc2@example.com>
369 To: recipient@example.com
370 Cc: cc1@example.com, cc2@example.com
372 From: sender@localhost
380 test_mhmail "$expected" \
381 '-from sender@localhost -cc cc1@example.com -subject Test cc2@example.com' \
383 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
386 # check with no newline on stdin
387 # Shows different behavior than compiled mhmail, which was silent in this case.
388 cat > "$expected" <<EOF
391 cat > "$expected_err" <<EOF
392 mhmail: empty message not sent, use -body '' to force.
396 printf '' | mhmail recipient@example.com -server 127.0.0.1 -port $localport \
397 >"$actual" 2>"$actual_err"
400 check "$expected" "$actual"
401 check "$expected_err" "$actual_err"
402 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
405 # check with one newline on stdin
406 # Verified same behavior as compiled mhmail.
407 cat > "$expected" <<EOF
408 EHLO nosuchhost.example.com
409 MAIL FROM:<sender@localhost>
410 RCPT TO:<recipient@example.com>
412 To: recipient@example.com
413 From: sender@localhost
421 test_mhmail "$expected" '-from sender@localhost' '|' '\n'
422 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
425 # check with multiple newlines on stdin
426 # Verified same behavior as compiled mhmail.
427 cat > "$expected" <<EOF
428 EHLO nosuchhost.example.com
429 MAIL FROM:<sender@localhost>
430 RCPT TO:<recipient@example.com>
432 To: recipient@example.com
433 From: sender@localhost
443 test_mhmail "$expected" '-from sender@localhost' '|' '\n\n\n'
444 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
447 # check with text and no trailing newline on stdin
448 # Verified same behavior as compiled mhmail.
449 cat > "$expected" <<EOF
450 EHLO nosuchhost.example.com
451 MAIL FROM:<sender@localhost>
452 RCPT TO:<recipient@example.com>
454 To: recipient@example.com
455 From: sender@localhost
463 test_mhmail "$expected" '-from sender@localhost' '|' 'no newline in input'
464 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
467 # check with text and multiple trailing blank lines on stdin
468 # Verified same behavior as compiled mhmail.
469 cat > "$expected" <<EOF
470 EHLO nosuchhost.example.com
471 MAIL FROM:<sender@localhost>
472 RCPT TO:<recipient@example.com>
474 To: recipient@example.com
475 From: sender@localhost
485 test_mhmail "$expected" '-from sender@localhost' '|' "here's some text\n\n\n"
486 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
489 # check with no newline to -body
490 # Verified same behavior as compiled mhmail.
491 cat > "$expected" <<EOF
492 EHLO nosuchhost.example.com
493 MAIL FROM:<sender@localhost>
494 RCPT TO:<recipient@example.com>
496 To: recipient@example.com
497 From: sender@localhost
505 test_mhmail "$expected" '-from sender@localhost' -b ''
506 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
509 # check with one newline to -body
510 # Shows different behavior than compiled mhmail, which suppressed the newline.
511 cat > "$expected" <<EOF
512 EHLO nosuchhost.example.com
513 MAIL FROM:<sender@localhost>
514 RCPT TO:<recipient@example.com>
516 To: recipient@example.com
517 From: sender@localhost
526 test_mhmail "$expected" '-from sender@localhost' -b '
528 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
531 # check with multiple newlines to -body
532 # Shows different behavior than compiled mhmail, which suppressed one
534 cat > "$expected" <<EOF
535 EHLO nosuchhost.example.com
536 MAIL FROM:<sender@localhost>
537 RCPT TO:<recipient@example.com>
539 To: recipient@example.com
540 From: sender@localhost
551 test_mhmail "$expected" '-from sender@localhost' -b '
555 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
558 # check with text and no trailing newline to -body
559 # Verified same behavior as compiled mhmail.
560 cat > "$expected" <<EOF
561 EHLO nosuchhost.example.com
562 MAIL FROM:<sender@localhost>
563 RCPT TO:<recipient@example.com>
565 To: recipient@example.com
566 From: sender@localhost
574 test_mhmail "$expected" '-from sender@localhost' -b 'no newline in input'
575 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
578 # check with text and multiple trailing blank lines to -body
579 # Shows different behavior than compiled mhmail, which suppressed one
581 cat > "$expected" <<EOF
582 EHLO nosuchhost.example.com
583 MAIL FROM:<sender@localhost>
584 RCPT TO:<recipient@example.com>
586 To: recipient@example.com
587 From: sender@localhost
597 test_mhmail "$expected" '-from sender@localhost' -b "here's some text
600 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
604 # Verified same behavior as compiled mhmail.
605 cat > "$expected" <<EOF
606 EHLO nosuchhost.example.com
607 MAIL FROM:<orig_recipient@example.com>
608 RCPT TO:<recipient@example.com>
610 Resent-To: recipient@example.com
611 Resent-From: orig_recipient@example.com
612 To: recipient@example.com
613 From: sender@localhost
617 please resend this message, #1
622 test_mhmail "$expected" '-from orig_recipient@example.com -resent' \
623 -b 'To: recipient@example.com
624 From: sender@localhost
625 Date: Sat Jun 16 18:35:15 -0500
627 please resend this message, #1'
629 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
631 # check -resent -profile, using stdin
632 # Not supported by compiled mhmail.
633 cat > "$expected" <<EOF
634 EHLO nosuchhost.example.com
635 MAIL FROM:<orig_recipient@example.com>
636 RCPT TO:<recipient@example.com>
638 To: recipient@example.com
639 From: sender@localhost
641 Resent-To: recipient@example.com
642 Resent-From: orig_recipient@example.com
645 please resend this message, #2
650 test_mhmail "$expected" \
651 '-from orig_recipient@example.com -resent -profile -nomsgid' \
652 '|' 'To: recipient@example.com
653 From: sender@localhost
654 Date: Sat Jun 16 18:35:15 -0500
656 please resend this message, #2'
658 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
661 # check -resent -profile, using -b
662 # Not supported by compiled mhmail.
663 cat > "$expected" <<EOF
664 EHLO nosuchhost.example.com
665 MAIL FROM:<orig_recipient@example.com>
666 RCPT TO:<recipient@example.com>
668 To: recipient@example.com
669 From: sender@localhost
671 Resent-To: recipient@example.com
672 Resent-From: orig_recipient@example.com
675 please resend this message, #3
680 test_mhmail "$expected" \
681 '-from orig_recipient@example.com -resent -profile -nomsgid' \
682 -b 'To: recipient@example.com
683 From: sender@localhost
684 Date: Sat Jun 16 18:35:15 -0500
686 please resend this message, #3'
688 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
691 # check -header-field.
692 # Not supported by compiled mhmail.
693 cat > "$expected" <<EOF
694 EHLO nosuchhost.example.com
695 MAIL FROM:<sender@example.com>
696 RCPT TO:<recipient@example.com>
698 To: recipient@example.com
699 From: sender@example.com
703 with added header field
708 test_mhmail "$expected" \
709 '-from sender@example.com -header-field User-Agent:nmh' \
710 -b 'with added header field'
712 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}
715 # check multiple -header-fields.
716 # Not supported by compiled mhmail.
717 cat > "$expected" <<EOF
718 EHLO nosuchhost.example.com
719 MAIL FROM:<sender@example.com>
720 RCPT TO:<recipient@example.com>
722 To: recipient@example.com
723 From: sender@example.com
725 Content-Type: text/plain;charset=utf-8
726 Content-Transfer-Encoding: 8bit
729 with added header fields
734 test_mhmail "$expected" \
735 "-from sender@example.com -header-field MIME-Version:1.0 \
736 -header-field Content-Type:text/plain;charset=utf-8 \
737 -header-field Content-Transfer-Encoding:8bit" \
738 -b 'with added header fields'
740 [ ${failed:-0} -eq 0 ] || exit ${failed:-0}