From 025baff48a7551db789c4822815e9ce4f5ddb5fc Mon Sep 17 00:00:00 2001 From: Simon Montagu Date: Thu, 20 Aug 2009 00:59:07 -0700 Subject: [PATCH] Convert messages from UTF-8 to UTF-16 after the whole message has been read instead of while buffering, to prevent corruption when multi-byte sequences are split between buffers. Bug 269812, r=bienvenu, sr=Standard8 --- mailnews/base/src/nsMessenger.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index abf28529c3..4c9c112942 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -251,7 +251,7 @@ public: ePlainText, eHTML } m_outputFormat; - nsString m_msgBuffer; + nsCString m_msgBuffer; nsCString m_contentType; // used only when saving attachment @@ -1661,9 +1661,10 @@ nsSaveMsgListener::OnStopRequest(nsIRequest* request, nsISupports* aSupport, // if (m_outputFormat == ePlainText) { - ConvertBufToPlainText(m_msgBuffer); + NS_ConvertUTF8toUTF16 utf16Buffer(m_msgBuffer); + ConvertBufToPlainText(utf16Buffer); rv = nsMsgI18NSaveAsCharset(TEXT_PLAIN, nsMsgI18NFileSystemCharset(), - m_msgBuffer.get(), &conBuf); + utf16Buffer.get(), &conBuf); if ( NS_SUCCEEDED(rv) && (conBuf) ) conLength = strlen(conBuf); } @@ -1788,7 +1789,7 @@ nsSaveMsgListener::OnDataAvailable(nsIRequest* request, if (NS_SUCCEEDED(rv)) { if ( (m_doCharsetConversion) && (m_outputFormat == ePlainText) ) - m_msgBuffer.Append(NS_ConvertUTF8toUTF16(Substring(m_dataBuffer, m_dataBuffer + readCount))); + m_msgBuffer.Append(Substring(m_dataBuffer, m_dataBuffer + readCount)); else rv = m_outputStream->Write(m_dataBuffer, readCount, &writeCount);