From 880f5c3a2c6315b73ecb54f2ec4c1a71bb9d6741 Mon Sep 17 00:00:00 2001 From: David Levine Date: Sat, 16 Jun 2012 09:24:29 -0500 Subject: [PATCH] Replaced compiled mhmail with script that was formerly named mhmail.in. Added test-mhmail. --- .gitignore | 1 - Makefile.am | 10 +- docs/pending-release-notes | 7 + man/mhmail.man | 50 +++- test/post/test-mhmail | 581 ++++++++++++++++++++++++++++++++++++++++++++ uip/{mhmail.in => mhmail} | 0 6 files changed, 636 insertions(+), 13 deletions(-) create mode 100755 test/post/test-mhmail rename uip/{mhmail.in => mhmail} (100%) diff --git a/.gitignore b/.gitignore index 3e34897..4a05816 100644 --- a/.gitignore +++ b/.gitignore @@ -66,7 +66,6 @@ a.out.dSYM/ /uip/mhbuild /uip/mhl /uip/mhlist -/uip/mhmail /uip/mhn /uip/mhparam /uip/mhpath diff --git a/Makefile.am b/Makefile.am index 5e91c8a..93516da 100644 --- a/Makefile.am +++ b/Makefile.am @@ -63,7 +63,7 @@ TESTS = test/bad-input/test-header \ test/post/test-post-basic test/post/test-post-multiple \ test/post/test-post-dcc test/post/test-post-fcc \ test/post/test-post-multifrom test/post/test-post-envelope \ - test/post/test-post-group \ + test/post/test-post-group test/post/test-mhmail \ test/refile/test-refile \ test/repl/test-if-str test/repl/test-trailing-newline \ test/repl/test-multicomp \ @@ -113,13 +113,13 @@ BUILT_SOURCES = sbr/sigmsg.h ## bin_PROGRAMS = uip/ali uip/anno uip/burst uip/comp uip/dist uip/flist \ uip/folder uip/forw uip/inc uip/install-mh uip/mark \ - uip/mhbuild uip/mhlist uip/mhmail uip/mhn uip/mhparam \ + uip/mhbuild uip/mhlist uip/mhn uip/mhparam \ uip/mhpath uip/mhshow uip/mhstore uip/msgchk uip/msh uip/new \ uip/packf uip/pick uip/prompter uip/refile uip/repl uip/rmf \ uip/rmm uip/scan uip/send uip/show uip/sortm uip/whatnow \ uip/whom -bin_SCRIPTS = etc/sendfiles +bin_SCRIPTS = uip/mhmail etc/sendfiles ## ## This is all programs that get installed in the "lib" directory @@ -226,7 +226,7 @@ EXTRA_DIST = config/version.sh sbr/sigmsg.awk etc/mts.conf.in etc/sendfiles.in \ man/unseen.man man/whatnow.man man/whom.man \ test/README $(TESTS) test/inc/deb359167.mbox \ test/inc/fromline.txt test/inc/msgheader.txt test/inc/filler.txt \ - test/inc/md5sums test/post/test-post-common.sh \ + test/inc/md5sums test/post/test-post-common.sh uip/mhmail \ SPECS/nmh.spec SPECS/build-nmh-cygwin ## @@ -275,8 +275,6 @@ uip_mhlist_SOURCES = uip/mhlist.c uip/mhparse.c uip/mhcachesbr.c \ uip/md5.c uip_mhlist_LDADD = $(LDADD) $(TERMLIB) -uip_mhmail_SOURCES = uip/mhmail.c - uip_mhn_SOURCES = uip/mhn.c uip/mhparse.c uip/mhcachesbr.c uip/mhshowsbr.c \ uip/mhlistsbr.c uip/mhstoresbr.c uip/mhmisc.c uip/mhfree.c \ uip/termsbr.c uip/md5.c diff --git a/docs/pending-release-notes b/docs/pending-release-notes index 3e8fb6b..f12b408 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -7,6 +7,8 @@ NEW FEATURES - All nmh programs will now warn about multiple profile entries for the same component. In previous versions, all but the first were silently ignored. +- mhmail now supports all post(8) options, and optionally can use + send(1) with all of its options. ---------------------------- OBSOLETE/DEPRECATED FEATURES @@ -23,3 +25,8 @@ OBSOLETE/DEPRECATED FEATURES - Changed repl and dist default to -noatfile. The default of -atfile was deprecated in nmh 1.5. If there are no requests to maintain -atfile, it will be removed in the future. +- The undocumented -queue switch to mhmail has been removed. +- The undocumented -queue switch to post is deprecated/obsolete + and will be removed in the next release. It supports the + SMTP XQUE verb, which is obsolete according to + http://smtpfilter.sourceforge.net/esmtp.html diff --git a/man/mhmail.man b/man/mhmail.man index 261fbc7..5f243e7 100644 --- a/man/mhmail.man +++ b/man/mhmail.man @@ -19,8 +19,16 @@ mhmail \- send or read mail .IR addr ] .RB [ \-subject .IR subject ] +[switches\ for +.I post +\&... | +.RB [ \-profile +[switches\ for +.I send +\&...]] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] +.RB [ \-debug ] .ad .SH DESCRIPTION .B mhmail @@ -59,6 +67,16 @@ name of the temporary file as its argument to deliver the message to the specified user. .PP The +.B \-profile +switch instructs +.B mhmail +to use +.B send +instead of +.B post +to send the message. This allows use of the user's context and aliases. +.PP +The .B \-subject .I subject switch can be used to specify the @@ -74,15 +92,15 @@ line with the switch. If the standard input has zero length, .B mhmail -will not send the message. You can use the switch +will not send the message and return with status 1. You can use the switch .B \-body \*(lq\*(rq to force an empty message. .PP Normally, addresses appearing as arguments are put in the \*(lqTo:\*(rq field. If the .B \-cc -switch is used, all addresses following it are -placed in the \*(lqcc:\*(rq field. +switch is used, all addresses following it, even if there are +intervening switches, are placed in the \*(lqcc:\*(rq field. .PP By using .B \-from @@ -97,6 +115,22 @@ Naturally, .B post will fill\-in the \*(lqSender:\*(rq header correctly. +.PP +The +.B \-debug +option shows the draft file that would be posted/sent and the command +that would be used to post/send the draft, but does not post or send +it. +.PP +All other switches are passed on to +.B post +if +.B \-profile +is not used, or +.B send +if +.B \-profile +is used. .SH FILES .fc ^ ~ @@ -108,7 +142,7 @@ header correctly. .fi .SH "SEE ALSO" -inc(1), post(8) +inc(1), post(8), send(1) .SH DEFAULTS None @@ -118,4 +152,8 @@ If .B inc is invoked, then .BR inc 's -context changes occur. +context changes occur. With the +.B \-profile +switch, the context of +.B send +is used. diff --git a/test/post/test-mhmail b/test/post/test-mhmail new file mode 100755 index 0000000..08df557 --- /dev/null +++ b/test/post/test-mhmail @@ -0,0 +1,581 @@ +#!/bin/sh +###################################################### +# +# Test mhmail +# +###################################################### + +set -e + +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR +fi + +. "${srcdir}/test/post/test-post-common.sh" + +# Customize test_post () for use with mhmail. +# $1 is expected output file, provided by caller +# $2 is mhmail switches, except for -body +# $3 of -b signifies use -body switch, | signifies provide body on stdin +# $4 contains message body. When using stdin, can contain printf(1) format +# specifiers. +test_mhmail () +{ + "${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport & + pid="$!" + + # The server doesn't always come up fast enough, so sleep and + # retry a few times if it fails... + status=1 + for i in 0 1 2 3 4 5 6 7 8 9; do + if [ $3 = '|' ]; then + if printf "$4" | mhmail recipient@example.com $2 \ + -server 127.0.0.1 -port $localport; then + status=0 + break + fi + else + if mhmail recipient@example.com $2 -body "$4" \ + -server 127.0.0.1 -port $localport; then + status=0 + break + fi + fi + sleep 1 + done + [ $status -eq 0 ] || exit 1 + + wait ${pid} + + # + # It's hard to calculate the exact Date: header post is going to + # use, so we'll just use sed to remove the actual date so we can easily + # compare it against our "correct" output. And same for + # Message-ID. + # + + sed -e 's/^Date:.*/Date:/' \ + -e 's/^Message-ID:.*/Message-ID:/' "$actual" > "$actual".nodate + rm -f "$actual" + + check "$actual".nodate "$1" +} + +expected=$MH_TEST_DIR/test-mhmail$$.expected +expected_err=$MH_TEST_DIR/test-mhmail$$.expected_err +actual=$MH_TEST_DIR/test-mhmail$$.actual +actual_err=$MH_TEST_DIR/test-mhmail$$.actual_err + + +# check -help +# Verified behavior consistent with compiled sendmail. +cat >$expected <$actual 2>&1 +check $expected $actual + + +# check -version +# Verified same behavior as compiled mhmail. +case `mhmail -v` in + mhmail\ --*) ;; + * ) echo "$0: mhmail -v generated unexpected output" 1>&2 + failed=`expr ${failed:-0} + 1`;; +esac + + +# check with no arguments +# That will just run inc, which we don't want to do anything, +# so tell inc to just display its version. +# Verified same behavior as compiled mhmail. +printf "inc: -version\n" >> $MH +case `mhmail` in + inc\ --*) ;; + * ) echo "$0: mhmail generated unexpected output" 1>&2 + failed=`expr ${failed:-0} + 1`;; +esac + + +# check -debug +# Not supported by compiled mhmail. +mhmail -debug recipient@example.com -from sender@localhost \ + -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err" + +tmpfil=`head -1 $actual | sed -e 's/://'` + +cat > "$expected" < "$expected_err" < "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + +message +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost" '|' message +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check -from and -body +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + +body +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost" -b body +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check -from and -cc +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +RCPT TO: +DATA +To: recipient@example.com +Cc: recipient2@example.com +From: sender@localhost +Date: + +message +. +QUIT +EOF + +test_mhmail "$expected" \ + "-from sender@localhost -cc recipient2@example.com" '|' message +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check -from and multiple -cc addresses +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +RCPT TO: +RCPT TO: +RCPT TO: +DATA +To: recipient@example.com +Cc: recipient2@example.com, recipient3@example.com, + recipient4@example.com +From: sender@localhost +Date: + +message +. +QUIT +EOF + +test_mhmail "$expected" \ + "-from sender@localhost -cc recipient2@example.com recipient3@example.com recipient4@example.com" '|' message +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check -from and -subject +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +Subject: Test +From: sender@localhost +Date: + +message +. +QUIT +EOF + +test_mhmail "$expected" \ + "-from sender@localhost -subject Test" '|' message +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check -from and -profile +# Show that -profile causes mhmail to 1) read the profile and +# 2) use send(1) by added a send switch to the profile and +# verifying that it gets used. +# Not supported by compiled mhmail. +printf "send: -msgid\n" >> $MH + +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: +Message-ID: + +message +. +QUIT +EOF + +test_mhmail "$expected" \ + "-from sender@localhost -profile" '|' message +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check repeated -from and -subject arguments +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +Subject: Subject2 +From: sender2@localhost +Date: + +message +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost -from sender2@localhost \ +-subject Subject1 -subject Subject2" -b message +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + +# check repeated -body arguments +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + +body2 +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost -body body1" -b body2 +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check multiple -cc arguments +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +RCPT TO: +RCPT TO: +DATA +To: recipient@example.com +Cc: cc1@example.com, cc2@example.com +From: sender@localhost +Date: + +message +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost \ +-cc cc1@example.com -cc cc2@example.com" -b message +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check separated -cc arguments +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +RCPT TO: +RCPT TO: +DATA +To: recipient@example.com +Cc: cc1@example.com, cc2@example.com +Subject: Test +From: sender@localhost +Date: + +message +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost \ +-cc cc1@example.com -subject Test cc2@example.com" -b message +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check with no newline on stdin +# Shows different behavior than compiled mhmail, which was silent in this case. +cat > "$expected" < "$expected_err" <"$actual" 2>"$actual_err" +set -e + +check "$expected" "$actual" +check "$expected_err" "$actual_err" +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check with one newline on stdin +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + + +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost" '|' '\n' +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check with multiple newlines on stdin +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + + + + +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost" '|' '\n\n\n' +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check with text and no trailing newline on stdin +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + +no newline in input +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost" '|' 'no newline in input' +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check with text and multiple trailing blank lines on stdin +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + +here's some text + + +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost" '|' "here's some text\n\n\n" +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check with no newline to -body +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + + +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost" -b '' +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check with one newline to -body +# Shows different behavior than compiled mhmail, which suppressed the newline. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + + + +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost" -b ' +' +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check with multiple newlines to -body +# Shows different behavior than compiled mhmail, which suppressed one +# of the newlines. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + + + + + +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost" -b ' + + +' +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check with text and no trailing newline to -body +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + +no newline in input +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost" -b 'no newline in input' +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check with text and multiple trailing blank lines to -body +# Shows different behavior than compiled mhmail, which suppressed one +# of the newlines. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender@localhost +Date: + +here's some text + + +. +QUIT +EOF + +test_mhmail "$expected" "-from sender@localhost" -b "here's some text + +" +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +exit ${failed:-0} diff --git a/uip/mhmail.in b/uip/mhmail similarity index 100% rename from uip/mhmail.in rename to uip/mhmail -- 1.7.10.4