Bug 1202401 - part2 of "Prepare for m-c removal of nsISaveAsCharset.". Don't fall back to ASCII on failure. Fall back to UTF-8! r=jcranmer
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Sat, 21 Nov 2015 22:23:45 +0200
changeset 18621 e90ac2142811ab72bc578a834b0b182c64aadd52
parent 18620 b0fd980cf36e0b12422e6e54af9d55b9c46e5c08
child 18622 7d33cd195765b6f6838da0892f5658a72de06427
push id11403
push usermkmelin@iki.fi
push dateSat, 21 Nov 2015 20:24:44 +0000
treeherdercomm-central@e90ac2142811 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcranmer
bugs1202401
Bug 1202401 - part2 of "Prepare for m-c removal of nsISaveAsCharset.". Don't fall back to ASCII on failure. Fall back to UTF-8! r=jcranmer
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgSend.cpp
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -1170,25 +1170,26 @@ NS_IMETHODIMP nsMsgCompose::SendMsg(MSG_
     m_compFields->GetBody(msgBody);
   }
   if (!msgBody.IsEmpty())
   {
     // Convert body to mail charset
     nsCString outCString;
     rv = nsMsgI18NConvertFromUnicode(m_compFields->GetCharacterSet(),
       msgBody, outCString, false, true);
-    bool isAsciiOnly = NS_IsAscii(outCString.get());
+    bool isAsciiOnly = NS_IsAscii(outCString.get()) &&
+      !nsMsgI18Nstateful_charset(m_compFields->GetCharacterSet());
     if (m_compFields->GetForceMsgEncoding())
       isAsciiOnly = false;
     if (NS_SUCCEEDED(rv) && !outCString.IsEmpty())
     {
       // If the body contains characters outside the repertoire of the current
       // charset, just convert to UTF-8 and be done with it
       // unless disable_fallback_to_utf8 is set for this charset.
-      if (NS_ERROR_UENC_NOMAPPING == rv && m_editor)
+      if (NS_ERROR_UENC_NOMAPPING == rv)
       {
         bool needToCheckCharset;
         m_compFields->GetNeedToCheckCharset(&needToCheckCharset);
         if (needToCheckCharset)
         {
           bool disableFallback = false;
           nsCOMPtr<nsIPrefBranch> prefBranch (do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
           if (prefBranch)
@@ -1205,19 +1206,19 @@ NS_IMETHODIMP nsMsgCompose::SendMsg(MSG_
           }
         }
       }
       m_compFields->SetBodyIsAsciiOnly(isAsciiOnly);
       m_compFields->SetBody(outCString.get());
     }
     else
     {
-      m_compFields->SetBody(NS_LossyConvertUTF16toASCII(msgBody).get());
-      m_compFields->SetCharacterSet("US-ASCII");
-      SetDocumentCharset("US-ASCII");
+      m_compFields->SetBody(NS_ConvertUTF16toUTF8(msgBody).get());
+      m_compFields->SetCharacterSet("UTF-8");
+      SetDocumentCharset("UTF-8");
     }
   }
 
   // Let's open the progress dialog
   if (progress)
   {
     mProgress = progress;
 
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -1563,17 +1563,18 @@ nsMsgComposeAndSend::GetBodyFromEditor()
 
   // Convert body to mail charset
   nsCString    outCString;
   const char  *aCharset = mCompFields->GetCharacterSet();
 
   if (aCharset && *aCharset)
   {
     rv = nsMsgI18NConvertFromUnicode(aCharset, bodyStr, outCString, false, true);
-    bool isAsciiOnly = NS_IsAscii(outCString.get());
+    bool isAsciiOnly = NS_IsAscii(outCString.get()) &&
+      !nsMsgI18Nstateful_charset(mCompFields->GetCharacterSet());
     if (mCompFields->GetForceMsgEncoding())
       isAsciiOnly = false;
     mCompFields->SetBodyIsAsciiOnly(isAsciiOnly);
 
     // If the body contains characters outside the current mail charset,
     // convert to UTF-8.
     if (NS_ERROR_UENC_NOMAPPING == rv)
     {