]> diplodocus.org Git - nmh/blobdiff - test/mhfixmsg/test-mhfixmsg
Fixed file descriptor leak in mhfixmsg when run on multiple input files.
[nmh] / test / mhfixmsg / test-mhfixmsg
index b927b95e694525d0fa0415a8d1811675f4209f4e..c80cfb8b1a4b9404a9fdf3b79f3fb322fc261894 100755 (executable)
@@ -61,6 +61,7 @@ Usage: mhfixmsg [+folder] [msgs] [switches]
   -[no]replacetextplain
   -[no]fixboundary
   -[no]fixcte
+  -[no]checkbase64
   -fixtype mimetype
   -file file
   -outfile file
@@ -73,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"
 
 
@@ -865,13 +866,32 @@ EOF
 
 if test "$ICONV_ENABLED" -eq 1; then
   run_prog mhfixmsg last -textcharset utf-8 -outfile "$actual" 2>&1
-  check "$expected" "$actual"
+  check "$expected" "$actual" 'keep first'
 else
   echo "$0: skipping -textcharset check because nmh was built without iconv"
   rm -f "$expected"
 fi
 
 
+# check -textcharset -verbose
+start_test "-textcharset -verbose"
+cat >"$expected.err" <<EOF
+mhfixmsg: 17 part 1, decode text/plain; charset="iso-8859-1"; name="square.txt"
+mhfixmsg: 17 part 1, convert iso-8859-1 to utf-8
+EOF
+
+if test "$ICONV_ENABLED" -eq 1; then
+  run_prog mhfixmsg last -textcharset utf-8 -outfile "$actual" -verbose \
+           2>"$actual.err"
+  check "$expected" "$actual"
+  check "$expected.err" "$actual.err"
+else
+    echo "$0: skipping -textcharset -verbose check because nmh was built " \
+         "without iconv"
+  rm -f "$expected" "$expected.err"
+fi
+
+
 # check -nofixboundary
 start_test "-nofixboundary"
 cat >"$expected" <<EOF
@@ -1853,6 +1873,301 @@ run_prog mhfixmsg -file - -outfile - -decodeheaderfieldbodies utf-8 \
 check "$expected" "$actual"
 
 
+start_test "-checkbase64 with base64 code that ends with == plus footer"
+cat >"`mhpath new`" <<EOF
+From: Test <test@example.com>
+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" <<EOF
+From: Test <test@example.com>
+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`" <<EOF
+From: Test <test@example.com>
+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" <<EOF
+From: Test <test@example.com>
+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`" <<EOF
+From: Test <test@example.com>
+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" <<EOF
+From: Test <test@example.com>
+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`" <<EOF
+From: Test <test@example.com>
+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" <<EOF
+From: Test <test@example.com>
+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`" <<EOF
+From: Test <test@example.com>
+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" <<EOF
+From: Test <test@example.com>
+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" <<EOF
+mhfixmsg: invalid base64 byte 0x2d: -X-
+Wait, this shouldn't be here.
+
+EOF
+
+run_prog mhfixmsg last -outfile "$actual" 2>"$actual_err" || true
+check "$expected" "$actual"
+check "$expected_err" "$actual_err"
+
+
+start_test "-checkbase64 with base64 code in MIME part"
+cat >"`mhpath new`" <<EOF
+From: Test <test@example.com>
+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" <<EOF
+From: Test <test@example.com>
+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`" <<EOF
+From: Test <test@example.com>
+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" <<EOF
+From: Test <test@example.com>
+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*' -print \
   >"$actual"