message save as sometimes inserts extra LF chars, 460636, r/sr=bienvenu
authormozbugzilla@velox.ch
Wed, 22 Oct 2008 15:17:14 -0700
changeset 694 b52bc0e1b57a83f47edca686be91c05d262b80a4
parent 693 aab166693221d134555525041d8d63ccc7a902dd
child 695 13727f26b4a983aa0d4242f3ec1ee8012a09d9df
push id621
push userbienvenu@nventure.com
push dateWed, 22 Oct 2008 22:17:23 +0000
treeherdercomm-central@b52bc0e1b57a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs460636
message save as sometimes inserts extra LF chars, 460636, r/sr=bienvenu
mailnews/base/util/nsMsgMailNewsUrl.cpp
--- a/mailnews/base/util/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp
@@ -817,17 +817,17 @@ NS_IMETHODIMP nsMsgSaveAsListener::OnDat
   if (msgUrl)
     msgUrl->GetCanonicalLineEnding(&useCanonicalEnding);
   
   const char *lineEnding = (useCanonicalEnding) ? CRLF : MSG_LINEBREAK;
   PRUint32 lineEndingLength = (useCanonicalEnding) ? 2 : MSG_LINEBREAK_LEN;
   
   PRUint32 readCount, maxReadCount = SAVE_BUF_SIZE - m_leftOver;
   PRUint32 writeCount;
-  char *start, *end;
+  char *start, *end, lastCharInPrevBuf = '\0';
   PRUint32 linebreak_len = 0;
 
   while (count > 0)
   {
       if (count < maxReadCount)
           maxReadCount = count;
       rv = inStream->Read(m_dataBuffer + m_leftOver,
                           maxReadCount,
@@ -849,16 +849,20 @@ NS_IMETHODIMP nsMsgSaveAsListener::OnDat
 
       count -= readCount;
       maxReadCount = SAVE_BUF_SIZE - m_leftOver;
 
       if (!end && count > maxReadCount)
           // must be a very very long line; sorry cannot handle it
           return NS_ERROR_FAILURE;
 
+      // make sure we don't insert another LF, accidentally
+      if (lastCharInPrevBuf == '\r' && *start == '\n')
+          start++;
+
       while (start && end)
       {
           if (PL_strncasecmp(start, "X-Mozilla-Status:", 17) &&
               PL_strncasecmp(start, "X-Mozilla-Status2:", 18) &&
               PL_strncmp(start, "From - ", 7))
           {
               rv = m_outputStream->Write(start, end-start, &writeCount);
               rv = m_outputStream->Write(lineEnding, lineEndingLength, &writeCount);
@@ -877,16 +881,18 @@ NS_IMETHODIMP nsMsgSaveAsListener::OnDat
           {
               m_leftOver -= (start - m_dataBuffer);
               memcpy(m_dataBuffer, start,
                             m_leftOver+1); // including null
               maxReadCount = SAVE_BUF_SIZE - m_leftOver;
           }
       }
       if (NS_FAILED(rv)) return rv;
+      if (end)
+          lastCharInPrevBuf = *end;
   }
   return rv;
   
   //  rv = m_outputStream->WriteFrom(inStream, PR_MIN(available, count), &bytesWritten);
 }
 
 nsresult nsMsgSaveAsListener::SetupMsgWriteStream(nsIFile *aFile, PRBool addDummyEnvelope)
 {