*outCString = inString.ToNewUTF8String();
*outCString = ToNewUTF8String(inString);
nsresult ConvertFromUnicode(const nsString& aCharset,                             const nsString& inString,                            char** outCString){#if 0   nsCAutoString s;  nsresult rv;  rv = nsMsgI18NConvertFromUnicode(aCharset, inString, s);  *outCString = PL_strdup(s);  return rv;#endif  *outCString = NULL;  if (inString.IsEmpty()) {    *outCString = nsCRT::strdup("");    return (NULL == *outCString) ? NS_ERROR_OUT_OF_MEMORY : 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")) {    *outCString = inString.ToNewCString();    return (NULL == *outCString) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;  }  else if (aCharset.EqualsIgnoreCase("UTF-8")) {    *outCString = inString.ToNewUTF8String();    return (NULL == *outCString) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;  }  nsAutoString convCharset; convCharset.AssignWithConversion("ISO-8859-1");  nsresult res;  // Resolve charset alias  nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID, &res));   if (NS_SUCCEEDED(res)) {    nsAutoString aAlias(aCharset);    if (aAlias.Length()) {      res = calias->GetPreferred(aAlias, convCharset);    }  }  nsCOMPtr<nsICharsetConverterManager> ccm =            do_GetService(kCharsetConverterManagerCID, &res);   if(NS_SUCCEEDED(res)) {    nsIUnicodeEncoder* encoder = nsnull;    // get an unicode converter    res = ccm->GetUnicodeEncoder(&convCharset, &encoder);    if(NS_SUCCEEDED(res) && (nsnull != encoder)) {      PRUnichar *unichars = (PRUnichar *) inString.get();      PRInt32 unicharLength = inString.Length();      PRInt32 dstLength;      res = encoder->GetMaxLength(unichars, unicharLength, &dstLength);      if (NS_SUCCEEDED(res)) {        res = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?');        if (NS_SUCCEEDED(res)) {          // allocale an output buffer          *outCString = (char *) PR_Malloc(dstLength + 1);          if (nsnull != *outCString) {            PRInt32 buffLength = dstLength;            **outCString = '\0';            res = encoder->Convert(unichars, &unicharLength, *outCString, &dstLength);            if (NS_SUCCEEDED(res)) {              PRInt32 finLen = buffLength - dstLength;              res = encoder->Finish((char *)(*outCString+dstLength), &finLen);              if (NS_SUCCEEDED(res)) {                dstLength += finLen;              }              (*outCString)[dstLength] = '\0';            }          }          else {            res = NS_ERROR_OUT_OF_MEMORY;          }        }      }      NS_IF_RELEASE(encoder);    }      }  return res;}