if (text->needUpdateMsgWinCharset && *text->charset) { if (!nsCRT::strcasecmp(text->charset, "us-ascii")) SetMailCharacterSetToMsgWindow(obj, NS_LITERAL_STRING("ISO-8859-1").get()); else SetMailCharacterSetToMsgWindow(obj, NS_ConvertASCIItoUCS2(text->charset).get()); }
static int MimeInlineText_initializeCharset(MimeObject *obj){  MimeInlineText  *text = (MimeInlineText *) obj;  text->inputAutodetect = PR_FALSE;  text->charsetOverridable = PR_FALSE;    /* Figure out an appropriate charset for this object.  */  if (!text->charset && obj->headers)  {    if (obj->options && obj->options->override_charset)    {      text->charset = nsCRT::strdup(obj->options->default_charset);    }    else    {      char *ct = MimeHeaders_get (obj->headers, HEADER_CONTENT_TYPE,                                  PR_FALSE, PR_FALSE);      if (ct)      {        text->charset = MimeHeaders_get_parameter (ct, "charset", NULL, NULL);        PR_Free(ct);      }          if (!text->charset)      {        /* If we didn't find "Content-Type: ...; charset=XX" then look           for "X-Sun-Charset: XX" instead.  (Maybe this should be done           in MimeSunAttachmentClass, but it's harder there than here.)         */        text->charset = MimeHeaders_get (obj->headers,                                          HEADER_X_SUN_CHARSET,                                          PR_FALSE, PR_FALSE);      }      if (!text->charset)      {        nsresult res;        nsXPIDLString detector_name;                text->charsetOverridable = PR_TRUE;        nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &res));         if (NS_SUCCEEDED(res)) {          if (NS_SUCCEEDED(prefs->GetLocalizedUnicharPref("intl.charset.detector", getter_Copies(detector_name)))) {            //only if we can get autodetector name correctly, do we set this to true            text->inputAutodetect = PR_TRUE;          }        }                if (obj->options && obj->options->default_charset)          text->charset = nsCRT::strdup(obj->options->default_charset);        else        {          // New change for falling back to a default view charset          nsresult        rv;          nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID, &rv));          if ( NS_SUCCEEDED(rv) && prefs)          {            nsXPIDLString value;            rv = prefs->GetLocalizedUnicharPref("mailnews.view_default_charset", getter_Copies(value));            if(NS_SUCCEEDED(rv)) {              text->charset = ToNewUTF8String(value);            }          }          if (!text->charset)            text->charset = nsCRT::strdup("");        }      }     }  }    if (text->inputAutodetect)  {    //we need to prepare lineDam for charset detection    text->lineDamBuffer = (char*)PR_Malloc(DAM_MAX_BUFFER_SIZE);    text->lineDamPtrs = (char**)PR_Malloc(DAM_MAX_LINES*sizeof(char*));    text->curDamOffset = 0;    text->lastLineInDam = 0;    if (!text->lineDamBuffer || !text->lineDamPtrs)    {      text->inputAutodetect = PR_FALSE;      PR_FREEIF(text->lineDamBuffer);      PR_FREEIF(text->lineDamPtrs);    }  }  //update MsgWindow charset if we are instructed to do so  if (text->needUpdateMsgWinCharset && *text->charset) {    if (!nsCRT::strcasecmp(text->charset, "us-ascii"))      SetMailCharacterSetToMsgWindow(obj, NS_LITERAL_STRING("ISO-8859-1").get());    else      SetMailCharacterSetToMsgWindow(obj, NS_ConvertASCIItoUCS2(text->charset).get());  }  text->initializeCharset = PR_TRUE;  return 0;}