]> diplodocus.org Git - nmh/commitdiff
Fixed decoding of header fields when they contain a character that
authorDavid Levine <levinedl@acm.org>
Thu, 3 Jan 2013 02:07:43 +0000 (20:07 -0600)
committerDavid Levine <levinedl@acm.org>
Thu, 3 Jan 2013 02:07:43 +0000 (20:07 -0600)
can't be converted.  Added test case to test-scan.  valgrind also
noticed that things went amiss.

docs/pending-release-notes
sbr/fmt_rfc2047.c
test/scan/test-scan

index 6fe7f47c3e17c0b4eb73e2ee99896f453500566e..1467018b7db1a64298f566ed8a9b4b961c94a18f 100644 (file)
@@ -88,3 +88,5 @@ BUG FIXES
 - Fixed pick(1) to properly unfold multiple-line header fields by
   removing newlines instead of replacing them with spaces [Bug #15215].
 - Removed the artificial limit of 1000 messages at a time for rmmproc.
+- Fixed decoding of header fields when they contain a character that
+  can't be converted.
index 4d3fc296d0e90d987d5002035446f30884dd0e5e..25c98c3ded2ae2b392eb652a7ff1d41a49f12318 100644 (file)
@@ -303,8 +303,10 @@ decode_rfc2047 (char *str, char *dst, size_t dstlen)
                            break;
                        /* skip to next input character */
                        if (fromutf8) {
-                           for (start++;(start < q) && ((*start & 192) == 128);start++)
-                               inbytes--;
+                           for (++start, --inbytes;
+                                start < q  &&  (*start & 192) == 128;
+                                ++start, --inbytes)
+                               continue;
                        } else
                            start++, inbytes--;
                        if (start >= q)
index 79ac85d5d81a6c93249c904aaade6dcb422c2a9d..7fd4b7bb2cbba500e6739d558d60ce3300516a59 100755 (executable)
@@ -14,10 +14,10 @@ fi
 
 setup_test
 
-expected=$MH_TEST_DIR/$$.expected
-actual=$MH_TEST_DIR/$$.actual
+expected="$MH_TEST_DIR/$$.expected"
+actual="$MH_TEST_DIR/$$.actual"
 
-cat > $expected <<EOF
+cat >"$expected" <<EOF
    1  09/29 Test1              Testing message 1<<This is message number 1 >>
    2  09/29 Test2              Testing message 2<<This is message number 2 >>
    3  09/29 Test3              Testing message 3<<This is message number 3 >>
@@ -30,12 +30,11 @@ cat > $expected <<EOF
   10  09/29 Test10             Testing message 10<<This is message number 10 >>
 EOF
 
-scan +inbox -width 80 > $actual || exit 1
-
+scan +inbox -width 80 >"$actual" || exit 1
 check "$expected" "$actual"
 
 # check highlighting
-cat > $expected <<EOF
+cat >"$expected" <<EOF
    1  09/29 Test1              Testing message 1<<This is message number 1 >>\e[m
    2  09/29 Test2              Testing message 2<<This is message number 2 >>\e[m
    3  09/29 Test3              Testing message 3<<This is message number 3 >>\e[m
@@ -51,8 +50,26 @@ EOF
 printf 'Unseen-Sequence: unseen\n' >> $MH
 mark -sequence cur 5
 mark -sequence unseen 10
-scan -form scan.highlighted -width 80 > $actual || exit 1
+scan -form scan.highlighted -width 80 >"$actual" || exit 1
+check "$expected" "$actual"
+
+# check decoding with an invalid multibyte sequence.
+cat >"$expected" <<EOF
+  11  12/31 Test11             2013 New Year?s Deals! Start the year right
+EOF
+
+cat >`mhpath new` <<EOF
+From: Test11 <test11@example.com>
+To: Some User <user@example.com>
+Date: Mon, 31 Dec 2012 00:00:00
+Message-Id: 11@test.nmh
+Subject: =?UTF-8?B?MjAxMyBOZXcgWWVhcuKAmXMgRGVhbHMhIFN0YXJ0IHRoZSB5ZWFy?=
+       =?UTF-8?B?IHJpZ2h0IHdpdGggYmlnIHNhdmluZ3M=?=
 
+This message has an encoded Subject with an invalid character for the
+ISO-8859-1 character set.
+EOF
+LC_CTYPE=ISO-8859-1 MM_CHARSET=ISO-8859-1 scan -width 75 last >"$actual"
 check "$expected" "$actual"