Fix bug 1154521 - jsmime fails on long references header and e-mail gets sent and stored in Sent without headers (regression). r=rkent, a=rkent
authorPhilipp Kewisch <mozilla@kewis.ch>
Sat, 02 May 2015 22:10:16 +0200
changeset 25926 4621293acff7ff33bcfe09b229d0bf09b696d570
parent 25925 47119288c8c59418f27b76c985e72933000430ce
child 25927 7b7d20c7a1973ba6add2e19bdf20f307e0d09f34
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrkent, rkent
bugs1154521
Fix bug 1154521 - jsmime fails on long references header and e-mail gets sent and stored in Sent without headers (regression). r=rkent, a=rkent
mailnews/mime/jsmime/jsmime.js
mailnews/mime/jsmime/test/test_structured_headers.js
--- a/mailnews/mime/jsmime/jsmime.js
+++ b/mailnews/mime/jsmime/jsmime.js
@@ -251,16 +251,25 @@ addHeader("Resent-Message-ID", parseMess
 // Miscellaneous headers (those that don't fall under the above schemes):
 
 // RFC 2047
 structuredDecoders.set("Content-Transfer-Encoding", function (values) {
   return values[0].toLowerCase();
 });
 structuredEncoders.set("Content-Transfer-Encoding", writeUnstructured);
 
+// Some clients like outlook.com send non-compliant References headers that
+// separate values using commas. Temporarily replace commas with spaces until
+// full references header parsing is implemented. See bug 1154521.
+function replaceCommasWithSpaces(values) {
+  return values[0].replace(/,/g, " ");
+}
+structuredDecoders.set("References", replaceCommasWithSpaces);
+structuredDecoders.set("In-Reply-To", replaceCommasWithSpaces);
+
 return Object.freeze({
   decoders: structuredDecoders,
   encoders: structuredEncoders,
   spellings: preferredSpellings,
 });
 
 });
 def('headerparser', function(require) {
--- a/mailnews/mime/jsmime/test/test_structured_headers.js
+++ b/mailnews/mime/jsmime/test/test_structured_headers.js
@@ -133,16 +133,28 @@ suite('Structured headers', function () 
   let date_tests = [
     ["Thu, 06 Sep 2012 08:08:21 -0700", new Date("2012-09-06T08:08:21-0700")],
     ["This is so not a date", new Date(NaN)],
   ];
   date_headers.forEach(function (header) {
     testHeader(header, date_tests);
   });
 
+  let multiple_unstructured_headers = ['In-Reply-To', 'References'];
+  let multiple_unstructured_tests = [
+    ["<asdasdasd@asdasdasd.com>", "<asdasdasd@asdasdasd.com>"],
+    ["<asd@asd.com> <asdf@asdf.com>", "<asd@asd.com> <asdf@asdf.com>"],
+
+    // This test is needed for clients sending non-compliant headers, see bug 1154521
+    ["<asd@asd.com>,<asdf@asdf.com>,<asdfg@asdfg.com>", "<asd@asd.com> <asdf@asdf.com> <asdfg@asdfg.com>"],
+  ];
+  multiple_unstructured_headers.forEach(function (header) {
+    testHeader(header, multiple_unstructured_tests);
+  });
+
   let unstructured_headers = ['Comments', 'Content-Description', 'Keywords',
     'Subject'];
   let unstructured_tests = [
     ["", ""],
     ["This is a subject", "This is a subject"],
     [["Subject 1", "Subject 2"], "Subject 1"],
     ["=?UTF-8?B?56eB44Gv5Lu25ZCN5Y2I5YmN?=",
       "\u79c1\u306f\u4ef6\u540d\u5348\u524d"],