X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/4c3830a96cdc7f17576d986d440a08ead54bee7a..7540f02725475698a47046ebf4e55b3e8dea5ab6:/test/mhmail/test-mhmail?ds=inline diff --git a/test/mhmail/test-mhmail b/test/mhmail/test-mhmail index 422c647d..c3969578 100755 --- a/test/mhmail/test-mhmail +++ b/test/mhmail/test-mhmail @@ -14,39 +14,37 @@ fi . "${srcdir}/test/post/test-post-common.sh" +# Find MIME type string, using configured procs if available. +MIMETYPEPROC=`mhparam mimetypeproc` +MIMEENCODINGPROC=`mhparam mimeencodingproc` +content_type_string() { + if test -z "$MIMETYPEPROC" -o -z "$MIMEENCODINGPROC"; then + #### This should be the order of name and charset. + echo "text/plain; name=\"`basename $1`\"; charset=\"us-ascii\"" + else + #### Excise any leading filename followed by : and whitespace. + printf '%s; charset="%s"; name="%s"' \ + `$MIMETYPEPROC $1 | sed -e 's/.*: *//'` \ + `$MIMEENCODINGPROC $1 | sed -e 's/.*: *//'` `basename $1` + fi +} + # 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. +# $4 contains the message body. 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} + pid=`"${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport` + + if [ $3 = '|' ]; then + printf '%s' "$4" | mhmail recipient@example.com $2 \ + -server 127.0.0.1 -port $localport + else + mhmail recipient@example.com $2 -body "$4" \ + -server 127.0.0.1 -port $localport + fi # # It's hard to calculate the exact Date: header post is going to @@ -70,14 +68,16 @@ actual_err=$MH_TEST_DIR/test-mhmail$$.actual_err # check -help +start_test "-help" # Verified behavior consistent with compiled sendmail. cat >$expected <$actual 2>&1 -check $expected $actual +#### Skip nmh intro text. +mhmail -help 2>&1 | sed '/^$/,$d' >"$actual" +check "$expected" "$actual" # check -version +start_test "-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`;; + * ) printf '%s: mhmail -v generated unexpected output\n' "$0" >&2 + failed=`expr ${failed:-0} + 1`;; esac - -# check with no arguments +# check for missing argument to switches that require them +start_test "for missing argument to switches that require them" +for switch in attach body cc from headerfield subject to; do + run_test "mhmail recipient -$switch" \ + "mhmail: missing argument to -$switch" +done +for switch in attach body cc from headerfield subject to; do + run_test "mhmail recipient -$switch -nosend" \ + "mhmail: missing argument to -$switch" +done +for switch in attach body cc from headerfield subject to; do + run_test "mhmail recipient -$switch -server 127.0.0.1" \ + "mhmail: missing argument to -$switch" +done + + +# check with no switches +start_test "with no switches" # 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 +printf 'inc: -version\n' >> $MH case `mhmail` in inc\ --*) ;; - * ) echo "$0: mhmail generated unexpected output" 1>&2 + * ) echo "$0: mhmail generated unexpected output" >&2 failed=`expr ${failed:-0} + 1`;; esac # check -nosend +start_test "-nosend" # Not supported by compiled mhmail. -mhmail -nosend recipient@example.com -from sender@localhost \ +mhmail -nosend recipient@example.com -from sender1@localhost \ -server 127.0.0.1 -port $localport -body '' >"$actual" 2>"$actual_err" -tmpfil=`head -1 $actual | sed -e 's/://'` - cat > "$expected" < "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender2@localhost Date: message @@ -151,19 +170,20 @@ message QUIT EOF -test_mhmail "$expected" "-from sender@localhost -nosend -send" '|' message +test_mhmail "$expected" "-from sender2@localhost -nosend -send" '|' message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check -from +start_test "-from" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender3@localhost Date: message @@ -171,19 +191,20 @@ message QUIT EOF -test_mhmail "$expected" "-from sender@localhost" '|' message +test_mhmail "$expected" "-from sender3@localhost" '|' message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check -from and -body +start_test "-from and -body" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender4@localhost Date: body @@ -191,21 +212,22 @@ body QUIT EOF -test_mhmail "$expected" "-from sender@localhost" -b body +test_mhmail "$expected" "-from sender4@localhost" -b body [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check -from and -cc +start_test "-from and -cc" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: RCPT TO: DATA To: recipient@example.com Cc: recipient2@example.com -From: sender@localhost +From: sender5@localhost Date: message @@ -214,15 +236,16 @@ QUIT EOF test_mhmail "$expected" \ - "-from sender@localhost -cc recipient2@example.com" '|' message + "-from sender5@localhost -cc recipient2@example.com" '|' message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check -from and multiple -cc addresses +start_test "-from and multiple -cc addresses" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: RCPT TO: RCPT TO: @@ -231,7 +254,7 @@ DATA To: recipient@example.com Cc: recipient2@example.com, recipient3@example.com, recipient4@example.com -From: sender@localhost +From: sender6@localhost Date: message @@ -240,21 +263,22 @@ QUIT EOF test_mhmail "$expected" \ - '-from sender@localhost -cc recipient2@example.com recipient3@example.com '\ -'recipient4@example.com' '|' message + '-from sender6@localhost -cc recipient2@example.com '\ +'recipient3@example.com recipient4@example.com' '|' message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check -from and -subject +start_test "-from and -subject" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com Subject: Test -From: sender@localhost +From: sender7@localhost Date: message @@ -262,24 +286,27 @@ message QUIT EOF -test_mhmail "$expected" '-from sender@localhost -subject Test' '|' message +test_mhmail "$expected" '-from sender7@localhost -subject Test' '|' message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check -from and -profile +start_test "-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 +printf 'send: -msgid\n' >> $MH cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender8@localhost +MIME-Version: 1.0 +Content-Type: text/plain; charset="us-ascii" Date: Message-ID: @@ -288,20 +315,21 @@ message QUIT EOF -test_mhmail "$expected" '-from sender@localhost -profile' '|' message +test_mhmail "$expected" '-from sender8@localhost -profile' '|' message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} -# check repeated -from and -subject arguments +# check repeated -from and -subject switches +start_test "repeated -from and -subject switches" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com Subject: Subject2 -From: sender2@localhost +From: sender9@localhost Date: message @@ -309,19 +337,20 @@ message QUIT EOF -test_mhmail "$expected" '-from sender@localhost -from sender2@localhost '\ +test_mhmail "$expected" '-from sender9@localhost -from sender9@localhost '\ '-subject Subject1 -subject Subject2' -b message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} -# check repeated -body arguments +# check repeated -body switches +start_test "repeated -body switches" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender10@localhost Date: body2 @@ -329,22 +358,23 @@ body2 QUIT EOF -test_mhmail "$expected" "-from sender@localhost -body body1" -b body2 +test_mhmail "$expected" "-from sender10@localhost -body body1" -b body2 [ ${failed:-0} -eq 0 ] || exit ${failed:-0} -# check multiple -cc arguments +# check multiple -cc switches +start_test "multiple -cc switches" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: RCPT TO: RCPT TO: DATA To: recipient@example.com Cc: cc1@example.com, cc2@example.com -From: sender@localhost +From: sender11@localhost Date: message @@ -353,15 +383,16 @@ QUIT EOF test_mhmail "$expected" \ - '-from sender@localhost -cc cc1@example.com -cc cc2@example.com' -b message + '-from sender11@localhost -cc cc1@example.com -cc cc2@example.com' -b message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check separated -cc arguments +start_test "separated -cc arguments" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: RCPT TO: RCPT TO: @@ -369,7 +400,34 @@ DATA To: recipient@example.com Cc: cc1@example.com, cc2@example.com Subject: Test -From: sender@localhost +From: sender12@localhost +Date: + +message +. +QUIT +EOF + +test_mhmail "$expected" \ + '-from sender12@localhost -cc cc1@example.com -subject '\ +'Test cc2@example.com' -b message +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +# check -cc switch followed by -to switch +start_test "-cc switch followed by -to switch" +# Verified same behavior as compiled mhmail. +cat > "$expected" < +RCPT TO: +RCPT TO: +RCPT TO: +DATA +To: recipient@example.com, recipient2@example.com +Cc: cc1@example.com +Subject: Test +From: sender13@localhost Date: message @@ -378,12 +436,14 @@ QUIT EOF test_mhmail "$expected" \ - '-from sender@localhost -cc cc1@example.com -subject Test cc2@example.com' \ + "-from sender13@localhost -cc cc1@example.com -subject Test \ + -to recipient2@example.com" \ -b message [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check with no newline on stdin +start_test "with no newline on stdin" # Shows different behavior than compiled mhmail, which was silent in this case. cat > "$expected" < "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender14@localhost Date: @@ -418,19 +479,21 @@ Date: QUIT EOF -test_mhmail "$expected" '-from sender@localhost' '|' '\n' +test_mhmail "$expected" '-from sender14@localhost' '|' ' +' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check with multiple newlines on stdin +start_test "with multiple newlines on stdin" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender15@localhost Date: @@ -440,19 +503,23 @@ Date: QUIT EOF -test_mhmail "$expected" '-from sender@localhost' '|' '\n\n\n' +test_mhmail "$expected" '-from sender15@localhost' '|' ' + + +' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check with text and no trailing newline on stdin +start_test "with text and no trailing newline on stdin" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender16@localhost Date: no newline in input @@ -460,19 +527,20 @@ no newline in input QUIT EOF -test_mhmail "$expected" '-from sender@localhost' '|' 'no newline in input' +test_mhmail "$expected" '-from sender16@localhost' '|' 'no newline in input' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check with text and multiple trailing blank lines on stdin +start_test "with text and multiple trailing blank lines on stdin" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender17@localhost Date: here's some text @@ -482,19 +550,23 @@ here's some text QUIT EOF -test_mhmail "$expected" '-from sender@localhost' '|' "here's some text\n\n\n" +test_mhmail "$expected" '-from sender17@localhost' '|' "here's some text + + +" [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check with no newline to -body +start_test "with no newline to -body" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender18@localhost Date: @@ -502,19 +574,20 @@ Date: QUIT EOF -test_mhmail "$expected" '-from sender@localhost' -b '' +test_mhmail "$expected" '-from sender18@localhost' -b '' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check with one newline to -body +start_test "with one newline to -body" # Shows different behavior than compiled mhmail, which suppressed the newline. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender19@localhost Date: @@ -523,21 +596,22 @@ Date: QUIT EOF -test_mhmail "$expected" '-from sender@localhost' -b ' +test_mhmail "$expected" '-from sender19@localhost' -b ' ' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check with multiple newlines to -body +start_test "with multiple newlines to -body" # Shows different behavior than compiled mhmail, which suppressed one # of the newlines. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender20@localhost Date: @@ -548,7 +622,7 @@ Date: QUIT EOF -test_mhmail "$expected" '-from sender@localhost' -b ' +test_mhmail "$expected" '-from sender20@localhost' -b ' ' @@ -556,14 +630,15 @@ test_mhmail "$expected" '-from sender@localhost' -b ' # check with text and no trailing newline to -body +start_test "with text and no trailing newline to -body" # Verified same behavior as compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender21@localhost Date: no newline in input @@ -571,20 +646,21 @@ no newline in input QUIT EOF -test_mhmail "$expected" '-from sender@localhost' -b 'no newline in input' +test_mhmail "$expected" '-from sender21@localhost' -b 'no newline in input' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check with text and multiple trailing blank lines to -body +start_test "with text and multiple trailing blank lines to -body" # Shows different behavior than compiled mhmail, which suppressed one # of the newlines. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender22@localhost Date: here's some text @@ -594,13 +670,14 @@ here's some text QUIT EOF -test_mhmail "$expected" '-from sender@localhost' -b "here's some text +test_mhmail "$expected" '-from sender22@localhost' -b "here's some text " [ ${failed:-0} -eq 0 ] || exit ${failed:-0} # check -resent +start_test "-resent" # Verified same behavior as compiled mhmail. cat > "$expected" < "$expected" < RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender24@localhost Date: Resent-To: recipient@example.com Resent-From: orig_recipient@example.com @@ -650,7 +728,7 @@ EOF test_mhmail "$expected" \ '-from orig_recipient@example.com -resent -profile -nomsgid' \ '|' 'To: recipient@example.com -From: sender@localhost +From: sender24@localhost Date: Sat Jun 16 18:35:15 -0500 please resend this message, 2' @@ -659,6 +737,7 @@ please resend this message, 2' # check -resent -profile, using -b +start_test "-resent -profile, using -b" # Not supported by compiled mhmail. cat > "$expected" < RCPT TO: DATA To: recipient@example.com -From: sender@localhost +From: sender25@localhost Date: Resent-To: recipient@example.com Resent-From: orig_recipient@example.com @@ -680,7 +759,7 @@ EOF test_mhmail "$expected" \ '-from orig_recipient@example.com -resent -profile -nomsgid' \ -b 'To: recipient@example.com -From: sender@localhost +From: sender25@localhost Date: Sat Jun 16 18:35:15 -0500 please resend this message, 3' @@ -688,15 +767,16 @@ please resend this message, 3' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} -# check -header-field. +# check -headerfield. +start_test "-headerfield." # Not supported by compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@example.com +From: sender26@example.com User-Agent: nmh Date: @@ -706,24 +786,25 @@ QUIT EOF test_mhmail "$expected" \ - '-from sender@example.com -header-field User-Agent:nmh' \ + '-from sender26@example.com -headerfield User-Agent:nmh' \ -b 'with added header field' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} -# check multiple -header-fields. +# check multiple -headerfields. +start_test "multiple -headerfields." # Not supported by compiled mhmail. cat > "$expected" < +MAIL FROM: RCPT TO: DATA To: recipient@example.com -From: sender@example.com +From: sender27@example.com MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit Date: with added header fields @@ -732,12 +813,54 @@ QUIT EOF test_mhmail "$expected" \ - "-from sender@example.com -header-field MIME-Version:1.0 \ --header-field Content-Type:text/plain;charset=utf-8 \ --header-field Content-Transfer-Encoding:8bit" \ + "-from sender27@example.com -headerfield MIME-Version:1.0 \ +-headerfield Content-Type:text/plain;charset=utf-8 \ +-headerfield Content-Transfer-Encoding:7bit" \ -b 'with added header fields' [ ${failed:-0} -eq 0 ] || exit ${failed:-0} +# check -attach +start_test "-attach" +# Not supported by compiled mhmail. +cat > "$expected" < +RCPT TO: +DATA +To: recipient@example.com +From: sender28@example.com +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" +Date: +Message-ID: + +------- =_aaaaaaaaaa0 +Content-Type: text/plain; charset="us-ascii" + +See how easy it is to add an attachment! + +------- =_aaaaaaaaaa0 +Content-Type: `content_type_string ${srcdir}/test/mhmail/attachment.txt` +Content-Description: attachment.txt +Content-Disposition: attachment; filename="attachment.txt" + +The future disappears into memory, With only a moment between, +Forever dwells in that moment, hope is what remains to be seen +Forever dwells in that moment, hope is what remains to be seen. + +------- =_aaaaaaaaaa0-- +. +QUIT +EOF + +test_mhmail "$expected" \ + "-from sender28@example.com -attach ${srcdir}/test/mhmail/attachment.txt" \ + -b 'See how easy it is to add an attachment!' + +[ ${failed:-0} -eq 0 ] || exit ${failed:-0} + + +finish_test exit ${failed:-0}