X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/97d33c31f4d3fdef03610c1652b5e246184e0097..b22bcbc2adddca14cc1889b1eee37643e0b88489:/test/mhfixmsg/test-mhfixmsg?ds=sidebyside diff --git a/test/mhfixmsg/test-mhfixmsg b/test/mhfixmsg/test-mhfixmsg index 8d7a3a85..66e45a32 100755 --- a/test/mhfixmsg/test-mhfixmsg +++ b/test/mhfixmsg/test-mhfixmsg @@ -16,6 +16,8 @@ fi setup_test +check_exit '-eq 1' mhfixmsg - + #### Make sure that html-to-text conversion is what we expect. require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8 @@ -26,8 +28,7 @@ actual_err="$MH_TEST_DIR/test-mhfixmsg$$.actual_err" mhn_defaults="$MH_INST_DIR${nmhetcdir}/mhn.defaults" -if grep mhfixmsg-format-text/html "${mhn_defaults}" \ - >/dev/null; then +if grep mhfixmsg-format-text/html "${mhn_defaults}" >/dev/null; then can_reformat_texthtml=1 if grep 'mhfixmsg-format-text/html.*w3m' "${mhn_defaults}" \ >/dev/null; then @@ -52,12 +53,15 @@ Usage: mhfixmsg [+folder] [msgs] [switches] -decodetext 8bit|7bit|binary -nodecodetext -decodetypes + -decodeheaderfieldbodies utf-8 + -nodecodeheaderfieldbodies -[no]crlflinebreaks -[no]textcharset -[no]reformat -[no]replacetextplain -[no]fixboundary -[no]fixcte + -[no]checkbase64 -fixtype mimetype -file file -outfile file @@ -70,7 +74,7 @@ Usage: mhfixmsg [+folder] [msgs] [switches] EOF #### Skip nmh intro text. -run_prog mhfixmsg -help | sed '/^$/,$d' >"$actual" 2>&1 +run_prog mhfixmsg -help 2>&1 | sed '/^$/,$d' >"$actual" check "$expected" "$actual" @@ -85,15 +89,15 @@ esac # check that non-MIME messages aren't modified # check -outfile -start_test "that non-MIME messages aren't modified, and -outfile" +start_test "non-MIME messages aren't modified, and -outfile" run_test 'mhfixmsg first -outfile '"$actual" '' check "`mhpath first`" "$actual" 'keep first' # check that non-MIME messages with no bodies aren't modified # check -outfile -start_test "that non-MIME messages with no bodies aren't modified, and -outfile" -cat >`mhpath new` <"`mhpath new`" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 @@ -107,7 +111,7 @@ check "`mhpath last`" "$actual" # check -nofixcte start_test "-nofixcte" -cat >"$MH_TEST_DIR"/Mail/inbox/11 <"`mhpath new`" </dev/null run_test 'mhfixmsg' '' check "$expected" "$MH_TEST_DIR"/Mail/inbox/11 'keep first' cp "$MH_TEST_DIR"/Mail/inbox/11.original "$MH_TEST_DIR"/Mail/inbox/11 -check "$MH_TEST_DIR"/Mail/inbox/,11 "$MH_TEST_DIR"/Mail/inbox/11.original +check "$MH_TEST_DIR/Mail/inbox/${sbackup}11" "$MH_TEST_DIR"/Mail/inbox/11.original # check backup with -file @@ -195,7 +200,13 @@ cp "$MH_TEST_DIR"/Mail/inbox/11 "$MH_TEST_DIR"/Mail/inbox/11.original folder last >/dev/null run_test 'mhfixmsg -file '"$MH_TEST_DIR"/Mail/inbox/11 '' check "$MH_TEST_DIR"/Mail/inbox/11 "$expected" 'keep first' -check "$MH_TEST_DIR"/Mail/inbox/,11 "$MH_TEST_DIR"/Mail/inbox/11.original +check "$MH_TEST_DIR/Mail/inbox/${sbackup}11" "$MH_TEST_DIR"/Mail/inbox/11.original + + +# check -file with directory +start_test "-file with directory" +run_test 'mhfixmsg -file /tmp' 'mhfixmsg: /tmp is a directory +mhfixmsg: unable to parse message from file /tmp' # check -reformat (enabled by default): addition of text/plain part @@ -234,7 +245,7 @@ Content-Transfer-Encoding: 7bit ------=_nmh-multipart-- EOF -cat >"$MH_TEST_DIR"/Mail/inbox/12 <"`mhpath new`" <"$MH_TEST_DIR"/Mail/inbox/12 <"`mhpath last`" <"$expected" <"$expected.err" #### lynx inserts multiple blank lines, so squeeze them. - run_prog mhfixmsg last -nodecode -outfile - -verbose 2>"$actual.err" | \ + run_prog mhfixmsg last -nodecodetext -outfile - -verbose 2>"$actual.err" | \ squeeze_lines >"$actual" check "$expected" "$actual" 'ignore space' check "$expected.err" "$actual.err" @@ -449,7 +460,7 @@ This is a text/plain part. ------- =_aaaaaaaaaa0-- EOF -cat >`mhpath new` <"`mhpath new`" <`mhpath new` <"`mhpath new`" <`mhpath new` <"`mhpath new`" <`mhpath new` <"`mhpath new`" <"$expected" <<'EOF' MIME-Version: 1.0 Date: Thu, 11 Apr 2013 02:47:08 -0700 @@ -766,7 +777,7 @@ Content-Transfer-Encoding: quoted-printable EOF -cat >`mhpath new` <<'EOF' +cat >"`mhpath new`" <<'EOF' MIME-Version: 1.0 Content-Type: text/html; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable @@ -836,7 +847,7 @@ EOF #### Generated the encoded text below with: #### $ printf '\275\262=\274\n' | base64 -cat >`mhpath new` <"`mhpath new`" <"$expected" <`mhpath new` <"`mhpath new`" <"$actual" 2>"$actual.err" check "$expected" "$actual" if grep "mhfixmsg: $MH_TEST_DIR/Mail/.*, fix multipart boundary" \ @@ -936,8 +947,8 @@ check "$expected" "$actual" # check that message is not modified when -fixboundary fails -start_test "that message is not modified when -fixboundary fails" -cat >`mhpath new` <"`mhpath new`" <`mhpath new` <"`mhpath new`" <"$expected" <`mhpath new` <"`mhpath new`" <"$expected" < @@ -1100,14 +1112,14 @@ This is an RFC-822 message. and some garbage at the end EOF -cat >`mhpath new` <"`mhpath new`" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 Message-Id: @test.nmh Subject: message with message/rfc822 attachment MIME-Version: 1.0 -Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaa0" +Content-Type: multipart/mixed; boundary="----- =badboundary" and some garbage before the attachment @@ -1146,7 +1158,7 @@ There are two CR-LF pairs at the end of this sentence. EOF -cat >`mhpath new` <<'EOF' +cat >"`mhpath new`" <<'EOF' MIME-Version: 1.0 From: sender@example.com To: recipient@example.com @@ -1174,7 +1186,7 @@ There were two CR-LF pairs at the end of this sentence. EOF -cat >`mhpath new` <<'EOF' +cat >"`mhpath new`" <<'EOF' MIME-Version: 1.0 From: sender@example.com To: recipient@example.com @@ -1219,7 +1231,7 @@ Content-Disposition: inline ------=_Part_876302-- EOF -cat >`mhpath new` <<'EOF' +cat >"`mhpath new`" <<'EOF' To: recipient@example.com From: sender@example.com Subject: mhfixmsg replacement of bad text/plain part test @@ -1319,7 +1331,7 @@ Content-Disposition: attachment; ------- =_aaaaaaaaaa0-- EOF -cat >`mhpath new` <"`mhpath new`" <"$MH_TEST_DIR/Mail/rmmproc" <<'EOF' +if [ $can_reformat_texthtml -eq 1 ]; then + # check rmmproc + start_test "rmmproc" + cat >"$MH_TEST_DIR/Mail/rmmproc" <<'EOF' mv "$1" "$1.backup" EOF -chmod a+x "${MH_TEST_DIR}/Mail/rmmproc" -echo "rmmproc: ${MH_TEST_DIR}/Mail/rmmproc" >>"$MH" -cp "${MH_TEST_DIR}/Mail/inbox/16" "${MH_TEST_DIR}/Mail/inbox/16.original" + chmod a+x "${MH_TEST_DIR}/Mail/rmmproc" + echo "rmmproc: ${MH_TEST_DIR}/Mail/rmmproc" >>"$MH" + cp "${MH_TEST_DIR}/Mail/inbox/16" "${MH_TEST_DIR}/Mail/inbox/16.original" -run_test 'mhfixmsg 16' '' -check "${MH_TEST_DIR}/Mail/inbox/16.backup" \ - "${MH_TEST_DIR}/Mail/inbox/16.original" + run_test 'mhfixmsg 16' '' + check "${MH_TEST_DIR}/Mail/inbox/16.backup" \ + "${MH_TEST_DIR}/Mail/inbox/16.original" -# check -normmproc -start_test "-normmproc" -cp "${MH_TEST_DIR}/Mail/inbox/21" "${MH_TEST_DIR}/Mail/inbox/22" + # check -normmproc + start_test "-normmproc" + cp "${MH_TEST_DIR}/Mail/inbox/21" "${MH_TEST_DIR}/Mail/inbox/22" -run_test 'mhfixmsg 21 -normmproc' -check "${MH_TEST_DIR}/Mail/inbox/22" \ - "${MH_TEST_DIR}/Mail/inbox/,21" 'keep first' + run_test 'mhfixmsg 21 -normmproc' + check "${MH_TEST_DIR}/Mail/inbox/22" \ + "${MH_TEST_DIR}/Mail/inbox/${sbackup}21" 'keep first' +fi # check -rmmproc @@ -1395,7 +1409,7 @@ this is plain text ------- =_aaaaaaaaaa0-- EOF -cat >`mhpath new` <"`mhpath new`" <`mhpath new` <"`mhpath new`" <`mhpath new` <"`mhpath new`" <`mhpath new` <"`mhpath new`" <`mhpath new` <"`mhpath new`" <"$expected.err" <`mhpath new` <"`mhpath new`" <"$actual.err" set -e #### Expected output is identical to the input message. -check `mhpath last` "$actual" 'keep first' +check "`mhpath last`" "$actual" 'keep first' check "$expected.err" "$actual.err" @@ -1706,12 +1720,23 @@ check "$expected.err" "$actual.err" # (the charset string is missing its closing quote) with -outfile, and # input from stdin. Don't check err output, because it contains the name # of a tmp file. It's similar to that of the previous check. -start_test "that input is passed through to output when there's a parse error" +start_test "input is passed through to output when there's a parse error" set +e run_prog mhfixmsg -file - -outfile - <`mhpath last` >"$actual" 2>/dev/null set -e #### Expected output is identical to the input message. -check `mhpath last` "$actual" +check "`mhpath last`" "$actual" 'keep first' + + +start_test "pass through message with relative folder path with parse error" +#### Factor out leading portion of current folder path and make it relative. +pwd=`pwd -P` +set +e +run_prog mhfixmsg +./`mhpath | sed "s%^$pwd/%%"` last -out - >"$actual" 2>/dev/null +set -e +folder -f +inbox >/dev/null +#### Expected output is identical to the input message. +check "`mhpath last`" "$actual" start_test "fix RFC 2047 encoded header parameters" @@ -1741,7 +1766,7 @@ is testø.txt. --001a114dd3e8fe9c56053d92f414-- EOF -cat >`mhpath new` <"`mhpath new`" <"$actual" 2>/dev/null check "$expected" "$actual" +start_test "-nodecodeheaderfieldbodies" +cat >"`mhpath new`" <"$actual" 2>/dev/null +check `mhpath last` "$actual" 'keep first' + + +start_test "test decoding of UTF-8 header value" +cat >"$expected" <"$actual" 2>/dev/null +check "$expected" "$actual" + + +start_test "-checkbase64 with base64 code that ends with == plus footer" +cat >"`mhpath new`" < +Subject: base64 code that ends with == +MIME-Version: 1.0 +Content-Type: text/plain +Content-Transfer-Encoding: base64 + +VGhpcyBpcyBzb21lIHRleHQuCg== + +-- +Wait, this shouldn't be here. +EOF + +cat >"$expected" < +Subject: base64 code that ends with == +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="----=_nmh-multipart" + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +This is some text. + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +-- +Wait, this shouldn't be here. + +------=_nmh-multipart-- +EOF +run_prog mhfixmsg last -outfile "$actual" +check "$expected" "$actual" + + +start_test "-checkbase64 with -nodecodetext" +cat >"`mhpath new`" < +Subject: base64 code that ends with == +MIME-Version: 1.0 +Content-Type: text/plain +Content-Transfer-Encoding: base64 + +VGhpcyBpcyBzb21lIHRleHQuCg== + +-- +Wait, this shouldn't be here. +EOF + +cat >"$expected" < +Subject: base64 code that ends with == +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="----=_nmh-multipart" + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: base64 + +VGhpcyBpcyBzb21lIHRleHQuCg== + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +-- +Wait, this shouldn't be here. + +------=_nmh-multipart-- +EOF +run_prog mhfixmsg -nodecodetext last -outfile "$actual" +check "$expected" "$actual" + + +start_test "-checkbase64 with base64 code that ends with = plus footer" +cat >"`mhpath new`" < +Subject: base64 code that ends with = +MIME-Version: 1.0 +Content-Type: text/plain +Content-Transfer-Encoding: base64 + +VGhpcyBpcyBwbGFpbiB0ZXh0Lgo= + +-- +Wait, this shouldn't be here. +EOF + +cat >"$expected" < +Subject: base64 code that ends with = +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="----=_nmh-multipart" + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +This is plain text. + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +-- +Wait, this shouldn't be here. + +------=_nmh-multipart-- +EOF +run_prog mhfixmsg last -outfile "$actual" +check "$expected" "$actual" + + +start_test "-checkbase64 with base64 code that ends without = plus footer" +cat >"`mhpath new`" < +Subject: base64 code that ends without = +MIME-Version: 1.0 +Content-Type: text/plain +Content-Transfer-Encoding: base64 + +VGhpcyBpcyBzb21lIHRleHQK + +-- +Wait, this shouldn't be here. +EOF + +cat >"$expected" < +Subject: base64 code that ends without = +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="----=_nmh-multipart" + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +This is some text + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +-- +Wait, this shouldn't be here. + +------=_nmh-multipart-- +EOF +run_prog mhfixmsg last -outfile "$actual" +check "$expected" "$actual" + + +start_test "-checkbase64 with base64 code that contains single invalid character" +cat >"`mhpath new`" < +Subject: base64 code that ends without = +MIME-Version: 1.0 +Content-Type: text/plain +Content-Transfer-Encoding: base64 + +VGhpcyBpcyBzb21lIHRleHQK + +-X- +Wait, this shouldn't be here. +EOF + +cat >"$expected" < +Subject: base64 code that ends without = +MIME-Version: 1.0 +Content-Type: text/plain +Content-Transfer-Encoding: base64 + +VGhpcyBpcyBzb21lIHRleHQK + +-X- +Wait, this shouldn't be here. +EOF + +cat >"$expected_err" <"$actual_err" || true +check "$expected" "$actual" +check "$expected_err" "$actual_err" + + +start_test "-checkbase64 with base64 code in MIME part" +cat >"`mhpath new`" < +Subject: MIME part with base64 encoded text and unencoded footer +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="----=_nmh-multipart" + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: base64 + +VGhpcyBpcyBzb21lIHRleHQK + +-- +Wait, this shouldn't be here. + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +This is a second text/plain part. + +------=_nmh-multipart-- +EOF + +cat >"$expected" < +Subject: MIME part with base64 encoded text and unencoded footer +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="----=_nmh-multipart" + +------=_nmh-multipart +Content-Type: multipart/mixed; boundary="----=_nmh-multipart1" + +------=_nmh-multipart1 +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +This is some text + +------=_nmh-multipart1 +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +-- +Wait, this shouldn't be here. + +------=_nmh-multipart1-- + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +This is a second text/plain part. + +------=_nmh-multipart-- +EOF +run_prog mhfixmsg last -outfile "$actual" +check "$expected" "$actual" + + +start_test "-checkbase64 with 8-bit encoded base64 code" +cat >"`mhpath new`" < +Subject: 8-bit encoded base64 code +MIME-Version: 1.0 +Content-Type: text/plain +Content-Transfer-Encoding: base64 + +U2VlIFJGQyAyMDQ1IMKnNi44Lg== + +-- +Wait, this shouldn't be here. +EOF +cat >"$expected" < +Subject: 8-bit encoded base64 code +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="----=_nmh-multipart" +Content-Transfer-Encoding: 8bit + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: 8bit + +See RFC 2045 §6.8. + +------=_nmh-multipart +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +-- +Wait, this shouldn't be here. + +------=_nmh-multipart-- +EOF + +run_prog mhfixmsg last -outfile "$actual" +check "$expected" "$actual" + + # make sure there are no tmp files left over -find "$MH_TEST_DIR/Mail" \( -name 'mhfix*' -o -name ',mhfix*' \) -print \ +find "$MH_TEST_DIR/Mail" -name '*mhfix*' -print \ >"$actual" cat >"$expected" <