Bug 1143569 - User-agent error when posting to NNTP due to RFC5536 violation of Tb (user-agent header is folded just after user-agent:, "user-agent:[CRLF][SP]Mozilla..."). r=jcranmer, a=rkent
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Thu, 23 Apr 2015 23:03:10 +0300
changeset 25983 6c54d11a4ed56b918fba35b069d6725ae1658e50
parent 25982 7203a728a4c90f3643488b6bbba5e06e0389ee68
child 25984 9a608494ae0ab5403a598a67d2e6c5adebbbcd68
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)
reviewersjcranmer, rkent
bugs1143569
Bug 1143569 - User-agent error when posting to NNTP due to RFC5536 violation of Tb (user-agent header is folded just after user-agent:, "user-agent:[CRLF][SP]Mozilla..."). r=jcranmer, a=rkent
mailnews/mime/jsmime/jsmime.js
mailnews/mime/test/unit/test_EncodeMimePartIIStr_UTF8.js
mailnews/mime/test/unit/test_structured_headers.js
--- a/mailnews/mime/jsmime/jsmime.js
+++ b/mailnews/mime/jsmime/jsmime.js
@@ -2676,17 +2676,17 @@ HeaderEmitter.prototype.addPhrase = func
   if (this._useASCII && nonAsciiRe.test(text)) {
     this.encodeRFC2047Phrase(text, mayBreakAfter);
     return;
   }
 
   // If quoting the entire string at once could fit in the line length, then do
   // so. The check here is very loose, but this will inform is if we are going
   // to definitely overrun the soft margin.
-  if (text.length < this._softMargin) {
+  if ((this._currentLine.length + text.length) < this._softMargin) {
     try {
       this.addQuotable(text, qchars, mayBreakAfter);
       // If we don't have a breakpoint, and the text is encoded as a sequence of
       // atoms (and not a quoted-string), then make the last space we added a
       // breakpoint, regardless of the mayBreakAfter setting.
       if (this._preferredBreakpoint == 0 && text.contains(" ")) {
         if (this._currentLine[this._currentLine.length - 1] != '"')
           this._preferredBreakpoint = this._currentLine.lastIndexOf(" ");
@@ -2830,17 +2830,17 @@ HeaderEmitter.prototype.encodeRFC2047Phr
  * @public
  * @param {String} name The name of the header.
  */
 HeaderEmitter.prototype.addHeaderName = function (name) {
   this._currentLine = this._currentLine.trimRight();
   if (this._currentLine.length > 0) {
     this._commitLine();
   }
-  this.addText(name + ": ", true);
+  this.addText(name + ": ", false);
 };
 
 /**
  * Add a header and its structured value to the output.
  *
  * The name can be any case-insensitive variant of a known structured header;
  * the output will include the preferred name of the structure instead of the
  * case put into the name. If no structured encoder can be found, and the input
--- a/mailnews/mime/test/unit/test_EncodeMimePartIIStr_UTF8.js
+++ b/mailnews/mime/test/unit/test_EncodeMimePartIIStr_UTF8.js
@@ -11,18 +11,18 @@ function run_test() {
 
   var checks =
   [
     ["", false, ""],
     ["\u0436", false, "=?UTF-8?B?0LY=?="], //CYRILLIC SMALL LETTER ZHE
     ["IamASCII", false, "IamASCII"],
     // Although an invalid email, we shouldn't crash on it (bug 479206)
     ["crash test@foo.invalid>", true, "\"crash test\"@foo.invalid"],
-    ["MXR now displays links to Github log & Blame for Gaia/Rust/Servo", false,
-     "MXR now displays links to Github log & Blame for Gaia/Rust/Servo"],
+    ["MXR now displays links to Github log & Blame for\r\n Gaia/Rust/Servo", false,
+     "MXR now displays links to Github log & Blame for\r\n Gaia/Rust/Servo"],
     ["-----------------------:", false, "-----------------------:"],
   ];
 
   for (i = 0; i < checks.length; ++i)
   {
     do_check_eq(
       MailServices.mimeConverter.encodeMimePartIIStr_UTF8(checks[i][0], checks[i][1], "UTF-8", "Subject".length, 72),
       checks[i][2]);
--- a/mailnews/mime/test/unit/test_structured_headers.js
+++ b/mailnews/mime/test/unit/test_structured_headers.js
@@ -163,21 +163,24 @@ add_task(function* check_nsIMimeHeaders(
 });
 
 add_task(function* checkBuildMimeText() {
   let headers = new StructuredHeaders();
   headers.setHeader("To", [{name: "François Smith", email: "user@☃.invalid"}]);
   headers.setHeader("From", [{name: "John Doe", email: "jdoe@test.invalid"}]);
   headers.setHeader("Subject", "A subject that spans a distance quite in " +
     "excess of 80 characters so as to force an intermediary CRLF");
+  headers.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:40.0) Gecko/20100101 Thunderbird/40.0a1");
   let mimeText =
     "To: =?UTF-8?Q?Fran=c3=a7ois_Smith?= <user@☃.invalid>\r\n" +
     "From: John Doe <jdoe@test.invalid>\r\n" +
     "Subject: A subject that spans a distance quite in excess of 80 characters so\r\n" +
-    " as to force an intermediary CRLF\r\n";
+      " as to force an intermediary CRLF\r\n" +
+    "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:40.0) Gecko/20100101\r\n" +
+      " Thunderbird/40.0a1\r\n";
   do_check_eq(headers.buildMimeText(), mimeText);
 
   // Check the version used for the nsIMimeHeaders implementation. This requires
   // initializing with a UTF-8 version.
   let utf8Text = mimeText.replace("☃", "\xe2\x98\x83");
   let mimeHeaders = Cc["@mozilla.org/messenger/mimeheaders;1"]
                       .createInstance(Ci.nsIMimeHeaders);
   mimeHeaders.initialize(utf8Text);