decode rfc2047 header in mhparse
authorPhilipp Takacs <philipp@bureaucracy.de>
Mon, 19 Sep 2016 16:23:39 +0000 (18:23 +0200)
committerPhilipp Takacs <philipp@bureaucracy.de>
Sun, 23 Apr 2017 12:56:17 +0000 (14:56 +0200)
attachment filenames are mostly rfc2047 encoded. Now all
mime header are decoded to avoid problems.

test/tests/mhstore/test-filenames [new file with mode: 0755]
uip/mhparse.c

diff --git a/test/tests/mhstore/test-filenames b/test/tests/mhstore/test-filenames
new file mode 100755 (executable)
index 0000000..a1d3c3d
--- /dev/null
@@ -0,0 +1,86 @@
+#!/bin/sh
+######################################################
+#
+# Test filenames
+#
+######################################################
+
+. "$MH_TEST_COMMON"
+
+require_locale en_US.utf-8 en_US.utf8
+LC_ALL=en_US.UTF-8
+export LC_ALL
+
+tempdir=`TMPDIR=$MH_TEST_DIR mktemp -d -t "XXXXX"`
+cd $tempdir
+
+msgfile=`mhpath b`
+cat > $msgfile <<EOF
+To: recipient@example.com
+From: sender@example.com
+Subject: mhlist test
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
+
+------- =_aaaaaaaaaa0
+Content-Type: multipart/related;
+    type="multipart/alternative";
+    boundary="subpart__1.1"
+
+--subpart__1.1
+Content-Type: text/plain; charset="iso-8859-1"
+Content-Disposition: attachment; filename="=?UTF-8?B?YmzDpGIudHh0?="
+
+This is the first text/plain part, in a subpart.
+
+--subpart__1.1--
+
+------- =_aaaaaaaaaa0
+Content-Type: text/plain; charset="iso-8859-1"
+Content-Disposition: attachment; filename="=?UTF-8?Q?bl=C3=A4.txt?="
+Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
+Content-Transfer-Encoding: quoted-printable
+
+This is the second text/plain part.
+
+------- =_aaaaaaaaaa0
+Content-Type: text/plain; charset="iso-8859-1"; name="test3"
+Content-Disposition: attachment;
+
+This is the third text/plain part.
+
+------- =_aaaaaaaaaa0
+Content-Type: text/plain; charset="iso-8859-1"
+Content-Disposition: attachment; filename="test4"
+Content-Transfer-Encoding: base64
+
+VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
+
+------- =_aaaaaaaaaa0
+Content-Type: text/plain; charset="iso-8859-1"; name="test23"
+Content-Disposition: attachment; filename="test5"
+
+This is the third text/plain part.
+
+------- =_aaaaaaaaaa0
+Content-Type: text/plain; charset="iso-8859-1"
+Content-Disposition: attachment;
+
+This is the third text/plain part.
+
+------- =_aaaaaaaaaa0--
+EOF
+
+msgnum=`pick l`
+
+runandcheck "mhstore l" <<!
+storing message $msgnum part 1.1 as file bläb.txt
+storing message $msgnum part 2 as file blä.txt
+storing message $msgnum part 3 as file test3
+storing message $msgnum part 4 as file test4
+storing message $msgnum part 5 as file test5
+storing message $msgnum part 6 as file $msgnum.6.plain
+!
+
+cd $OLDPWD
+rm -rf $tempdir
index a478b42..2b72e7b 100644 (file)
@@ -234,6 +234,7 @@ get_content(FILE *in, char *file, int toplevel)
        enum state state;
        struct field f = {{0}};
        int compnum;
+       char *buf;
        CT ct;
        HF hp;
 
@@ -259,8 +260,17 @@ get_content(FILE *in, char *file, int toplevel)
                        }
                        compnum++;
 
+                       /* decode rfc2047 */
+                       buf = mh_xcalloc(sizeof(char *), f.valuelen);
+                       if (!decode_rfc2047(f.value, buf, f.valuelen)) {
+                               mh_free0(&buf);
+                               buf = mh_xstrdup(f.value);
+                       }
+
                        /* add the header data to the list */
-                       add_header(ct, mh_xstrdup(f.name), mh_xstrdup(f.value));
+                       add_header(ct, mh_xstrdup(f.name), buf);
+
+                       buf = NULL;
 
                        ct->c_begin = ftell(in) + 1;
                        continue;