if (!nsCRT::strcasecmp("ISO-2022-JP", charset)) { NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &res); if (nsnull != prefs && NS_SUCCEEDED(res)) { PRBool return_val;  if (NS_FAILED(prefs->GetBoolPref("mailnews.send_hankaku_kana", &return_val))) return_val = PR_FALSE;  if (!return_val) { nsCOMPtr <nsITextTransform> textTransform; res = nsComponentManager::CreateInstance(NS_HANKAKUTOZENKAKU_PROGID, nsnull, NS_GET_IID(nsITextTransform), getter_AddRefs(textTransform)); if (NS_SUCCEEDED(res)) { nsAutoString aText(inString); nsAutoString aResult; res = textTransform->Change(aText, aResult); if (NS_SUCCEEDED(res)) { return aConv->Convert(aResult.GetUnicode(), outString); } } } } }
nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char *charset, const PRUnichar* inString, char** outString){  NS_ASSERTION(contentType, "null ptr- contentType");  NS_ASSERTION(charset, "null ptr- charset");  NS_ASSERTION(outString, "null ptr- outString");  if(!contentType || !charset || !outString)    return NS_ERROR_NULL_POINTER;  *outString = NULL;  PRBool bTEXT_HTML = PR_FALSE;  nsresult res;  if (!nsCRT::strcasecmp(contentType, TEXT_HTML)) {    bTEXT_HTML = PR_TRUE;  }  else if (nsCRT::strcasecmp(contentType, TEXT_PLAIN)) {    return NS_ERROR_ILLEGAL_VALUE;  // not supported type  }  // Resolve charset alias  nsAutoString aCharset(charset);  NS_WITH_SERVICE(nsICharsetAlias, calias, kCharsetAliasCID, &res);   if (NS_SUCCEEDED(res)) {    nsAutoString aAlias(aCharset);    if (aAlias.Length()) {      res = calias->GetPreferred(aAlias, aCharset);    }  }  if (NS_FAILED(res)) {    return res;  }  nsCOMPtr <nsISaveAsCharset> aConv;  // charset converter plus entity, NCR generation  res = nsComponentManager::CreateInstance(kSaveAsCharsetCID, NULL,                                            nsISaveAsCharset::GetIID(), getter_AddRefs(aConv));  if(NS_SUCCEEDED(res)) {    // attribute:     // html text - charset conv then fallback to entity or NCR    // plain text - charset conv then fallback to '?'    char charset_buf[kMAX_CSNAME+1];    if (bTEXT_HTML) {      res = aConv->Init(aCharset.ToCString(charset_buf, kMAX_CSNAME+1),                         nsISaveAsCharset::attr_htmlTextDefault,                         nsIEntityConverter::html40);    }    else {      // fallback for text/plain: first try transliterate then '?'      res = aConv->Init(aCharset.ToCString(charset_buf, kMAX_CSNAME+1),                         nsISaveAsCharset::attr_FallbackQuestionMark + nsISaveAsCharset::attr_EntityAfterCharsetConv,                         nsIEntityConverter::transliterate);    }    if (NS_SUCCEEDED(res)) {      res = aConv->Convert(inString, outString);    }  }   return res;}