Bug 1271864 - when saving message as file, use UTF-8 in case of encoding error. r=aceman
authorJorg K <jorgk@jorgk.com>
Sat, 21 Jan 2017 08:45:48 +0100
changeset 27343 48282013040ad39e8e7736103fd52031449a101b
parent 27342 c3771425de0e070de6d5a5f2e6c62e8116f92379
child 27344 caec227d306587812dec330d815d80061fd2c25e
push id1878
push userclokep@gmail.com
push dateTue, 07 Mar 2017 14:18:40 +0000
treeherdercomm-beta@ab59ffd05575 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman
bugs1271864
Bug 1271864 - when saving message as file, use UTF-8 in case of encoding error. r=aceman
mailnews/base/src/nsMessenger.cpp
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -1852,16 +1852,21 @@ nsSaveMsgListener::OnStopRequest(nsIRequ
     MOZ_ASSERT(m_outputFormat == ePlainText,
       "For HTML, m_doCharsetConversion shouldn't be set");
     NS_ConvertUTF8toUTF16 utf16Buffer(m_msgBuffer);
     ConvertBufToPlainText(utf16Buffer, false, false, false, false);
 
     nsCString outCString;
     rv = nsMsgI18NConvertFromUnicode(nsMsgI18NFileSystemCharset(),
       utf16Buffer, outCString, false, true);
+    if (rv == NS_ERROR_UENC_NOMAPPING) {
+      // If we can't encode with the preferred charset, use UTF-8.
+      CopyUTF16toUTF8(utf16Buffer, outCString);
+      rv = NS_OK;
+    }
     if (NS_SUCCEEDED(rv))
     {
       uint32_t writeCount;
       rv = m_outputStream->Write(outCString.get(), outCString.Length(), &writeCount);
       if (outCString.Length() != writeCount)
         rv = NS_ERROR_FAILURE;
     }
   }