Bug 1498795 - Be more tolerant of spaces in base64-encoded RFC 2047 tokens. r+a=jorgk
authorAlfred Peters <infofrommozilla@gmail.com>
Sat, 05 Jan 2019 10:46:00 +0100
changeset 33927 c45fa8a5db0c4a538ff650a91b93a4e825d9f742
parent 33926 ec30d1b23b43a57e1a18eaded23c7a043a44136f
child 33928 9ecaec399244c48275f18d4dfdf66a5613d15db9
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
bugs1498795
Bug 1498795 - Be more tolerant of spaces in base64-encoded RFC 2047 tokens. r+a=jorgk
mailnews/mime/jsmime/jsmime.js
mailnews/mime/jsmime/test/test_header.js
--- a/mailnews/mime/jsmime/jsmime.js
+++ b/mailnews/mime/jsmime/jsmime.js
@@ -631,17 +631,17 @@ function decodeRFC2047Words(headerValue)
     // language parameter that gets passed in.
     let charset = tokenParts[1].split('*', 1)[0];
     let encoding = tokenParts[2], text = tokenParts[3];
 
     let buffer;
     if (encoding == 'B' || encoding == 'b') {
       // Decode base64. If there's any non-base64 data, treat the string as
       // an illegal token.
-      if (/[^A-Za-z0-9+\/=]/.exec(text))
+      if (/[^ A-Za-z0-9+\/=]/.exec(text))
         return false;
 
       // Decode the string
       buffer = mimeutils.decode_base64(text, false)[0];
     } else if (encoding == 'Q' || encoding == 'q') {
       // Q encoding here looks a lot like quoted-printable text. The differences
       // between quoted-printable and this are that quoted-printable allows you
       // to quote newlines (this doesn't), while this replaces spaces with _.
--- a/mailnews/mime/jsmime/test/test_header.js
+++ b/mailnews/mime/jsmime/test/test_header.js
@@ -620,23 +620,20 @@ suite('headerparser', function () {
         "\u2200  \u2201  \u2202  \u2203  \u2204  \u2205  \u2206  \u2207  " +
         "\u2208  \u2209  \u220a  \u220b  \u220c  \u220d  \u220e  \u220f"],
       ["=?UTF-8?B?4oiAICDiiIEgIOKIgiAg4oiDICDiiIQgIOKIhSAg4oiGICDiiIcgIOKIiA=" +
         "==?=\n =?UTF-8?B?ICDiiIkgIOKIiiAg4oiLICDiiIwgIOKIjSAg4oiOICDiiI8=?=",
         "\u2200  \u2201  \u2202  \u2203  \u2204  \u2205  \u2206  \u2207  " +
         "\u2208  \u2209  \u220a  \u220b  \u220c  \u220d  \u220e  \u220f"],
 
       // Some interesting headers found in the wild:
-      // Invalid base64 text. We decide not to decode this word.
-      ["Re: [Kitchen Nightmares] Meow! Gordon Ramsay Is =?ISO-8859-1?B?UEgR l" +
-        "qZ VuIEhlYWQgVH rbGeOIFNob BJc RP2JzZXNzZW?= With My =?ISO-8859-1?B?" +
-        "SHVzYmFuZ JzX0JhbGxzL JfU2F5c19BbXiScw==?= Baking Company Owner",
-        "Re: [Kitchen Nightmares] Meow! Gordon Ramsay Is =?ISO-8859-1?B?UEgR " +
-        "lqZ VuIEhlYWQgVH rbGeOIFNob BJc RP2JzZXNzZW?= With My =?ISO-8859-1?B" +
-        "?SHVzYmFuZ JzX0JhbGxzL JfU2F5c19BbXiScw==?= Baking Company Owner"],
+      // Bug 1498795: Tolerate spaces in base64-encoded RFC 2047 tokens.
+      ["=?UTF-8?B?Q29uc2lndW Ug dG9kbyBlbCBmw7p0Ym9sIA==?= =?iso-8859-1?" +
+       "B?Y2 9uI EZVU0nTTiBjb24g?= =?windows-1252?B?ZX N 0ZSBvZmVydPNu?=",
+        "Consigue todo el f\u00fatbol con FUSI\u00d3N con este ofert\u00f3n"],
       ["=?us-ascii?Q?=09Edward_Rosten?=", "\tEdward Rosten"],
       ["=?us-ascii?Q?=3D=3FUTF-8=3FQ=3Ff=3DC3=3DBCr=3F=3D?=",
         "=?UTF-8?Q?f=C3=BCr?="],
       // We don't decode unrecognized charsets (This one is actually UTF-8).
       ["=??B?Sy4gSC4gdm9uIFLDvGRlbg==?=", "=??B?Sy4gSC4gdm9uIFLDvGRlbg==?="],
 
       // Test for bug 1374149 with ISO-2022-JP where we shouldn't stream
       // if the first token ends in ESC(B.