nsAutoString aAlias; aAlias.AssignWithConversion(aCharset);
nsAutoString aAlias; aAlias.AssignWithConversion(aCharset.get());
nsresult nsMsgI18NConvertFromUnicode(const nsCString& aCharset,                                      const nsString& inString,                                     nsCString& outString){  if (inString.IsEmpty()) {    outString.Truncate(0);    return NS_OK;  }  // Note: this will hide a possible error when the unicode text may contain more than one charset.  // (e.g. Latin1 + Japanese). Use nsMsgI18NSaveAsCharset instead to avoid that problem.  else if (aCharset.IsEmpty() ||      aCharset.EqualsIgnoreCase("us-ascii") ||      aCharset.EqualsIgnoreCase("ISO-8859-1")) {    outString.AssignWithConversion(inString);    return NS_OK;  }  else if (aCharset.EqualsIgnoreCase("UTF-8")) {    char *s = ToNewUTF8String(inString);    if (NULL == s)      return NS_ERROR_OUT_OF_MEMORY;    outString.Assign(s);    Recycle(s);    return NS_OK;  }  nsAutoString convCharset; convCharset.AssignWithConversion("ISO-8859-1");  nsresult res;  // Resolve charset alias  nsCOMPtr <nsICharsetAlias> calias = do_GetService(NS_CHARSETALIAS_CONTRACTID, &res);  if (NS_SUCCEEDED(res)) {    nsAutoString aAlias; aAlias.AssignWithConversion(aCharset);    if (aAlias.Length()) {      res = calias->GetPreferred(aAlias, convCharset);    }  }  nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);  if(NS_SUCCEEDED(res)) {    nsCOMPtr <nsIUnicodeEncoder> encoder;    // get an unicode converter    res = ccm->GetUnicodeEncoder(&convCharset, getter_AddRefs(encoder));    if(NS_SUCCEEDED(res)) {      res = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?');      if (NS_SUCCEEDED(res)) {        const PRUnichar *originalSrcPtr = inString.get();        PRUnichar *currentSrcPtr = NS_CONST_CAST(PRUnichar *, originalSrcPtr);        PRInt32 originalUnicharLength = inString.Length();        PRInt32 srcLength;        PRInt32 dstLength;        char localbuf[512];        PRInt32 consumedLen = 0;        outString.Assign("");        // convert        while (consumedLen < originalUnicharLength) {          srcLength = originalUnicharLength - consumedLen;            dstLength = 512;          res = encoder->Convert(currentSrcPtr, &srcLength, localbuf, &dstLength);          if (NS_FAILED(res) || dstLength == 0)            break;          outString.Append(localbuf, dstLength);          currentSrcPtr += srcLength;          consumedLen = currentSrcPtr - originalSrcPtr; // src length used so far        }        res = encoder->Finish(localbuf, &dstLength);        if (NS_SUCCEEDED(res))          outString.Append(localbuf, dstLength);      }    }      }  return res;}