Bug 1197686 - Preprocess References header. r=jcranmer, a=rkent
authorJorg K <mozilla@jorgk.com>
Thu, 10 Sep 2015 23:20:00 +0200
changeset 22890 48e8ee8813e377fbf9a35a76de0701ed64b47322
parent 22889 0681e92bad2e320308672c8700622536af538f84
child 22891 b1afb50fb6dd8a1eaad071c5a3135f034ea5a027
push id1465
push userkent@caspia.com
push dateMon, 14 Sep 2015 21:51:35 +0000
treeherdercomm-beta@48e8ee8813e3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcranmer, rkent
bugs1197686
Bug 1197686 - Preprocess References header. r=jcranmer, 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
@@ -252,23 +252,29 @@ addHeader("Resent-Message-ID", parseMess
 
 // 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 implemted. See bug 1154521.
-function replaceCommasWithSpaces(values) {
-  return values[0].replace(/,/g, " ");
+// separate values using commas. Also, some clients don't separate References
+// with spaces, since these are optional accordint to RFC2822. So here we
+// preprocess these headers (see bug 1154521 and bug 1197686).
+function preprocessMessageIDs(values) {
+  let msgId = /<[^>]*>/g;
+  let match, ids = [];
+  while ((match = msgId.exec(values)) !== null) {
+    ids.push(match[0]);
+  }
+  return ids.join(' ');
 }
-structuredDecoders.set("References", replaceCommasWithSpaces);
-structuredDecoders.set("In-Reply-To", replaceCommasWithSpaces);
+structuredDecoders.set("References", preprocessMessageIDs);
+structuredDecoders.set("In-Reply-To", preprocessMessageIDs);
 
 return Object.freeze({
   decoders: structuredDecoders,
   encoders: structuredEncoders,
   spellings: preferredSpellings,
 });
 
 });
--- a/mailnews/mime/jsmime/test/test_structured_headers.js
+++ b/mailnews/mime/jsmime/test/test_structured_headers.js
@@ -140,16 +140,18 @@ suite('Structured headers', function () 
 
   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>"],
+    // Test for bug 1197686
+    ["<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 = [