Bug 1410973 - make nsMsgI18NFileSystemCharset() return an nsCString and related clean-up. r=erahm a=IanN DONTBUILD SEAMONKEY_2_49_ESR_RELBRANCH
authorJorg K <jorgk@jorgk.com>
Mon, 13 Nov 2017 23:48:53 +0100
branchSEAMONKEY_2_49_ESR_RELBRANCH
changeset 28320 cb7e2c0d38be0d7b2dfb3136d2de433d9879fa15
parent 28319 3d893021229caef57831f03b40960a4b3bc2736d
child 28321 8db1b7bb3957e05d5d4d9390a9f1a11fcdd43a07
push id2136
push userfrgrahl@gmx.net
push dateMon, 15 Jul 2019 16:13:42 +0000
treeherdercomm-esr52@6b30146aa411 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm, IanN
bugs1410973
Bug 1410973 - make nsMsgI18NFileSystemCharset() return an nsCString and related clean-up. r=erahm a=IanN DONTBUILD SeaMonkey ESR52 release branch only.
mailnews/addrbook/src/nsAbManager.cpp
mailnews/base/search/src/nsMsgSearchAdapter.cpp
mailnews/base/search/src/nsMsgSearchTerm.cpp
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/base/util/nsMsgI18N.cpp
mailnews/base/util/nsMsgI18N.h
mailnews/compose/src/nsMsgAttachmentHandler.cpp
mailnews/compose/src/nsMsgCompUtils.cpp
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgComposeService.cpp
mailnews/compose/src/nsMsgSend.cpp
mailnews/import/becky/src/nsBeckyUtils.cpp
mailnews/import/outlook/src/MapiMessage.cpp
mailnews/import/outlook/src/nsOutlookCompose.cpp
mailnews/import/text/src/nsTextAddress.cpp
mailnews/mapi/mapihook/src/msgMapiHook.cpp
mailnews/mime/src/mimedrft.cpp
mailnews/mime/src/mimehdrs.cpp
mailnews/mime/src/mimemsg.cpp
mailnews/mime/src/mimetpfl.cpp
mailnews/mime/src/mimetpla.cpp
mailnews/news/src/nsNNTPProtocol.cpp
mailnews/news/src/nsNewsFolder.cpp
mailnews/news/src/nsNntpIncomingServer.cpp
--- a/mailnews/addrbook/src/nsAbManager.cpp
+++ b/mailnews/addrbook/src/nsAbManager.cpp
@@ -712,18 +712,20 @@ nsAbManager::ExportDirectoryToDelimitedT
   for (i = 0; i < ArrayLength(EXPORT_ATTRIBUTES_TABLE); i++) {
     if (EXPORT_ATTRIBUTES_TABLE[i].plainTextStringID != 0) {
 
       // We don't need to truncate the string here as getter_Copies will
       // do that for us.
       if (NS_FAILED(bundle->GetStringFromID(EXPORT_ATTRIBUTES_TABLE[i].plainTextStringID, getter_Copies(columnName))))
         columnName.AppendInt(EXPORT_ATTRIBUTES_TABLE[i].plainTextStringID);
 
-      rv = nsMsgI18NConvertFromUnicode(useUTF8 ? "UTF-8" : nsMsgI18NFileSystemCharset(),
-                                       columnName, revisedName);
+      rv = nsMsgI18NConvertFromUnicode(useUTF8 ? NS_LITERAL_CSTRING("UTF-8") :
+                                                 nsMsgI18NFileSystemCharset(),
+                                       columnName,
+                                       revisedName);
       NS_ENSURE_SUCCESS(rv,rv);
 
       rv = outputStream->Write(revisedName.get(),
                                revisedName.Length(),
                                &writeCount);
       NS_ENSURE_SUCCESS(rv,rv);
 
       if (revisedName.Length() != writeCount)
@@ -803,18 +805,20 @@ nsAbManager::ExportDirectoryToDelimitedT
                   needsQuotes = true;
 
               if (needsQuotes)
               {
                 newValue.Insert(NS_LITERAL_STRING("\""), 0);
                 newValue.AppendLiteral("\"");
               }
 
-              rv = nsMsgI18NConvertFromUnicode(useUTF8 ? "UTF-8" : nsMsgI18NFileSystemCharset(),
-                                               newValue, valueCStr);
+              rv = nsMsgI18NConvertFromUnicode(useUTF8 ? NS_LITERAL_CSTRING("UTF-8") :
+                                                         nsMsgI18NFileSystemCharset(),
+                                               newValue,
+                                               valueCStr);
               NS_ENSURE_SUCCESS(rv,rv);
 
               if (NS_FAILED(rv)) {
                 NS_ERROR("failed to convert string to system charset.  use LDIF");
                 valueCStr = "?";
               }
 
               length = valueCStr.Length();
--- a/mailnews/base/search/src/nsMsgSearchAdapter.cpp
+++ b/mailnews/base/search/src/nsMsgSearchAdapter.cpp
@@ -550,17 +550,18 @@ nsresult nsMsgSearchAdapter::EncodeImapT
         // do all sorts of crazy escaping
         convertedValue = reallyDredd ? EscapeSearchUrl (searchTermValue.get()) :
         EscapeImapSearchProtocol(searchTermValue.get());
         useQuotes = ((!reallyDredd ||
                     (nsDependentString(convertedValue).FindChar(char16_t(' ')) != -1)) &&
            (attrib != nsMsgSearchAttrib::Keywords));
         // now convert to char* and escape quoted_specials
         nsAutoCString valueStr;
-        nsresult rv = ConvertFromUnicode(NS_LossyConvertUTF16toASCII(destCharset).get(),
+        nsresult rv = nsMsgI18NConvertFromUnicode(
+          NS_LossyConvertUTF16toASCII(destCharset),
           nsDependentString(convertedValue), valueStr);
         if (NS_SUCCEEDED(rv))
         {
           const char *vptr = valueStr.get();
           // max escaped length is one extra character for every character in the cmd.
           mozilla::UniquePtr<char[]> newValue = mozilla::MakeUnique<char[]>(2*strlen(vptr) + 1);
           if (newValue)
           {
--- a/mailnews/base/search/src/nsMsgSearchTerm.cpp
+++ b/mailnews/base/search/src/nsMsgSearchTerm.cpp
@@ -1115,17 +1115,19 @@ nsresult nsMsgSearchTerm::MatchString(co
     if (!stringToMatch.IsEmpty())
       result = true;
   }
   else
   {
     nsAutoString utf16StrToMatch;
     if (charset != nullptr)
     {
-      ConvertToUnicode(charset, nsCString(stringToMatch), utf16StrToMatch);
+      nsMsgI18NConvertToUnicode(nsDependentCString(charset),
+                                stringToMatch,
+                                utf16StrToMatch);
     }
     else {
       NS_ASSERTION(MsgIsUTF8(stringToMatch), "stringToMatch is not UTF-8");
       CopyUTF8toUTF16(stringToMatch, utf16StrToMatch);
     }
     rv = MatchString(utf16StrToMatch, &result);
   }
 
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -5618,17 +5618,17 @@ NS_IMETHODIMP nsMsgDBFolder::GetMsgTextF
 
   // if the snippet is encoded, decode it
   if (!encoding.IsEmpty())
     decodeMsgSnippet(NS_ConvertUTF16toUTF8(encoding), !reachedEndBody, msgText);
 
   // In order to turn our snippet into unicode, we need to convert it from the charset we
   // detected earlier.
   nsString unicodeMsgBodyStr;
-  ConvertToUnicode(charset.get(), msgText, unicodeMsgBodyStr);
+  nsMsgI18NConvertToUnicode(charset, msgText, unicodeMsgBodyStr);
 
   // now we've got a msg body. If it's html, convert it to plain text.
   if (msgBodyIsHtml && aStripHTMLTags)
     ConvertMsgSnippetToPlainText(unicodeMsgBodyStr, unicodeMsgBodyStr);
 
   // We want to remove any whitespace from the beginning and end of the string
   unicodeMsgBodyStr.Trim(" \t\r\n", true, true);
 
--- a/mailnews/base/util/nsMsgI18N.cpp
+++ b/mailnews/base/util/nsMsgI18N.cpp
@@ -26,58 +26,59 @@
 #include "nsCRTGlue.h"
 #include "nsComponentManagerUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsIFileStreams.h"
 //
 // International functions necessary for composition
 //
 
-nsresult nsMsgI18NConvertFromUnicode(const char* aCharset,
-                                     const nsString& inString,
+nsresult nsMsgI18NConvertFromUnicode(const nsACString& aCharset,
+                                     const nsAString& inString,
                                      nsACString& outString,
                                      bool aIsCharsetCanonical,
                                      bool aReportUencNoMapping)
 {
   if (inString.IsEmpty()) {
     outString.Truncate();
     return NS_OK;
   }
   // Note: This will hide a possible error if the Unicode contains more than one
   // charset, e.g. Latin1 + Japanese.
-  else if (!aReportUencNoMapping && (!*aCharset ||
-             !PL_strcasecmp(aCharset, "us-ascii") ||
-             !PL_strcasecmp(aCharset, "ISO-8859-1"))) {
+  else if (!aReportUencNoMapping &&
+           (aCharset.IsEmpty() ||
+            aCharset.Equals("us-ascii", nsCaseInsensitiveCStringComparator()) ||
+            aCharset.Equals("ISO-8859-1", nsCaseInsensitiveCStringComparator()))) {
     LossyCopyUTF16toASCII(inString, outString);
     return NS_OK;
   }
-  else if (!PL_strcasecmp(aCharset, "UTF-8")) {
+  else if (aCharset.Equals("UTF-8", nsCaseInsensitiveCStringComparator())) {
     CopyUTF16toUTF8(inString, outString);
     return NS_OK;
   }
 
   nsresult rv;
   nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr <nsIUnicodeEncoder> encoder;
 
   // get an unicode converter
   if (aIsCharsetCanonical)  // optimize for modified UTF-7 used by IMAP
-    rv = ccm->GetUnicodeEncoderRaw(aCharset, getter_AddRefs(encoder));
+    rv = ccm->GetUnicodeEncoderRaw(PromiseFlatCString(aCharset).get(), getter_AddRefs(encoder));
   else
-    rv = ccm->GetUnicodeEncoder(aCharset, getter_AddRefs(encoder));
+    rv = ccm->GetUnicodeEncoder(PromiseFlatCString(aCharset).get(), getter_AddRefs(encoder));
   NS_ENSURE_SUCCESS(rv, rv);
   // Must set behavior to kOnError_Signal if we want to receive the
   // NS_ERROR_UENC_NOMAPPING signal, should it occur.
   int32_t behavior = aReportUencNoMapping ? nsIUnicodeEncoder::kOnError_Signal:
     nsIUnicodeEncoder::kOnError_Replace;
   rv = encoder->SetOutputErrorBehavior(behavior, nullptr, '?');
   NS_ENSURE_SUCCESS(rv, rv);
 
-  const char16_t *originalSrcPtr = inString.get();
+  const char16_t *originalSrcPtr = inString.BeginReading();;
   const char16_t *currentSrcPtr = originalSrcPtr;
   int32_t originalUnicharLength = inString.Length();
   int32_t srcLength;
   int32_t dstLength;
   char localbuf[512+10]; // We have seen cases were the buffer was overrun
                          // by two (!!) bytes (Bug 1255863).
                          // So give it ten bytes more for now to avoid a crash.
   int32_t consumedLen = 0;
@@ -111,32 +112,33 @@ nsresult nsMsgI18NConvertFromUnicode(con
   if (NS_SUCCEEDED(rv)) {
     if (dstLength)
       outString.Append(localbuf, dstLength);
     return !mappingFailure ? rv: NS_ERROR_UENC_NOMAPPING;
   }
   return rv;
 }
 
-nsresult nsMsgI18NConvertToUnicode(const char* aCharset,
-                                   const nsCString& inString, 
+nsresult nsMsgI18NConvertToUnicode(const nsACString& aCharset,
+                                   const nsACString& inString,
                                    nsAString& outString,
                                    bool aIsCharsetCanonical)
 {
   if (inString.IsEmpty()) {
     outString.Truncate();
     return NS_OK;
   }
-  else if (!*aCharset || !PL_strcasecmp(aCharset, "us-ascii") ||
-           !PL_strcasecmp(aCharset, "ISO-8859-1")) {
+  else if (aCharset.IsEmpty() || 
+           aCharset.Equals("us-ascii", nsCaseInsensitiveCStringComparator()) ||
+           aCharset.Equals("ISO-8859-1", nsCaseInsensitiveCStringComparator())) {
     // Despite its name, it also works for Latin-1.
     CopyASCIItoUTF16(inString, outString);
     return NS_OK;
   }
-  else if (!PL_strcasecmp(aCharset, "UTF-8")) {
+  else if (aCharset.Equals("UTF-8", nsCaseInsensitiveCStringComparator())) {
     if (MsgIsUTF8(inString)) {
       nsAutoString tmp;
       CopyUTF8toUTF16(inString, tmp);
       if (!tmp.IsEmpty() && tmp.First() == char16_t(0xFEFF))
         tmp.Cut(0, 1);
       outString.Assign(tmp);
       return NS_OK;
     }
@@ -147,22 +149,22 @@ nsresult nsMsgI18NConvertToUnicode(const
   nsresult rv;
   nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr <nsIUnicodeDecoder> decoder;
 
   // get an unicode converter
   if (aIsCharsetCanonical)  // optimize for modified UTF-7 used by IMAP
-    rv = ccm->GetUnicodeDecoderRaw(aCharset, getter_AddRefs(decoder));
+    rv = ccm->GetUnicodeDecoderRaw(PromiseFlatCString(aCharset).get(), getter_AddRefs(decoder));
   else
-    rv = ccm->GetUnicodeDecoderInternal(aCharset, getter_AddRefs(decoder));
+    rv = ccm->GetUnicodeDecoderInternal(PromiseFlatCString(aCharset).get(), getter_AddRefs(decoder));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  const char *originalSrcPtr = inString.get();
+  const char *originalSrcPtr = inString.BeginReading();
   const char *currentSrcPtr = originalSrcPtr;
   int32_t originalLength = inString.Length();
   int32_t srcLength;
   int32_t dstLength;
   char16_t localbuf[512];
   int32_t consumedLen = 0;
 
   outString.Truncate();
@@ -178,34 +180,34 @@ nsresult nsMsgI18NConvertToUnicode(const
 
     currentSrcPtr += srcLength;
     consumedLen = currentSrcPtr - originalSrcPtr; // src length used so far
   }
   return rv;
 }
 
 // Charset used by the file system.
-const char * nsMsgI18NFileSystemCharset()
+const nsACString& nsMsgI18NFileSystemCharset()
 {
   /* Get a charset used for the file. */
   static nsAutoCString fileSystemCharset;
 
   if (fileSystemCharset.IsEmpty()) 
   {
     nsresult rv;
     nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
         if (NS_SUCCEEDED(rv)) {
           rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName,
                                            fileSystemCharset);
         }
 
     if (NS_FAILED(rv)) 
       fileSystemCharset.Assign("ISO-8859-1");
   }
-  return fileSystemCharset.get();
+  return fileSystemCharset;
 }
 
 // Charset used by the text file.
 void nsMsgI18NTextFileCharset(nsACString& aCharset)
 {
   nsresult rv;
   nsCOMPtr <nsIPlatformCharset> platformCharset =
     do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
@@ -220,18 +222,20 @@ void nsMsgI18NTextFileCharset(nsACString
 
 // MIME encoder, output string should be freed by PR_FREE
 // XXX : fix callers later to avoid allocation and copy
 char * nsMsgI18NEncodeMimePartIIStr(const char *header, bool structured, const char *charset, int32_t fieldnamelen, bool usemime) 
 {
   // No MIME, convert to the outgoing mail charset.
   if (false == usemime) {
     nsAutoCString convertedStr;
-    if (NS_SUCCEEDED(ConvertFromUnicode(charset, NS_ConvertUTF8toUTF16(header),
-                                        convertedStr)))
+    if (NS_SUCCEEDED(nsMsgI18NConvertFromUnicode(nsDependentCString(charset),
+                                                 NS_ConvertUTF8toUTF16(header),
+                                                 convertedStr)))
+
       return PL_strdup(convertedStr.get());
     else
       return PL_strdup(header);
   }
 
   nsAutoCString encodedString;
   nsresult res;
   nsCOMPtr<nsIMimeConverter> converter = do_GetService(NS_MIME_CONVERTER_CONTRACTID, &res);
@@ -307,17 +311,17 @@ bool nsMsgI18Ncheck_data_in_charset_rang
         consumedLen = currentSrcPtr - originalPtr; // src length used so far
       }
     }    
   }
 
   // if the conversion was not successful then try fallback to other charsets
   if (!result && fallbackCharset) {
     nsCString convertedString;
-    res = nsMsgI18NConvertFromUnicode(*fallbackCharset,
+    res = nsMsgI18NConvertFromUnicode(nsDependentCString(*fallbackCharset),
       nsDependentString(inString), convertedString, false, true);
     result = (NS_SUCCEEDED(res) && NS_ERROR_UENC_NOMAPPING != res);
   }
 
   return result;
 }
 
 // Simple parser to parse META charset. 
@@ -416,53 +420,53 @@ nsresult nsMsgI18NShrinkUTF8Str(const ns
     return NS_OK;
   }
   uint32_t len = prev - start;
   outString.Assign(Substring(inString, 0, len));
   return NS_OK;
 }
 
 void nsMsgI18NConvertRawBytesToUTF16(const nsCString& inString, 
-                                     const char* charset,
+                                     const nsACString& charset,
                                      nsAString& outString)
 {
   if (MsgIsUTF8(inString))
   {
     CopyUTF8toUTF16(inString, outString);
     return;
   }
 
-  nsresult rv = ConvertToUnicode(charset, inString, outString);
+  nsresult rv = nsMsgI18NConvertToUnicode(charset, inString, outString);
   if (NS_SUCCEEDED(rv))
     return;
 
   const char* cur = inString.BeginReading();
   const char* end = inString.EndReading();
   outString.Truncate();
   while (cur < end) {
     char c = *cur++;
     if (c & char(0x80))
       outString.Append(UCS2_REPLACEMENT_CHAR);
     else
       outString.Append(c);
   }
 }
 
 void nsMsgI18NConvertRawBytesToUTF8(const nsCString& inString, 
-                                    const char* charset,
+                                    const nsACString& charset,
                                     nsACString& outString)
 {
   if (MsgIsUTF8(inString))
   {
     outString.Assign(inString);
     return;
   }
 
   nsAutoString utf16Text;
-  nsresult rv = ConvertToUnicode(charset, inString, utf16Text);
+  nsresult rv = nsMsgI18NConvertToUnicode(charset, inString, utf16Text);
   if (NS_SUCCEEDED(rv))
   {
     CopyUTF16toUTF8(utf16Text, outString);
     return;
   }
 
   // EF BF BD (UTF-8 encoding of U+FFFD)
   NS_NAMED_LITERAL_CSTRING(utf8ReplacementChar, "\357\277\275");
--- a/mailnews/base/util/nsMsgI18N.h
+++ b/mailnews/base/util/nsMsgI18N.h
@@ -55,17 +55,17 @@ NS_MSG_BASE bool nsMsgI18Nmultibyte_char
 NS_MSG_BASE bool      nsMsgI18Ncheck_data_in_charset_range(const char *charset, const char16_t* inString,
                                                            char **fallbackCharset=nullptr);
 
 /**
  * Return charset name of file system (OS dependent).
  *
  * @return            File system charset name.
  */
-NS_MSG_BASE const char * nsMsgI18NFileSystemCharset(void);
+NS_MSG_BASE const nsACString& nsMsgI18NFileSystemCharset(void);
 
 /**
  * Return charset name of text file (OS dependent).
  *
  * @param aCharset    [OUT] Text file charset name.
  */
 NS_MSG_BASE void nsMsgI18NTextFileCharset(nsACString& aCharset);
 
@@ -78,33 +78,33 @@ NS_MSG_BASE void nsMsgI18NTextFileCharse
  * @param aIsCharsetCanonical  [IN] Whether the charset is canonical or not.
  * @param aReportUencNoMapping [IN] Set encoder to report (instead of using
  *                                  replacement char on errors). Set to true
  *                                  to receive NS_ERROR_UENC_NOMAPPING when
  *                                  that happens. Note that
  *                                  NS_ERROR_UENC_NOMAPPING is a success code!
  * @return            nsresult.
  */
-NS_MSG_BASE nsresult nsMsgI18NConvertFromUnicode(const char* aCharset,
-                                                 const nsString& inString,
+NS_MSG_BASE nsresult nsMsgI18NConvertFromUnicode(const nsACString& aCharset,
+                                                 const nsAString& inString,
                                                  nsACString& outString,
                                                  bool aIsCharsetCanonical =
                                                         false,
                                                  bool reportUencNoMapping =
                                                         false);
 /**
  * Convert from charset to unicode.
  *
  * @param charset     [IN] Charset name.
  * @param inString    [IN] Input string to convert.
  * @param outString   [OUT] Output unicode string.
  * @return            nsresult.
  */
-NS_MSG_BASE nsresult nsMsgI18NConvertToUnicode(const char* aCharset,
-                                               const nsCString& inString,
+NS_MSG_BASE nsresult nsMsgI18NConvertToUnicode(const nsACString& aCharset,
+                                               const nsACString& inString,
                                                nsAString& outString,
                                                bool aIsCharsetCanonical =
                                                       false);
 /**
  * Parse for META charset.
  *
  * @param file    [IN] A nsIFile.
  * @return            A charset name or empty string if not found.
@@ -125,74 +125,36 @@ NS_MSG_BASE nsresult nsMsgI18NShrinkUTF8
                                             nsACString &outString);
 
 /*
  * Convert raw bytes in header to UTF-16
  *
  * @param inString   [IN] Input raw octets
  * @param outString  [OUT] Output UTF-16 string
  */
-NS_MSG_BASE void nsMsgI18NConvertRawBytesToUTF16(const nsCString& inString, 
-                                                 const char* charset,
+NS_MSG_BASE void nsMsgI18NConvertRawBytesToUTF16(const nsCString& inString,
+                                                 const nsACString& charset,
                                                  nsAString& outString);
 
 /*
  * Convert raw bytes in header to UTF-8
  *
  * @param inString   [IN] Input raw octets
  * @param outString  [OUT] Output UTF-8 string
  */
-NS_MSG_BASE void nsMsgI18NConvertRawBytesToUTF8(const nsCString& inString, 
-                                                const char* charset,
+NS_MSG_BASE void nsMsgI18NConvertRawBytesToUTF8(const nsCString& inString,
+                                                const nsACString& charset,
                                                 nsACString& outString);
 
 // inline forwarders to avoid littering with 'x-imap4-.....'
 inline nsresult CopyUTF16toMUTF7(const nsString &aSrc, nsACString& aDest)
 {
-    return nsMsgI18NConvertFromUnicode("x-imap4-modified-utf7", aSrc,
+    return nsMsgI18NConvertFromUnicode(NS_LITERAL_CSTRING("x-imap4-modified-utf7"), aSrc,
                                        aDest, true);
 }
 
 inline nsresult CopyMUTF7toUTF16(const nsCString& aSrc, nsAString& aDest)
 {
-    return nsMsgI18NConvertToUnicode("x-imap4-modified-utf7", aSrc,
+    return nsMsgI18NConvertToUnicode(NS_LITERAL_CSTRING("x-imap4-modified-utf7"), aSrc,
                                      aDest, true);
 }
 
-inline nsresult ConvertToUnicode(const char* charset,
-                                 const nsCString &aSrc, nsAString& aDest)
-{
-    return nsMsgI18NConvertToUnicode(charset, aSrc, aDest);
-}
-
-inline nsresult ConvertToUnicode(const char* charset,
-                                 const char* aSrc, nsAString& aDest)
-{
-    return nsMsgI18NConvertToUnicode(charset, nsDependentCString(aSrc), aDest);
-}
-
-inline nsresult ConvertFromUnicode(const char* charset,
-                                   const nsString &aSrc, nsACString& aDest)
-{
-    return nsMsgI18NConvertFromUnicode(charset, aSrc, aDest);
-}
-
-inline void ConvertRawBytesToUTF16(const nsCString& inString, 
-                                   const char* charset, nsAString& outString)
-{
-    return nsMsgI18NConvertRawBytesToUTF16(inString, charset, outString);
-}
-
-inline void ConvertRawBytesToUTF16(const char* inString, 
-                                   const char* charset, nsAString& outString)
-{
-    return nsMsgI18NConvertRawBytesToUTF16(nsDependentCString(inString),
-                                           charset,
-                                           outString);
-}
-
-inline void ConvertRawBytesToUTF8(const nsCString& inString, 
-                                  const char* charset, nsACString& outString)
-{
-    return nsMsgI18NConvertRawBytesToUTF8(inString, charset, outString);
-}
-
 #endif /* _nsMsgI18N_H_ */
--- a/mailnews/compose/src/nsMsgAttachmentHandler.cpp
+++ b/mailnews/compose/src/nsMsgAttachmentHandler.cpp
@@ -1044,17 +1044,17 @@ nsMsgAttachmentHandler::LoadDataFromFile
 
   uint32_t bytesRead;
   inputFile->Read(readBuf, readSize, &bytesRead);
   inputFile->Close();
 
   nsDependentCString cstringReadBuf(readBuf, bytesRead);
   if (charsetConversion)
   {
-    if (NS_FAILED(ConvertToUnicode(m_charset.get(), cstringReadBuf, sigData)))
+    if (NS_FAILED(nsMsgI18NConvertToUnicode(m_charset, cstringReadBuf, sigData)))
       CopyASCIItoUTF16(cstringReadBuf, sigData);
   }
   else
     CopyASCIItoUTF16(cstringReadBuf, sigData);
 
   PR_FREEIF(readBuf);
   return NS_OK;
 }
@@ -1223,17 +1223,17 @@ nsMsgAttachmentHandler::UrlExit(nsresult
 
         nsCOMPtr<nsIOutputStream> outputStream;
         nsresult rv = MsgNewBufferedFileOutputStream(getter_AddRefs(outputStream), mTmpFile,
                                                      PR_WRONLY | PR_CREATE_FILE, 00600);
 
         if (NS_SUCCEEDED(rv))
         {
           nsAutoCString tData;
-          if (NS_FAILED(ConvertFromUnicode(m_charset.get(), conData, tData)))
+          if (NS_FAILED(nsMsgI18NConvertFromUnicode(m_charset, conData, tData)))
             LossyCopyUTF16toASCII(conData, tData);
           if (!tData.IsEmpty())
           {
             uint32_t bytesWritten;
             (void) outputStream->Write(tData.get(), tData.Length(), &bytesWritten);
           }
           outputStream->Close();
           // this silliness is because Windows nsIFile caches its file size
--- a/mailnews/compose/src/nsMsgCompUtils.cpp
+++ b/mailnews/compose/src/nsMsgCompUtils.cpp
@@ -603,17 +603,17 @@ mime_generate_attachment_headers (const 
     // first try main body's charset to encode the file name,
     // then try local file system charset if fails
     CopyUTF8toUTF16(nsDependentCString(real_name), realName);
     if (bodyCharset && *bodyCharset &&
         nsMsgI18Ncheck_data_in_charset_range(bodyCharset, realName.get()))
       charset.Assign(bodyCharset);
     else
     {
-      charset.Assign(nsMsgI18NFileSystemCharset());
+      charset = nsMsgI18NFileSystemCharset();
       if (!nsMsgI18Ncheck_data_in_charset_range(charset.get(), realName.get()))
         charset.Assign("UTF-8"); // set to UTF-8 if fails again
     }
 
     encodedRealName = RFC2231ParmFolding("filename", charset, nullptr,
                                          realName);
     // somehow RFC2231ParamFolding failed. fall back to legacy method
     if (!encodedRealName || !*encodedRealName) {
@@ -973,17 +973,17 @@ RFC2231ParmFolding(const char *parmName,
   NS_ENSURE_TRUE(parmName && *parmName && !parmValue.IsEmpty(), nullptr);
 
   bool needEscape;
   nsCString dupParm;
 
   if (!NS_IsAscii(parmValue.get()) || is7bitCharset(charset)) {
     needEscape = true;
     nsAutoCString nativeParmValue;
-    ConvertFromUnicode(charset.get(), parmValue, nativeParmValue);
+    nsMsgI18NConvertFromUnicode(charset, parmValue, nativeParmValue);
     MsgEscapeString(nativeParmValue, nsINetUtil::ESCAPE_ALL, dupParm);
   }
   else {
     needEscape = false;
     dupParm.Adopt(
       msg_make_filename_qtext(NS_LossyConvertUTF16toASCII(parmValue).get(),
                               true));
   }
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -1346,18 +1346,18 @@ NS_IMETHODIMP nsMsgCompose::SendMsg(MSG_
   else
   {
     m_compFields->GetBody(msgBody);
   }
   if (!msgBody.IsEmpty())
   {
     // Convert body to mail charset
     nsCString outCString;
-    rv = nsMsgI18NConvertFromUnicode(m_compFields->GetCharacterSet(),
-      msgBody, outCString, false, true);
+    rv = nsMsgI18NConvertFromUnicode(nsDependentCString(m_compFields->GetCharacterSet()),
+                                     msgBody, outCString, false, true);
     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
@@ -2584,35 +2584,35 @@ NS_IMETHODIMP QuotingOutputStreamListene
               NS_ENSURE_SUCCESS(rv, rv);
               compFields->SetCharacterSet(charset.get());
             }
           }
         }
       }
 
       mHeaders->ExtractHeader(HEADER_FROM, true, outCString);
-      ConvertRawBytesToUTF16(outCString, charset.get(), from);
+      nsMsgI18NConvertRawBytesToUTF16(outCString, charset, from);
 
       mHeaders->ExtractHeader(HEADER_TO, true, outCString);
-      ConvertRawBytesToUTF16(outCString, charset.get(), to);
+      nsMsgI18NConvertRawBytesToUTF16(outCString, charset, to);
 
       mHeaders->ExtractHeader(HEADER_CC, true, outCString);
-      ConvertRawBytesToUTF16(outCString, charset.get(), cc);
+      nsMsgI18NConvertRawBytesToUTF16(outCString, charset, cc);
 
       mHeaders->ExtractHeader(HEADER_BCC, true, outCString);
-      ConvertRawBytesToUTF16(outCString, charset.get(), bcc);
+      nsMsgI18NConvertRawBytesToUTF16(outCString, charset, bcc);
 
       mHeaders->ExtractHeader(HEADER_MAIL_FOLLOWUP_TO, true, outCString);
-      ConvertRawBytesToUTF16(outCString, charset.get(), mailFollowupTo);
+      nsMsgI18NConvertRawBytesToUTF16(outCString, charset, mailFollowupTo);
 
       mHeaders->ExtractHeader(HEADER_REPLY_TO, false, outCString);
-      ConvertRawBytesToUTF16(outCString, charset.get(), replyTo);
+      nsMsgI18NConvertRawBytesToUTF16(outCString, charset, replyTo);
 
       mHeaders->ExtractHeader(HEADER_MAIL_REPLY_TO, true, outCString);
-      ConvertRawBytesToUTF16(outCString, charset.get(), mailReplyTo);
+      nsMsgI18NConvertRawBytesToUTF16(outCString, charset, mailReplyTo);
 
       mHeaders->ExtractHeader(HEADER_NEWSGROUPS, false, outCString);
       if (!outCString.IsEmpty())
         mMimeConverter->DecodeMimeHeader(outCString.get(), charset.get(),
                                          false, true, newgroups);
 
       mHeaders->ExtractHeader(HEADER_FOLLOWUP_TO, false, outCString);
       if (!outCString.IsEmpty())
@@ -4324,17 +4324,17 @@ nsMsgCompose::LoadDataFromFile(nsIFile *
     }
   }
 
   nsAutoCString readStr(readBuf, (int32_t) fileSize);
   PR_FREEIF(readBuf);
 
   // XXX: ^^^ could really use nsContentUtils::SlurpFileToString instead!
 
-  if (NS_FAILED(ConvertToUnicode(sigEncoding.get(), readStr, sigData)))
+  if (NS_FAILED(nsMsgI18NConvertToUnicode(sigEncoding, readStr, sigData)))
     CopyASCIItoUTF16(readStr, sigData);
 
   //remove sig meta charset to allow user charset override during composition
   if (removeSigCharset)
   {
     nsAutoCString metaCharset("charset=");
     metaCharset.Append(sigEncoding);
     int32_t pos = sigData.Find(metaCharset.BeginReading(), true);
--- a/mailnews/compose/src/nsMsgComposeService.cpp
+++ b/mailnews/compose/src/nsMsgComposeService.cpp
@@ -745,17 +745,17 @@ NS_IMETHODIMP nsMsgTemplateReplyHelper::
 
   compFields->SetSubject(subject);
   compFields->SetRawHeader("Auto-Submitted", NS_LITERAL_CSTRING("auto-replied"), nullptr);
 
   nsCString charset;
   rv = mTemplateHdr->GetCharset(getter_Copies(charset));
   NS_ENSURE_SUCCESS(rv, rv);
   compFields->SetCharacterSet(charset.get());
-  rv = nsMsgI18NConvertToUnicode(charset.get(), mTemplateBody, body);
+  rv = nsMsgI18NConvertToUnicode(charset, mTemplateBody, body);
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "couldn't convert templ body to unicode");
   compFields->SetBody(body);
 
   nsCString msgUri;
   nsCOMPtr <nsIMsgFolder> folder;
   mHdrToReplyTo->GetFolder(getter_AddRefs(folder));
   folder->GetUriForMsg(mHdrToReplyTo, msgUri);
   // populate the compose params
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -1586,17 +1586,21 @@ nsMsgComposeAndSend::GetBodyFromEditor()
   nsCString attachment1_body;
 
   // Convert body to mail charset
   nsCString    outCString;
   const char  *aCharset = mCompFields->GetCharacterSet();
 
   if (aCharset && *aCharset)
   {
-    rv = nsMsgI18NConvertFromUnicode(aCharset, nsDependentString(bodyText), outCString, false, true);
+    rv = nsMsgI18NConvertFromUnicode(nsDependentCString(aCharset),
+                                     nsDependentString(bodyText),
+                                     outCString,
+                                     false,
+                                     true);
     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.
@@ -1628,17 +1632,17 @@ nsMsgComposeAndSend::GetBodyFromEditor()
       attachment1_body = outCString;
 
     // If we have an origHTMLBody that is not null, this means that it is
     // different than the bodyText because of formatting conversions. Because of
     // this we need to do the charset conversion on this part separately
     if (origHTMLBody)
     {
       nsCString newBody;
-      rv = nsMsgI18NConvertFromUnicode(aCharset,
+      rv = nsMsgI18NConvertFromUnicode(nsDependentCString(aCharset),
         nsDependentString(origHTMLBody), newBody, false, true);
       if (NS_SUCCEEDED(rv))
       {
         mOriginalHTMLBody = ToNewCString(newBody);
       }
     }
     else {
       mOriginalHTMLBody = ToNewCString(attachment1_body);
@@ -2528,17 +2532,19 @@ nsMsgComposeAndSend::HackAttachments(nsI
          we need to avoid to call it ourself.
       */
       needToCallGatherMimeAttachments = false;
 
       nsresult status = m_attachments[i]->SnarfAttachment(mCompFields);
       if (NS_FAILED(status))
       {
         nsString errorMsg;
-        nsresult rv = ConvertToUnicode(nsMsgI18NFileSystemCharset(), m_attachments[i]->m_realName, attachmentFileName);
+        nsresult rv = nsMsgI18NConvertToUnicode(nsMsgI18NFileSystemCharset(),
+                                                m_attachments[i]->m_realName,
+                                                attachmentFileName);
         if (attachmentFileName.IsEmpty() && m_attachments[i]->mURL) {
           nsCString asciiSpec;
           m_attachments[i]->mURL->GetAsciiSpec(asciiSpec);
           attachmentFileName.AssignASCII(asciiSpec.get());
           rv = NS_OK;
         }
         if (NS_SUCCEEDED(rv))
         {
@@ -4845,17 +4851,19 @@ nsMsgComposeAndSend::GetSendBody(nsAStri
 {
   nsCString charSet;
   if (mCompFields)
     mCompFields->GetCharacterSet(getter_Copies(charSet));
   if (!m_attachment1_body) {
     aBody.Truncate();
     return NS_OK;
   }
-  return ConvertToUnicode(charSet.get(), m_attachment1_body, aBody);
+  return nsMsgI18NConvertToUnicode(charSet,
+                                   nsDependentCString(m_attachment1_body),
+                                   aBody);
 }
 
 NS_IMETHODIMP
 nsMsgComposeAndSend::GetSendBodyType(nsACString& aBodyType)
 {
   if (m_attachment1_type && *m_attachment1_type)
     aBodyType.Assign(nsDependentCString(m_attachment1_type));
   return NS_OK;
--- a/mailnews/import/becky/src/nsBeckyUtils.cpp
+++ b/mailnews/import/becky/src/nsBeckyUtils.cpp
@@ -290,17 +290,20 @@ nsBeckyUtils::ConvertToUTF8File(nsIFile 
   rv = NS_NewLocalFileOutputStream(getter_AddRefs(destination),
                                    convertedFile);
   NS_ENSURE_SUCCESS(rv, rv);
 
   const uint32_t kBlock = 8192;
 
   nsCOMPtr<nsIConverterInputStream> convertedInput =
     do_CreateInstance("@mozilla.org/intl/converter-input-stream;1");
-  convertedInput->Init(source, nsMsgI18NFileSystemCharset(), kBlock, 0x0000);
+  convertedInput->Init(source,
+                       PromiseFlatCString(nsMsgI18NFileSystemCharset()).get(),
+                       kBlock,
+                       0x0000);
 
   nsCOMPtr<nsIConverterOutputStream> convertedOutput =
     do_CreateInstance("@mozilla.org/intl/converter-output-stream;1");
   convertedOutput->Init(destination, "UTF-8", kBlock, 0x0000);
 
   char16_t *line = (char16_t *)moz_xmalloc(kBlock);
   uint32_t readBytes = kBlock;
   bool writtenBytes;
--- a/mailnews/import/outlook/src/MapiMessage.cpp
+++ b/mailnews/import/outlook/src/MapiMessage.cpp
@@ -733,35 +733,35 @@ bool CMapiMessage::FetchBody(void)
     const char* charset = CpToCharset(codepage);
     if (charset) {
       bFoundCharset = CheckBodyInCharsetRange(charset);
       if (bFoundCharset)
         m_mimeCharset.Assign(charset);
     }
   }
   if (!bFoundCharset) { // Use system default
-    const char* charset = nsMsgI18NFileSystemCharset();
-    if (charset) {
-      bFoundCharset = CheckBodyInCharsetRange(charset);
+    const nsCString charset(nsMsgI18NFileSystemCharset());
+    if (!charset.IsEmpty()) {
+      bFoundCharset = CheckBodyInCharsetRange(charset.get());
       if (bFoundCharset)
-        m_mimeCharset.Assign(charset);
+        m_mimeCharset = charset;
     }
   }
   if (!bFoundCharset) // Everything else failed, let's use the lossless utf-8...
     m_mimeCharset.Assign("utf-8");
 
   MAPI_DUMP_STRING(m_body.get());
   MAPI_TRACE0("\r\n");
 
   return true;
 }
 
 void CMapiMessage::GetBody(nsCString& dest) const
 {
-  nsMsgI18NConvertFromUnicode(m_mimeCharset.get(), m_body, dest);
+  nsMsgI18NConvertFromUnicode(m_mimeCharset, m_body, dest);
 }
 
 void CMapiMessage::FetchFlags(void)
 {
   LPSPropValue pVal = CMapiApi::GetMapiProperty(m_lpMsg, PR_MESSAGE_FLAGS);
   if (pVal)
     m_msgFlags = CMapiApi::GetLongFromProp(pVal);
   pVal = CMapiApi::GetMapiProperty(m_lpMsg, PR_LAST_VERB_EXECUTED);
@@ -1279,17 +1279,19 @@ void CMapiMessageHeaders::CHeaderField::
     if ((*pos == nsCRT::CR) && (*(pos+1) == nsCRT::LF) && IsWSP(*(pos+2)))
       pos += 2; // Skip CRLF if it is followed by SPACE or TAB
     else
       unfolded.Append(*(pos++));
   }
   if (m_fbody_utf8)
     CopyUTF8toUTF16(unfolded, dest);
   else
-    nsMsgI18NConvertToUnicode(fallbackCharset, unfolded, dest);
+    nsMsgI18NConvertToUnicode(nsDependentCString(fallbackCharset),
+                                                 unfolded,
+                                                 dest);
 }
 
 ////////////////////////////////////////
 
 const char* CMapiMessageHeaders::Specials[hdrMax] = {
   "Date:",
   "From:",
   "Sender:",
--- a/mailnews/import/outlook/src/nsOutlookCompose.cpp
+++ b/mailnews/import/outlook/src/nsOutlookCompose.cpp
@@ -311,17 +311,17 @@ nsresult nsOutlookCompose::ComposeTheMes
           new nsImportEmbeddedImageData(uri, nsDependentCString(cid),
                                      nsDependentCString(name));
         embeddedObjects->AppendElement(imageData, false);
       }
     }
   }
 
   nsCString bodyA;
-  nsMsgI18NConvertFromUnicode(msg.GetBodyCharset(), bodyW, bodyA);
+  nsMsgI18NConvertFromUnicode(nsDependentCString(msg.GetBodyCharset()), bodyW, bodyA);
 
   nsCOMPtr<nsIImportService> impService(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = impService->CreateRFC822Message(
                         m_pIdentity,                  // dummy identity
                         m_pMsgFields,                 // message fields
                         msg.BodyIsHtml() ? "text/html" : "text/plain",
--- a/mailnews/import/text/src/nsTextAddress.cpp
+++ b/mailnews/import/text/src/nsTextAddress.cpp
@@ -47,17 +47,17 @@ nsTextAddress::~nsTextAddress()
 
 nsresult nsTextAddress::GetUnicharLineStreamForFile(nsIFile *aFile,
                                                     nsIInputStream *aInputStream,
                                                     nsIUnicharLineInputStream **aStream)
 {
   nsAutoCString charset;
   nsresult rv = MsgDetectCharsetFromFile(aFile, charset);
   if (NS_FAILED(rv)) {
-    charset.Assign(nsMsgI18NFileSystemCharset());
+    charset = nsMsgI18NFileSystemCharset();
   }
 
   nsCOMPtr<nsIConverterInputStream> converterStream =
     do_CreateInstance("@mozilla.org/intl/converter-input-stream;1", &rv);
   if (NS_SUCCEEDED(rv)) {
     rv = converterStream->Init(aInputStream,
                                charset.get(),
                                8192,
--- a/mailnews/mapi/mapihook/src/msgMapiHook.cpp
+++ b/mailnews/mapi/mapihook/src/msgMapiHook.cpp
@@ -494,17 +494,19 @@ nsresult nsMapiHook::HandleAttachments (
             // leafName already contains a unicode leafName from lpszPathName. If we were given
             // a value for lpszFileName, use it. Otherwise stick with leafName
             if (aFiles[i].lpszFileName)
             {
               nsAutoString wholeFileName;
                 if (aIsUnicode)
                     wholeFileName.Assign(aFiles[i].lpszFileName);
                 else
-                    ConvertToUnicode(nsMsgI18NFileSystemCharset(), (char *) aFiles[i].lpszFileName, wholeFileName);
+                    nsMsgI18NConvertToUnicode(nsMsgI18NFileSystemCharset(),
+                                              nsDependentCString((char *) aFiles[i].lpszFileName),
+                                              wholeFileName);
                 // need to find the last '\' and find the leafname from that.
                 int32_t lastSlash = wholeFileName.RFindChar(char16_t('\\'));
                 if (lastSlash != kNotFound)
                   leafName.Assign(Substring(wholeFileName, lastSlash + 1));
                 else
                   leafName.Assign(wholeFileName);
             }
             else
@@ -617,33 +619,37 @@ nsresult nsMapiHook::PopulateCompFieldsW
   MOZ_LOG(MAPI, mozilla::LogLevel::Debug, ("to: %s cc: %s bcc: %s \n", NS_ConvertUTF16toUTF8(To).get(), NS_ConvertUTF16toUTF8(Cc).get(), NS_ConvertUTF16toUTF8(Bcc).get()));
 
   nsAutoCString platformCharSet;
   // set subject
   if (aMessage->lpszSubject)
   {
     nsAutoString Subject ;
     if (platformCharSet.IsEmpty())
-      platformCharSet.Assign(nsMsgI18NFileSystemCharset());
-    rv = ConvertToUnicode(platformCharSet.get(), (char *) aMessage->lpszSubject, Subject);
+      platformCharSet = nsMsgI18NFileSystemCharset();
+    rv = nsMsgI18NConvertToUnicode(platformCharSet,
+                                   nsDependentCString((char *) aMessage->lpszSubject),
+                                   Subject);
     if (NS_FAILED(rv)) return rv;
     aCompFields->SetSubject(Subject);
   }
 
   // handle attachments as File URL
   rv = HandleAttachments (aCompFields, aMessage->nFileCount, aMessage->lpFiles, false) ;
   if (NS_FAILED(rv)) return rv ;
 
   // set body
   if (aMessage->lpszNoteText)
   {
     nsAutoString Body ;
     if (platformCharSet.IsEmpty())
-      platformCharSet.Assign(nsMsgI18NFileSystemCharset());
-    rv = ConvertToUnicode(platformCharSet.get(), (char *) aMessage->lpszNoteText, Body);
+      platformCharSet = nsMsgI18NFileSystemCharset();
+    rv = nsMsgI18NConvertToUnicode(platformCharSet,
+                                   nsDependentCString((char *) aMessage->lpszNoteText),
+                                   Body);
     if (NS_FAILED(rv)) return rv ;
     if (Body.IsEmpty() || Body.Last() != '\n')
       Body.AppendLiteral(CRLF);
 
     // This is needed when Simple MAPI is used without a compose window.
     // See bug 1366196.
     if (Body.Find("<html>") == kNotFound)
       aCompFields->SetForcePlainText(true);
--- a/mailnews/mime/src/mimedrft.cpp
+++ b/mailnews/mime/src/mimedrft.cpp
@@ -183,17 +183,19 @@ nsresult CreateComposeParams(nsCOMPtr<ns
     {
       rv = curAttachment->m_url->GetSpec(spec);
       if (NS_SUCCEEDED(rv))
       {
         nsCOMPtr<nsIMsgAttachment> attachment = do_CreateInstance(NS_MSGATTACHMENT_CONTRACTID, &rv);
         if (NS_SUCCEEDED(rv) && attachment)
         {
           nsAutoString nameStr;
-          rv = ConvertToUnicode("UTF-8", curAttachment->m_realName.get(), nameStr);
+          rv = nsMsgI18NConvertToUnicode(NS_LITERAL_CSTRING("UTF-8"),
+                                         curAttachment->m_realName,
+                                         nameStr);
           if (NS_FAILED(rv))
             CopyASCIItoUTF16(curAttachment->m_realName, nameStr);
           attachment->SetName(nameStr);
           attachment->SetUrl(spec);
           attachment->SetTemporary(true);
           attachment->SetContentType(curAttachment->m_realType.get());
           attachment->SetMacType(curAttachment->m_xMacType.get());
           attachment->SetMacCreator(curAttachment->m_xMacCreator.get());
@@ -342,42 +344,52 @@ CreateCompositionFields(const char      
 
   // Now set all of the passed in stuff...
   cFields->SetCharacterSet(!PL_strcasecmp("us-ascii", charset) ? "ISO-8859-1" : charset);
 
   nsAutoCString val;
   nsAutoString outString;
 
   if (from) {
-    ConvertRawBytesToUTF16(from, charset, outString);
+    nsMsgI18NConvertRawBytesToUTF16(nsDependentCString(from),
+                                    nsDependentCString(charset),
+                                    outString);
     cFields->SetFrom(outString);
   }
 
   if (subject) {
     MIME_DecodeMimeHeader(subject, charset, false, true, val);
     cFields->SetSubject(NS_ConvertUTF8toUTF16(!val.IsEmpty() ? val.get() : subject));
   }
 
   if (reply_to) {
-    ConvertRawBytesToUTF16(reply_to, charset, outString);
+    nsMsgI18NConvertRawBytesToUTF16(nsDependentCString(reply_to),
+                                    nsDependentCString(charset),
+                                    outString);
     cFields->SetReplyTo(outString);
   }
 
   if (to) {
-    ConvertRawBytesToUTF16(to, charset, outString);
+    nsMsgI18NConvertRawBytesToUTF16(nsDependentCString(to),
+                                    nsDependentCString(charset),
+                                    outString);
     cFields->SetTo(outString);
   }
 
   if (cc) {
-    ConvertRawBytesToUTF16(cc, charset, outString);
+    nsMsgI18NConvertRawBytesToUTF16(nsDependentCString(cc),
+                                    nsDependentCString(charset),
+                                    outString);
     cFields->SetCc(outString);
   }
 
   if (bcc) {
-    ConvertRawBytesToUTF16(bcc, charset, outString);
+    nsMsgI18NConvertRawBytesToUTF16(nsDependentCString(bcc),
+                                    nsDependentCString(charset),
+                                    outString);
     cFields->SetBcc(outString);
   }
 
   if (fcc) {
     MIME_DecodeMimeHeader(fcc, charset, false, true, val);
     cFields->SetFcc(NS_ConvertUTF8toUTF16(!val.IsEmpty() ? val.get() : fcc));
   }
 
@@ -1379,17 +1391,19 @@ mime_parse_stream_complete (nsMIMESessio
           // Get a charset from the header if no override is set.
           if (!charsetOverride)
             mimeCharset = MimeHeaders_get_parameter (mdd->messageBody->m_type.get(), "charset", nullptr, nullptr);
           // If no charset is specified in the header then use the default.
           char *bodyCharset = mimeCharset ? mimeCharset : mdd->mailcharset;
           if (bodyCharset)
           {
             nsAutoString tmpUnicodeBody;
-            rv = ConvertToUnicode(bodyCharset, body, tmpUnicodeBody);
+            rv = nsMsgI18NConvertToUnicode(nsDependentCString(bodyCharset),
+                                           nsDependentCString(body),
+                                           tmpUnicodeBody);
             if (NS_FAILED(rv)) // Tough luck, ASCII/ISO-8859-1 then...
               CopyASCIItoUTF16(nsDependentCString(body), tmpUnicodeBody);
 
             char *newBody = ToNewUTF8String(tmpUnicodeBody);
             if (newBody)
             {
               PR_Free(body);
               body = newBody;
--- a/mailnews/mime/src/mimehdrs.cpp
+++ b/mailnews/mime/src/mimehdrs.cpp
@@ -34,17 +34,19 @@ MimeHeaders_convert_header_value(MimeDis
                                  bool convert_charset_only)
 {
   if (value.IsEmpty())
     return;
 
   if (convert_charset_only)
   {
     nsAutoCString output;
-    ConvertRawBytesToUTF8(value, opt->default_charset, output);
+    nsMsgI18NConvertRawBytesToUTF8(value,
+                                   nsDependentCString(opt->default_charset),
+                                   output);
     value.Assign(output);
     return;
   }
 
   if (opt && opt->rfc1522_conversion_p)
   {
     nsAutoCString temporary;
     MIME_DecodeMimeHeader(value.get(), opt->default_charset,
@@ -600,17 +602,18 @@ MimeHeaders_write_all_headers (MimeHeade
           MsgLowerCaseEqualsLiteral(name, "to") || MsgLowerCaseEqualsLiteral(name, "from") ||
           MsgLowerCaseEqualsLiteral(name, "cc") || MsgLowerCaseEqualsLiteral(name, "bcc") ||
           MsgLowerCaseEqualsLiteral(name, "reply-to") || MsgLowerCaseEqualsLiteral(name, "sender");
     MimeHeaders_convert_header_value(opt, hdr_value, convert_charset_only);
     // if we're saving as html, we need to convert headers from utf8 to message charset, if any
     if (opt->format_out == nsMimeOutput::nsMimeMessageSaveAs && charset)
     {
       nsAutoCString convertedStr;
-      if (NS_SUCCEEDED(ConvertFromUnicode(charset, NS_ConvertUTF8toUTF16(hdr_value),
+      if (NS_SUCCEEDED(nsMsgI18NConvertFromUnicode(nsDependentCString(charset),
+                       NS_ConvertUTF8toUTF16(hdr_value),
                        convertedStr)))
       {
         hdr_value = convertedStr;
       }
     }
 
     if (attachment) {
       if (NS_FAILED(mimeEmitterAddAttachmentField(opt, name.get(), hdr_value.get())))
--- a/mailnews/mime/src/mimemsg.cpp
+++ b/mailnews/mime/src/mimemsg.cpp
@@ -280,17 +280,17 @@ MimeMessage_close_headers (MimeObject *o
     nsCString contentType;
     contentType.Adopt(MimeHeaders_get(msg->hdrs, HEADER_CONTENT_TYPE, false, false));
     if (!contentType.IsEmpty())
       charset.Adopt(MimeHeaders_get_parameter(contentType.get(), "charset", nullptr, nullptr));
 
     // If we've got a charset, use nsMsgI18NConvertToUnicode to magically decode
     // the munged subject.
     if (!charset.IsEmpty()) {
-      nsresult rv = nsMsgI18NConvertToUnicode(charset.get(), orig, dest);
+      nsresult rv = nsMsgI18NConvertToUnicode(charset, orig, dest);
       // If we managed to convert the string, replace munged_subject with the
       // UTF8 version of it, otherwise, just forget about it (maybe there was an
       // improperly encoded string in there).
       PR_Free(obj->headers->munged_subject);
       if (NS_SUCCEEDED(rv))
         obj->headers->munged_subject = ToNewUTF8String(dest);
       else
         obj->headers->munged_subject = nullptr;
--- a/mailnews/mime/src/mimetpfl.cpp
+++ b/mailnews/mime/src/mimetpfl.cpp
@@ -367,17 +367,19 @@ MimeInlineTextPlainFlowed_parse_line (co
       if (obj->options->format_out == nsMimeOutput::nsMimeMessageSaveAs)
       {
         // Get the mail charset of this message.
         MimeInlineText  *inlinetext = (MimeInlineText *) obj;
         if (!inlinetext->initializeCharset)
           ((MimeInlineTextClass*)&mimeInlineTextClass)->initialize_charset(obj);
         mailCharset = inlinetext->charset;
         if (mailCharset && *mailCharset) {
-          rv = nsMsgI18NConvertToUnicode(mailCharset, PromiseFlatCString(inputStr), lineSource);
+          rv = nsMsgI18NConvertToUnicode(nsDependentCString(mailCharset),
+                                         PromiseFlatCString(inputStr),
+                                         lineSource);
           NS_ENSURE_SUCCESS(rv, -1);
         }
         else // this probably never happens...
           CopyUTF8toUTF16(inputStr, lineSource);
       }
       else   // line is in UTF-8
         CopyUTF8toUTF16(inputStr, lineSource);
 
@@ -466,17 +468,19 @@ MimeInlineTextPlainFlowed_parse_line (co
     status = MimeObject_write(obj, preface.get(), preface.Length(), true);
     if (status < 0) return status;
     nsAutoCString outString;
     if (obj->options->format_out != nsMimeOutput::nsMimeMessageSaveAs ||
         !mailCharset || !*mailCharset)
       CopyUTF16toUTF8(lineResult2, outString);
     else
     { // convert back to mailCharset before writing.
-      rv = nsMsgI18NConvertFromUnicode(mailCharset, lineResult2, outString);
+      rv = nsMsgI18NConvertFromUnicode(nsDependentCString(mailCharset),
+                                       lineResult2,
+                                       outString);
       NS_ENSURE_SUCCESS(rv, -1);
     }
     status = MimeObject_write(obj, outString.get(), outString.Length(), true);
     return status;
   }
   return 0;
 }
 
--- a/mailnews/mime/src/mimetpla.cpp
+++ b/mailnews/mime/src/mimetpla.cpp
@@ -313,17 +313,19 @@ MimeInlineTextPlain_parse_line (const ch
     // convert |line| to UTF-16 before 'html'izing (calling ScanTXT())
     if (obj->options->format_out == nsMimeOutput::nsMimeMessageSaveAs)
     { // Get the mail charset of this message.
       MimeInlineText  *inlinetext = (MimeInlineText *) obj;
       if (!inlinetext->initializeCharset)
          ((MimeInlineTextClass*)&mimeInlineTextClass)->initialize_charset(obj);
       mailCharset = inlinetext->charset;
       if (mailCharset && *mailCharset) {
-        rv = nsMsgI18NConvertToUnicode(mailCharset, inputStr, lineSourceStr);
+        rv = nsMsgI18NConvertToUnicode(nsDependentCString(mailCharset),
+                                       inputStr,
+                                       lineSourceStr);
         NS_ENSURE_SUCCESS(rv, -1);
       }
       else // this probably never happens ...
         CopyUTF8toUTF16(inputStr, lineSourceStr);
     }
     else  // line is in UTF-8
       CopyUTF8toUTF16(inputStr, lineSourceStr);
 
@@ -424,18 +426,19 @@ MimeInlineTextPlain_parse_line (const ch
       status = MimeObject_write(obj, prefaceResultStr.get(), prefaceResultStr.Length(), true);
       if (status < 0) return status;
       nsAutoCString outString;
       if (obj->options->format_out != nsMimeOutput::nsMimeMessageSaveAs ||
           !mailCharset || !*mailCharset)
         CopyUTF16toUTF8(lineResultUnichar, outString);
       else
       { // convert back to mailCharset before writing.
-        rv = nsMsgI18NConvertFromUnicode(mailCharset,
-                                         lineResultUnichar, outString);
+        rv = nsMsgI18NConvertFromUnicode(nsDependentCString(mailCharset),
+                                         lineResultUnichar,
+                                         outString);
         NS_ENSURE_SUCCESS(rv, -1);
       }
 
       status = MimeObject_write(obj, outString.get(), outString.Length(), true);
     }
     else
     {
       status = 0;
--- a/mailnews/news/src/nsNNTPProtocol.cpp
+++ b/mailnews/news/src/nsNNTPProtocol.cpp
@@ -1503,17 +1503,17 @@ nsresult nsNNTPProtocol::SendListSearche
   if (!line)
     return rv;  /* no line yet */
 
   if ('.' != line[0])
   {
         nsAutoCString charset;
         nsAutoString lineUtf16;
         if (NS_FAILED(m_nntpServer->GetCharset(charset)) ||
-            NS_FAILED(nsMsgI18NConvertToUnicode(charset.get(),
+            NS_FAILED(nsMsgI18NConvertToUnicode(charset,
                                                 nsDependentCString(line),
                                                 lineUtf16, true)))
             CopyUTF8toUTF16(nsDependentCString(line), lineUtf16);
 
     m_nntpServer->AddSearchableGroup(lineUtf16);
   }
   else
   {
@@ -2623,17 +2623,17 @@ nsresult nsNNTPProtocol::ProcessNewsgrou
 
   bool xactive=false;
   rv = m_nntpServer->QueryExtension("XACTIVE",&xactive);
   if (NS_SUCCEEDED(rv) && xactive)
   {
     nsAutoCString charset;
     nsAutoString lineUtf16;
     if (NS_SUCCEEDED(m_nntpServer->GetCharset(charset)) &&
-        NS_SUCCEEDED(nsMsgI18NConvertToUnicode(charset.get(),
+        NS_SUCCEEDED(nsMsgI18NConvertToUnicode(charset,
                                                nsDependentCString(line),
                                                lineUtf16, true)))
       m_nntpServer->SetGroupNeedsExtraInfo(NS_ConvertUTF16toUTF8(lineUtf16),
                                            true);
     else
       m_nntpServer->SetGroupNeedsExtraInfo(nsDependentCString(line), true);
   }
 
--- a/mailnews/news/src/nsNewsFolder.cpp
+++ b/mailnews/news/src/nsNewsFolder.cpp
@@ -1491,17 +1491,17 @@ nsMsgNewsFolder::GetRawName(nsACString &
     // convert to the server-side encoding
     nsCOMPtr <nsINntpIncomingServer> nntpServer;
     rv = GetNntpServer(getter_AddRefs(nntpServer));
     NS_ENSURE_SUCCESS(rv,rv);
 
     nsAutoCString dataCharset;
     rv = nntpServer->GetCharset(dataCharset);
     NS_ENSURE_SUCCESS(rv,rv);
-    rv = nsMsgI18NConvertFromUnicode(dataCharset.get(), name, mRawName);
+    rv = nsMsgI18NConvertFromUnicode(dataCharset, name, mRawName);
 
     if (NS_FAILED(rv))
       LossyCopyUTF16toASCII(name, mRawName);
   }
   aRawName = mRawName;
   return NS_OK;
 }
 
--- a/mailnews/news/src/nsNntpIncomingServer.cpp
+++ b/mailnews/news/src/nsNntpIncomingServer.cpp
@@ -987,17 +987,17 @@ nsNntpIncomingServer::AddNewsgroupToList
 {
     nsresult rv;
 
     nsAutoString newsgroupName;
     nsAutoCString dataCharset;
     rv = GetCharset(dataCharset);
     NS_ENSURE_SUCCESS(rv,rv);
 
-    rv = nsMsgI18NConvertToUnicode(dataCharset.get(),
+    rv = nsMsgI18NConvertToUnicode(dataCharset,
                                    nsDependentCString(aName),
                                    newsgroupName);
 #ifdef DEBUG_jungshik
     NS_ASSERTION(NS_SUCCEEDED(rv), "newsgroup name conversion failed");
 #endif
     if (NS_FAILED(rv)) {
         CopyASCIItoUTF16(nsDependentCString(aName), newsgroupName);
     }