Bug 1141446 - Handle mal-formed rfc2047 encoded From message header better; r=rkent, a=rkent
authorJorg K <mozilla@jorgk.com>
Thu, 07 May 2015 13:20:09 -0700
changeset 22306 6f83b581985080d8041570514f4461b6d52f180c
parent 22305 9cb911a699c93c1bce05d89c717e46ea4f28bfb7
child 22307 f8df0f149bda5a4756aa0ee5a6f1265f34da3283
push idunknown
push userunknown
push dateunknown
reviewersrkent, rkent
bugs1141446
Bug 1141446 - Handle mal-formed rfc2047 encoded From message header better; r=rkent, a=rkent
mailnews/mime/jsmime/jsmime.js
mailnews/mime/jsmime/test/test_header.js
--- a/mailnews/mime/jsmime/jsmime.js
+++ b/mailnews/mime/jsmime/jsmime.js
@@ -393,21 +393,18 @@ function getHeaderTokens(value, delimite
 
     // If we are in a qstring or a dliteral, process the character only if it is
     // what we are looking for to end the quote.
     if (endQuote !== undefined) {
       if (ch == endQuote && ch == '"') {
         // Quoted strings don't include their delimiters.
         let text = value.slice(tokenStart + 1, i);
 
-        // If RFC 2047 is enabled, decode the qstring only if the entire string
-        // appears to be a 2047 token. Don't unquote just yet (this will better
-        // match people who incorrectly treat RFC 2047 decoding as a separate,
-        // earlier step).
-        if (opts.rfc2047 && text.startsWith("=?") && text.endsWith("?="))
+        // If RFC 2047 is enabled, always decode the qstring.
+        if (opts.rfc2047)
           text = decodeRFC2047Words(text);
 
         tokenList.push(new Token(text));
         endQuote = undefined;
         tokenStart = undefined;
       } else if (ch == endQuote && ch == ']') {
         // Domain literals include their delimiters.
         tokenList.push(new Token(value.slice(tokenStart, i + 1)));
--- a/mailnews/mime/jsmime/test/test_header.js
+++ b/mailnews/mime/jsmime/test/test_header.js
@@ -363,16 +363,34 @@ suite('headerparser', function () {
         [{name: "", email: '"Simple < a"@b.c'}]],
       ["Tag <=?UTF-8?Q?email?=@b.c>", [{name: "Tag", email: "email@b.c"}]],
       // handling of comments and legacy display-names as per RFC 5322 §3.4
       ["jl1@b.c (=?ISO-8859-1?Q?Joe_L=F6we?=)", [{name: "Joe Löwe", email: "jl1@b.c"}]],
       ["(=?ISO-8859-1?Q?Joe_L=F6we?=) jl2@b.c", [{name: "Joe Löwe", email: "jl2@b.c"}]],
       ["(=?ISO-8859-1?Q?Joe_L=F6we?=) jl3@b.c (c2)", [{name: "c2", email: "jl3@b.c"}]],
       ["=?ISO-8859-1?Q?Joe_L=F6we?= <jl3@b.c> (c2)", [{name: "Joe Löwe (c2)", email: "jl3@b.c"}]],
       ["(=?ISO-8859-1?Q?Joe_L=F6we?=) <jl3@b.c> (c2)", [{name: "(Joe Löwe) (c2)", email: "jl3@b.c"}]],
+      // Bug 1141446: Malformed From addresses with erroneous quotes,
+      // note: acute accents: a \u00E1, e \u00E9, i \u00ED, o \u00F3, u \u00FA.
+      ["\"=?UTF-8?Q?Jazzy_Fern=C3=A1ndez_Nunoz?= jazzy.f.nunoz@example.com " +
+        "[BCN-FC]\" <Barcelona-Freecycle-noreply@yahoogroups.com>",
+        [{name: "Jazzy Fern\u00E1ndez Nunoz jazzy.f.nunoz@example.com [BCN-FC]",
+      email: "Barcelona-Freecycle-noreply@yahoogroups.com"}]],
+      ["\"=?UTF-8?B?TWlyaWFtIEJlcm5hYsOpIFBlcmVsbMOz?= miriam@example.com "+
+        "[BCN-FC]\" <Barcelona-Freecycle-noreply@yahoogroups.com>",
+        [{name: "Miriam Bernab\u00E9 Perell\u00F3 miriam@example.com [BCN-FC]",
+      email: "Barcelona-Freecycle-noreply@yahoogroups.com"}]],
+      ["\"=?iso-8859-1?Q?First_Mar=EDa_Furi=F3_Gancho?= mail@yahoo.es "+
+        "[BCN-FC]\" <Barcelona-Freecycle-noreply@yahoogroups.com>",
+        [{name: "First Mar\u00EDa Furi\u00F3 Gancho mail@yahoo.es [BCN-FC]",
+      email: "Barcelona-Freecycle-noreply@yahoogroups.com"}]],
+      ["\"=?iso-8859-1?B?U29maWEgQ2FzdGVsbPMgUm9tZXJv?= sonia@example.com "+
+        "[BCN-FC]\" <Barcelona-Freecycle-noreply@yahoogroups.com>",
+        [{name: "Sofia Castell\u00F3 Romero sonia@example.com [BCN-FC]",
+      email: "Barcelona-Freecycle-noreply@yahoogroups.com"}]],
     ];
     header_tests.forEach(function (data) {
       arrayTest(data, function () {
         assert.deepEqual(headerparser.parseAddressingHeader(data[0], true),
           data[1]);
       });
     });
   });