nsISaveAsCharset::attr_FallbackQuestionMark + nsISaveAsCharset::attr_EntityNone,
nsISaveAsCharset::attr_FallbackQuestionMark + nsISaveAsCharset::attr_EntityAfterCharsetConv,
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 || !inString || !outString)    return NS_ERROR_NULL_POINTER;  if (0 == *inString) {    *outString = nsCRT::strdup("");    return (NULL != *outString) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;  }  *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  }  nsCOMPtr <nsICharsetConverterManager2> ccm2 = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);  NS_ENSURE_SUCCESS(res, res);  nsCOMPtr <nsIAtom> charsetAtom;  res = ccm2->GetCharsetAtom(NS_ConvertASCIItoUCS2(charset).get(), getter_AddRefs(charsetAtom));  NS_ENSURE_SUCCESS(res, res);  const PRUnichar *charsetName;  res = charsetAtom->GetUnicode(&charsetName);  NS_ENSURE_SUCCESS(res, res);  // charset converter plus entity, NCR generation  nsCOMPtr <nsISaveAsCharset> conv = do_CreateInstance(NS_SAVEASCHARSET_CONTRACTID, &res);  NS_ENSURE_SUCCESS(res, res);  // attribute:   // html text - charset conv then fallback to entity or NCR  // plain text - charset conv then fallback to '?'  if (bTEXT_HTML)    // For ISO-8859-1 only, convert to entity first (always generate entites like &nbsp;).    res = conv->Init(NS_ConvertUCS2toUTF8(charsetName).get(),                      !nsCRT::strcmp(charsetName, NS_LITERAL_STRING("ISO-8859-1").get()) ?                     nsISaveAsCharset::attr_htmlTextDefault :                     nsISaveAsCharset::attr_EntityAfterCharsetConv + nsISaveAsCharset::attr_FallbackDecimalNCR,                      nsIEntityConverter::html32);  else    // fallback for text/plain: first try transliterate then '?'    res = conv->Init(NS_ConvertUCS2toUTF8(charsetName).get(),                      nsISaveAsCharset::attr_FallbackQuestionMark + nsISaveAsCharset::attr_EntityNone,                      nsIEntityConverter::transliterate);  NS_ENSURE_SUCCESS(res, res);  // Mapping characters in a certain range (required for Japanese only)  if (!nsCRT::strcmp(charsetName, NS_LITERAL_STRING("ISO-2022-JP").get())) {    static PRInt32 sSendHankakuKana = -1;    if (sSendHankakuKana < 0) {      nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &res));      NS_ENSURE_SUCCESS(res, res);      PRBool sendHankaku;      // Get a hidden 4.x pref with no UI, get it only once.      if (NS_FAILED(prefs->GetBoolPref("mailnews.send_hankaku_kana", &sendHankaku)))        sSendHankakuKana = 0;  // no pref means need the mapping      else        sSendHankakuKana = sendHankaku ? 1 : 0;    }    if (!sSendHankakuKana) {      nsCOMPtr <nsITextTransform> textTransform = do_CreateInstance(NS_HANKAKUTOZENKAKU_CONTRACTID, &res);      if (NS_SUCCEEDED(res)) {        nsAutoString mapped;        res = textTransform->Change(inString, nsCRT::strlen(inString), mapped);        if (NS_SUCCEEDED(res)) {          return conv->Convert(mapped.get(), outString);        }      }    }  }  // Convert to charset  return conv->Convert(inString, outString);}