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
-LC_ALL=en_US.UTF-8; export LC_ALL
+require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8
expected="$MH_TEST_DIR/test-mhfixmsg$$.expected"
expected_err="$MH_TEST_DIR/test-mhfixmsg$$.expected_err"
------=_nmh-multipart
Content-Type: text/plain; charset="Windows-1252"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
Need to go! Need ... to ... go!
------=_nmh-multipart
Content-Type: text/html; charset="Windows-1252"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
<html>
<head>
------=_nmh-multipart-3
Content-Type: text/plain; charset="Windows-1252"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
------=_nmh-multipart
------=_nmh-multipart-1
------=_nmh-multipart-3
Content-Type: text/html; charset="Windows-1252"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
<html>
<head>
------=_nmh-multipart
Content-Type: text/plain; charset="Windows-1252"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
Need to go! Need ... to ... go!
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
Content-Disposition: attachment; filename="test4.txt"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
This is a text/plain part.
Content-Type: text/plain; charset="iso-8859-1"
Content-Disposition: attachment; filename="test2.txt"
Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
This is the second text/plain part.
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
Content-Disposition: attachment; filename="test4.txt"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
This is the fourth text/plain part.
Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
------- =_aaaaaaaaaa0
-Content-Type: text/plain; charset=UTF-8; name="nul+square.txt"
+Content-Type: text/plain; charset="UTF-8"; name="nul+square.txt"
Content-Transfer-Encoding: base64
vbI9vAAK
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="iso-8859-1"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
This is a text plain part
Subject: mhfixmsg successful decode of text/plain with failed binary decode
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
+Content-Transfer-Encoding: binary
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="iso-8859-1"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
This is a text plain part
Subject: mhfixmsg binary decode test
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=\"----- =_aaaaaaaaaa0\"
+Content-Transfer-Encoding: binary
------- =_aaaaaaaaaa0
-Content-Type: text/plain; charset=UTF-8; name=\"nul+square.txt\"
+Content-Type: text/plain; charset=\"UTF-8\"; name=\"nul+square.txt\"
Content-Transfer-Encoding: binary
" "
------=_nmh-multipart
Content-Type: text/plain; charset="ISO-8859-1"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
Mile $0.00
Time $78.71
Subject: mhfixmsg textcharset test
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
+Content-Transfer-Encoding: 8bit
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="utf-8"; name="square.txt"
# check handling of rfc822 message type
+# also, checks -fixboundary
start_test "handling of rfc822 message type"
cat >"$expected" <<EOF
From: Test <test@example.com>
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
------=_Part_876302
Content-Type: text/plain; charset="UTF-8"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
Yes, the text/plain part really was empty.
------=_Part_876302
Content-Type: text/html; charset="UTF-8"
-Content-Transfer-Encoding: 8bit
Content-Disposition: inline
<html><head>
------=_Part_876302
Content-Type: text/html; charset="UTF-8"
-Content-Transfer-Encoding: 8bit
Content-Disposition: inline
<html><head>
------=_Part_876302
Content-Type: text/html; charset="UTF-8"
-Content-Transfer-Encoding: 8bit
Content-Disposition: inline
<html><head>
Content-Type: text/plain; charset="iso-8859-1"
Content-Disposition: attachment; filename="test1.txt"
Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
This is the text/plain part.
------- =_aaaaaaaaaa0
Content-Type: text/html; charset="iso-8859-1"; name="test2.txt"
Content-Disposition: attachment; filename="test2.txt"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
<html>
<head>
Content-Type: text/plain; charset="iso-8859-1"
Content-Disposition: attachment; filename="test1.txt"
Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
This is the text/plain part.
Content-Type: text/plain; charset="iso-8859-1"
Content-Disposition: attachment; filename="test1.txt"
Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
This is the text/plain part.
------- =_aaaaaaaaaa0
Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
Content-Disposition: attachment; filename="invite.ics"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
BEGIN:VCALENDAR\r
VERSION:2.0\r
Content-Type: text/plain; charset="iso-8859-1"
Content-Disposition: attachment; filename="test1.txt"
Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
This is the text/plain part.
------- =_aaaaaaaaaa0
Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics"
Content-Disposition: attachment; filename="invite.ics"
-Content-Transfer-Encoding: 8bit
+Content-Transfer-Encoding: 7bit
BEGIN:VCALENDAR
VERSION:2.0
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" '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`
+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"
+#### Also, add C-T-E:8bit to the message headers.
+cat >"$expected" <<EOF
+To: recipient@example.com
+From: sender@example.com
+Date: Wed, 28 Sep 2016 11:24:28 -0400
+Subject: invalid header parameter encoding
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary=001a114dd3e8fe9c56053d92f414
+Content-Transfer-Encoding: 8bit
+
+--001a114dd3e8fe9c56053d92f414
+Content-Type: text/plain; charset=UTF-8
+
+This is a test.
+
+--001a114dd3e8fe9c56053d92f414
+Content-Type: text/plain; charset="UTF-8"; name*=UTF-8''test%C3%B8.txt
+Content-Disposition: attachment; filename*=UTF-8''test%C3%B8.txt
+Content-Transfer-Encoding: 8bit
+
+This is the first text/plain part, in a subpart. The file name
+is testø.txt.
+
+--001a114dd3e8fe9c56053d92f414--
+EOF
+
+cat >`mhpath new` <<EOF
+To: recipient@example.com
+From: sender@example.com
+Date: Wed, 28 Sep 2016 11:24:28 -0400
+Subject: invalid header parameter encoding
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary=001a114dd3e8fe9c56053d92f414
+
+--001a114dd3e8fe9c56053d92f414
+Content-Type: text/plain; charset=UTF-8
+
+This is a test.
+
+--001a114dd3e8fe9c56053d92f414
+Content-Type: text/plain; charset=UTF-8; name="=?UTF-8?B?dGVzdMO4LnR4dA==?="
+Content-Disposition: attachment; filename="=?UTF-8?B?dGVzdMO4LnR4dA==?="
+Content-Transfer-Encoding: 8bit
+
+This is the first text/plain part, in a subpart. The file name
+is testø.txt.
+
+--001a114dd3e8fe9c56053d92f414--
+EOF
+run_prog mhfixmsg -file - -outfile - <`mhpath last` >"$actual" 2>/dev/null
+check "$expected" "$actual"
+
+
# make sure there are no tmp files left over
find "$MH_TEST_DIR/Mail" \( -name 'mhfix*' -o -name ',mhfix*' \) -print \
>"$actual"