fix message threading when message-id is on a continuation line, r=neil,a=Standard8, bug 676916
authorDavid Bienvenu <bienvenu@nventure.com>
Fri, 12 Aug 2011 13:55:15 -0700
changeset 8378 9bb45d76612a41fed16b6488ba99714b71f8132f
parent 8377 cb2c7a7d3b65e74687313111df670727d43b7fba
child 8379 47fc904950ffdb17f5b695be43a9ad2cfc1effc5
push idunknown
push userunknown
push dateunknown
reviewersneil, Standard8, bug
bugs676916
fix message threading when message-id is on a continuation line, r=neil,a=Standard8, bug 676916
mailnews/local/src/nsParseMailbox.cpp
mailnews/local/test/unit/test_msgIDParsing.js
mailnews/local/test/unit/xpcshell.ini
--- a/mailnews/local/src/nsParseMailbox.cpp
+++ b/mailnews/local/src/nsParseMailbox.cpp
@@ -1061,24 +1061,16 @@ int nsParseMailMessageState::ParseHeader
 
       ToLowerCase(headerStr);
       PRInt32 customHeaderIndex = m_customDBHeaders.IndexOf(headerStr);
       if (customHeaderIndex != -1)
         header = & m_customDBHeaderValues[customHeaderIndex];
     }
 
     buf = colon + 1;
-    // eliminate trailing blanks after the colon
-    while (*buf == ' ' || *buf == '\t')
-      buf++;
-
-    value = buf;
-    if (header)
-      header->value = value;
-
     PRUint32 writeOffset = 0; // number of characters replaced with a folded space
 
 SEARCH_NEWLINE:
     // move past any non terminating characters, rewriting them if folding white space
     // exists
     while (*buf != 0 && *buf != '\r' && *buf != '\n')
     {
       if (writeOffset)
@@ -1104,25 +1096,32 @@ SEARCH_NEWLINE:
       *(foldedSpace - writeOffset) = ' ';
       writeOffset += (buf - foldedSpace);
       buf++;
 
       // eliminate any additional white space
       while (buf < buf_end &&
               (*buf == '\n' || *buf == '\r' || *buf == ' ' || *buf == '\t'))
       {
-        *buf++;
+        buf++;
         writeOffset++;
       }
       goto SEARCH_NEWLINE;
     }
 
     if (header)
+    {
+      value = colon + 1;
+      // eliminate trailing blanks after the colon
+      while (*value == ' ' || *value == '\t')
+        value++;
+
+      header->value = value;
       header->length = buf - header->value - writeOffset;
-
+    }
     if (*buf == '\r' || *buf == '\n')
     {
       char *last = buf - writeOffset;
       char *saveBuf = buf;
       if (*buf == '\r' && buf[1] == '\n')
         buf++;
       buf++;
       // null terminate the left-over slop so we don't confuse msg filters.
new file mode 100644
--- /dev/null
+++ b/mailnews/local/test/unit/test_msgIDParsing.js
@@ -0,0 +1,31 @@
+/*
+ * Test bug 676916 - nsParseMailbox parses multi-line message-id header incorrectly
+ */
+
+
+load("../../../resources/mailTestUtils.js");
+var gMessenger = Cc["@mozilla.org/messenger;1"].
+                   createInstance(Ci.nsIMessenger);
+
+loadLocalMailAccount();
+
+let acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
+               .getService(Ci.nsIMsgAccountManager);
+let localAccount = acctMgr.FindAccountForServer(gLocalIncomingServer);
+let identity = acctMgr.createIdentity();
+identity.email = "bob@t2.exemple.net";
+localAccount.addIdentity(identity);
+localAccount.defaultIdentity = identity;
+
+function run_test()
+{
+  var headers = 
+    "from: alice@t1.example.com\r\n" + 
+    "to: bob@t2.exemple.net\r\n" + 
+    "message-id:   \r\n   <abcmessageid>\r\n";
+
+  let localFolder = gLocalInboxFolder.QueryInterface(Ci.nsIMsgLocalMailFolder);
+  gLocalInboxFolder.addMessage("From \r\n"+ headers + "\r\nhello\r\n");
+  var msgHdr = gLocalInboxFolder.GetMessageHeader(0);
+  do_check_eq(msgHdr.messageId, "abcmessageid");
+}
--- a/mailnews/local/test/unit/xpcshell.ini
+++ b/mailnews/local/test/unit/xpcshell.ini
@@ -3,16 +3,17 @@ head = head_maillocal.js
 tail = tail_local.js
 
 [test_bug457168.js]
 [test_fileName.js]
 [test_localSubFolders.js]
 [test_mailboxContentLength.js]
 [test_mailboxProtocol.js]
 [test_msgCopy.js]
+[test_msgIDParsing.js]
 [test_over2GBMailboxes.js]
 [test_over4GBMailboxes.js]
 [test_pop3AuthMethods.js]
 [test_pop3Duplicates.js]
 [test_pop3GSSAPIFail.js]
 [test_pop3GetNewMail.js]
 [test_pop3Password.js]
 [test_pop3Password2.js]