Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsMsgI18N.h File Reference
#include "nscore.h"
#include "msgCore.h"

Go to the source code of this file.

Defines

#define kMAX_CSNAME   64

Functions

NS_MSG_BASE char * nsMsgI18NEncodeMimePartIIStr (const char *header, PRBool structured, const char *charset, PRInt32 fieldnamelen, PRBool usemime)
 Encode an input string into RFC 2047 form.
NS_MSG_BASE PRBool nsMsgI18Nstateful_charset (const char *charset)
 Check if given charset is stateful (e.g.
NS_MSG_BASE PRBool nsMsgI18Nmultibyte_charset (const char *charset)
 Check if given charset is multibye (e.g.
NS_MSG_BASE PRBool nsMsgI18Ncheck_data_in_charset_range (const char *charset, const PRUnichar *inString, char **fallbackCharset=nsnull)
 Check the input (unicode) string is in a range of the given charset after the conversion.
NS_MSG_BASE const char * nsMsgI18NGetAcceptLanguage (void)
 Return accept language.
NS_MSG_BASE const char * nsMsgI18NFileSystemCharset (void)
 Return charset name of file system (OS dependent).
NS_MSG_BASE void nsMsgI18NTextFileCharset (nsACString &aCharset)
 Return charset name of text file (OS dependent).
NS_MSG_BASE nsresult nsMsgI18NConvertFromUnicode (const char *aCharset, const nsAFlatString &inString, nsACString &outString, PRBool aIsCharsetCanonical=PR_FALSE)
 Convert from unicode to target charset.
NS_MSG_BASE nsresult nsMsgI18NConvertToUnicode (const char *aCharset, const nsAFlatCString &inString, nsAString &outString, PRBool aIsCharsetCanonical=PR_FALSE)
 Convert from charset to unicode.
NS_MSG_BASE const char * nsMsgI18NParseMetaCharset (nsFileSpec *fileSpec)
 Parse for META charset.
NS_MSG_BASE nsresult nsMsgI18NConvertToEntity (const nsString &inString, nsString *outString)
 Convert input to HTML entities (e.g.
NS_MSG_BASE nsresult nsMsgI18NSaveAsCharset (const char *contentType, const char *charset, const PRUnichar *inString, char **outString, char **fallbackCharset=nsnull, PRBool *isAsciiOnly=nsnull)
 Convert from charset to unicode.
NS_MSG_BASE nsresult nsMsgI18NFormatNNTPXPATInNonRFC1522Format (const nsCString &aCharset, const nsString &inString, nsCString &outString)
 Convert from unicode to charset, generates NNTP XPAT search string.
nsresult CopyUTF16toMUTF7 (const nsAFlatString &aSrc, nsACString &aDest)
nsresult CopyMUTF7toUTF16 (const nsAFlatCString &aSrc, nsAString &aDest)
nsresult ConvertToUnicode (const char *charset, const nsAFlatCString &aSrc, nsAString &aDest)
nsresult ConvertToUnicode (const char *charset, const char *aSrc, nsAString &aDest)
nsresult ConvertFromUnicode (const char *charset, const nsAFlatString &aSrc, nsACString &aDest)

Define Documentation

#define kMAX_CSNAME   64

Definition at line 46 of file nsMsgI18N.h.


Function Documentation

nsresult ConvertFromUnicode ( const char *  charset,
const nsAFlatString aSrc,
nsACString &  aDest 
) [inline]

Definition at line 216 of file nsMsgI18N.h.

{
    return nsMsgI18NConvertFromUnicode(charset, aSrc, aDest);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult ConvertToUnicode ( const char *  charset,
const nsAFlatCString aSrc,
nsAString &  aDest 
) [inline]

Definition at line 204 of file nsMsgI18N.h.

{
    return nsMsgI18NConvertToUnicode(charset, aSrc, aDest);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult ConvertToUnicode ( const char *  charset,
const char *  aSrc,
nsAString &  aDest 
) [inline]

Definition at line 210 of file nsMsgI18N.h.

{
    return nsMsgI18NConvertToUnicode(charset, nsDependentCString(aSrc), aDest);
}

Here is the call graph for this function:

nsresult CopyMUTF7toUTF16 ( const nsAFlatCString aSrc,
nsAString &  aDest 
) [inline]

Definition at line 198 of file nsMsgI18N.h.

{
    return nsMsgI18NConvertToUnicode("x-imap4-modified-utf7", aSrc,
                                     aDest, PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult CopyUTF16toMUTF7 ( const nsAFlatString aSrc,
nsACString &  aDest 
) [inline]

Definition at line 192 of file nsMsgI18N.h.

{
    return nsMsgI18NConvertFromUnicode("x-imap4-modified-utf7", aSrc,
                                       aDest, PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_MSG_BASE PRBool nsMsgI18Ncheck_data_in_charset_range ( const char *  charset,
const PRUnichar inString,
char **  fallbackCharset = nsnull 
)

Check the input (unicode) string is in a range of the given charset after the conversion.

Note, do not use this for large string (e.g. message body) since this actually applies the conversion to the buffer.

Parameters:
charset[IN] Charset to be converted.
inString[IN] Input unicode string to be examined.
fallbackCharset[OUT] null if fallback charset is not needed. Otherwise, a fallback charset name may be set if that was used for the conversion. Caller is responsible for freeing the memory (or use nsXPIDLCString).
Returns:
True if the string can be converted within the charset range. False if one or more characters cannot be converted to the target charset.

Definition at line 286 of file nsMsgI18N.cpp.

{
  if (!charset || !*charset || !inString || !*inString)
    return PR_TRUE;

  nsresult res;
  PRBool result = PR_TRUE;
  
  nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(kCharsetConverterManagerCID, &res);

  if (NS_SUCCEEDED(res)) {
    nsCOMPtr <nsIUnicodeEncoder> encoder;

    // get an unicode converter
    res = ccm->GetUnicodeEncoderRaw(charset, getter_AddRefs(encoder));
    if(NS_SUCCEEDED(res)) {
      const PRUnichar *originalPtr = inString;
      PRInt32 originalLen = nsCRT::strlen(inString);
      const PRUnichar *currentSrcPtr = originalPtr;
      char localBuff[512];
      PRInt32 consumedLen = 0;
      PRInt32 srcLen;
      PRInt32 dstLength;

      // convert from unicode
      while (consumedLen < originalLen) {
        srcLen = originalLen - consumedLen;
        dstLength = 512;
        res = encoder->Convert(currentSrcPtr, &srcLen, localBuff, &dstLength);
        if (NS_ERROR_UENC_NOMAPPING == res) {
          result = PR_FALSE;
          break;
        }
        else if (NS_FAILED(res) || (0 == dstLength))
          break;

        currentSrcPtr += srcLen;
        consumedLen = currentSrcPtr - originalPtr; // src length used so far
      }
    }    
  }

  // if the conversion was not successful then try fallback to other charsets
  if (!result && fallbackCharset) {
    nsXPIDLCString convertedString;
    res = nsMsgI18NSaveAsCharset("text/plain", charset, inString, 
                                 getter_Copies(convertedString), fallbackCharset);
    result = (NS_SUCCEEDED(res) && NS_ERROR_UENC_NOMAPPING != res);
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_MSG_BASE nsresult nsMsgI18NConvertFromUnicode ( const char *  aCharset,
const nsAFlatString inString,
nsACString &  outString,
PRBool  aIsCharsetCanonical = PR_FALSE 
)

Convert from unicode to target charset.

Parameters:
charset[IN] Charset name.
inString[IN] Unicode string to convert.
outString[OUT] Converted output string.
Returns:
nsresult.

Definition at line 74 of file nsMsgI18N.cpp.

{
  if (inString.IsEmpty()) {
    outString.Truncate();
    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 || !PL_strcasecmp(aCharset, "us-ascii") ||
           !PL_strcasecmp(aCharset, "ISO-8859-1")) {
    LossyCopyUTF16toASCII(inString, outString);
    return NS_OK;
  }
  else if (!PL_strcasecmp(aCharset, "UTF-8")) {
    CopyUTF16toUTF8(inString, outString);
    return NS_OK;
  }

  nsresult rv;
  nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr <nsIUnicodeEncoder> encoder;

  // get an unicode converter
  if (aIsCharsetCanonical)  // optimize for modified UTF-7 used by IMAP
    rv = ccm->GetUnicodeEncoderRaw(aCharset, getter_AddRefs(encoder));
  else
    rv = ccm->GetUnicodeEncoder(aCharset, getter_AddRefs(encoder));
  NS_ENSURE_SUCCESS(rv, rv);
  rv = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?');
  NS_ENSURE_SUCCESS(rv, rv);

  const PRUnichar *originalSrcPtr = inString.get();
  const PRUnichar *currentSrcPtr = originalSrcPtr;
  PRInt32 originalUnicharLength = inString.Length();
  PRInt32 srcLength;
  PRInt32 dstLength;
  char localbuf[512];
  PRInt32 consumedLen = 0;

  outString.Truncate();
  // convert
  while (consumedLen < originalUnicharLength) {
    srcLength = originalUnicharLength - consumedLen;  
    dstLength = 512;
    rv = encoder->Convert(currentSrcPtr, &srcLength, localbuf, &dstLength);
    if (NS_FAILED(rv) || dstLength == 0)
      break;
    outString.Append(localbuf, dstLength);

    currentSrcPtr += srcLength;
    consumedLen = currentSrcPtr - originalSrcPtr; // src length used so far
  }
  rv = encoder->Finish(localbuf, &dstLength);
  if (NS_SUCCEEDED(rv))
    outString.Append(localbuf, dstLength);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Convert input to HTML entities (e.g.

 , á).

Parameters:
inString[IN] Input string to convert.
outString[OUT] Converted output string.
Returns:
nsresult.

Definition at line 398 of file nsMsgI18N.cpp.

{
  nsresult res;

  outString->Truncate();
  nsCOMPtr <nsIEntityConverter> entityConv = do_CreateInstance(kEntityConverterCID, &res);
  if(NS_SUCCEEDED(res)) {
    PRUnichar *entities = NULL;
    res = entityConv->ConvertToEntities(inString.get(), nsIEntityConverter::html40Latin1, &entities);
    if (NS_SUCCEEDED(res) && (NULL != entities))
      outString->Adopt(entities);
  }
 
  return res;
}

Here is the call graph for this function:

NS_MSG_BASE nsresult nsMsgI18NConvertToUnicode ( const char *  aCharset,
const nsAFlatCString inString,
nsAString &  outString,
PRBool  aIsCharsetCanonical = PR_FALSE 
)

Convert from charset to unicode.

Parameters:
charset[IN] Charset name.
inString[IN] Input string to convert.
outString[OUT] Output unicode string.
Returns:
nsresult.

Definition at line 136 of file nsMsgI18N.cpp.

{
  if (inString.IsEmpty()) {
    outString.Truncate();
    return NS_OK;
  }
  else if (!*aCharset || !PL_strcasecmp(aCharset, "us-ascii") ||
           !PL_strcasecmp(aCharset, "ISO-8859-1")) {
    // Despite its name, it also works for Latin-1.
    CopyASCIItoUTF16(inString, outString);
    return NS_OK;
  }
  else if (!PL_strcasecmp(aCharset, "UTF-8")) {
    if (IsUTF8(inString)) {
      nsAutoString tmp;
      CopyUTF8toUTF16(inString, tmp);
      if (!tmp.IsEmpty() && tmp.get()[0] == PRUnichar(0xFEFF))
        tmp.Cut(0, 1);
      outString.Assign(tmp);
      return NS_OK;
    }
    NS_WARNING("Invalid UTF-8 string");
    return NS_ERROR_UNEXPECTED;
  }

  nsresult rv;
  nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr <nsIUnicodeDecoder> decoder;

  // get an unicode converter
  if (aIsCharsetCanonical)  // optimize for modified UTF-7 used by IMAP
    rv = ccm->GetUnicodeDecoderRaw(aCharset, getter_AddRefs(decoder));
  else
    rv = ccm->GetUnicodeDecoder(aCharset, getter_AddRefs(decoder));
  NS_ENSURE_SUCCESS(rv, rv);

  const char *originalSrcPtr = inString.get();
  const char *currentSrcPtr = originalSrcPtr;
  PRInt32 originalLength = inString.Length();
  PRInt32 srcLength;
  PRInt32 dstLength;
  PRUnichar localbuf[512];
  PRInt32 consumedLen = 0;

  outString.Truncate();

  // convert
  while (consumedLen < originalLength) {
    srcLength = originalLength - consumedLen;  
    dstLength = 512;
    rv = decoder->Convert(currentSrcPtr, &srcLength, localbuf, &dstLength);
    if (NS_FAILED(rv) || dstLength == 0)
      break;
    outString.Append(localbuf, dstLength);

    currentSrcPtr += srcLength;
    consumedLen = currentSrcPtr - originalSrcPtr; // src length used so far
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_MSG_BASE char* nsMsgI18NEncodeMimePartIIStr ( const char *  header,
PRBool  structured,
const char *  charset,
PRInt32  fieldnamelen,
PRBool  usemime 
)

Encode an input string into RFC 2047 form.

Parameters:
header[IN] A header to encode.
structured[IN] Specify the header is structured or non-structured field (See RFC-822).
charset[IN] Charset name to convert.
fieldnamelen[IN] Header field name length. (e.g. "From: " -> 6)
usemime[IN] If false then apply charset conversion only no MIME encoding.
Returns:
Encoded buffer (in C string) or NULL in case of error.

Definition at line 240 of file nsMsgI18N.cpp.

{
  // No MIME, convert to the outgoing mail charset.
  if (PR_FALSE == usemime) {
    nsCAutoString convertedStr;
    if (NS_SUCCEEDED(ConvertFromUnicode(charset, NS_ConvertUTF8toUTF16(header),
                                        convertedStr)))
      return PL_strdup(convertedStr.get());
    else
      return PL_strdup(header);
  }

  char *encodedString = nsnull;
  nsresult res;
  nsCOMPtr<nsIMimeConverter> converter = do_GetService(NS_MIME_CONVERTER_CONTRACTID, &res);
  if (NS_SUCCEEDED(res) && nsnull != converter)
    res = converter->EncodeMimePartIIStr_UTF8(header, structured, charset, fieldnamelen, kMIME_ENCODED_WORD_SIZE, &encodedString);

  return NS_SUCCEEDED(res) ? encodedString : nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Return charset name of file system (OS dependent).

Returns:
File system charset name.

Definition at line 203 of file nsMsgI18N.cpp.

{
       /* Get a charset used for the file. */
       static nsCAutoString fileSystemCharset;

       if (fileSystemCharset.IsEmpty()) 
       {
              nsresult rv;
              nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
        if (NS_SUCCEEDED(rv)) {
          rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName,
                                           fileSystemCharset);
        }

              if (NS_FAILED(rv)) 
                     fileSystemCharset.Assign("ISO-8859-1");
       }
       return fileSystemCharset.get();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Convert from unicode to charset, generates NNTP XPAT search string.

Migrated from mozilla classic, see "http://lxr.mozilla.org/classic/source/include/libi18n.h#2162" for detail.

Parameters:
aCharset[IN] Charset name to convert.
inString[IN] Input unicode string to convert.
outString[OUT] Converted output, the pattern should be send to NNTP XPAT command for searching non-ASCII header.
Returns:
nsresult.

Definition at line 545 of file nsMsgI18N.cpp.

{
  outString.AssignWithConversion(inString);
  return NS_OK;
}

Return accept language.

Note, the return value is not valid after this method gets called again.

Returns:
Accept language.

Definition at line 554 of file nsMsgI18N.cpp.

{
  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); 
  if (prefBranch)
  {
    nsCOMPtr<nsIPrefLocalizedString> prefString;

    prefBranch->GetComplexValue("intl.accept_languages",
                                NS_GET_IID(nsIPrefLocalizedString),
                                getter_AddRefs(prefString));
    if (prefString)
    {
      nsXPIDLString ucsval;
      prefString->ToString(getter_Copies(ucsval));
      if (!ucsval.IsEmpty())
      {
        static nsCAutoString acceptLang;
        LossyCopyUTF16toASCII(ucsval, acceptLang);
        return acceptLang.get();
      }
    }
  }

  // Default Accept-Language
  return "en";
}

Here is the call graph for this function:

Check if given charset is multibye (e.g.

Shift_JIS, Big5).

Parameters:
charset[IN] Charset name.
Returns:
True if multibyte

Definition at line 268 of file nsMsgI18N.cpp.

{
  nsresult res;
  nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(kCharsetConverterManagerCID, &res);
  PRBool result = PR_FALSE;

  if (NS_SUCCEEDED(res)) {
    nsAutoString charsetData;
    res = ccm->GetCharsetData(charset, NS_LITERAL_STRING(".isMultibyte").get(), charsetData);
    if (NS_SUCCEEDED(res)) {
      result = charsetData.LowerCaseEqualsLiteral("true");
    }
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Parse for META charset.

Parameters:
fileSpec[IN] A filespec.
Returns:
A charset name or empty string if not found.

Definition at line 342 of file nsMsgI18N.cpp.

{ 
  static char charset[kMAX_CSNAME+1]; 
  char buffer[512]; 

  *charset = '\0'; 

  if (fileSpec->IsDirectory()) {
    NS_ASSERTION(0,"file is a directory");
    return charset; 
  }

  nsInputFileStream fileStream(*fileSpec); 

  while (!fileStream.eof() && !fileStream.failed() && 
         fileStream.is_open()) { 
    fileStream.readline(buffer, 512); 
    if (*buffer == nsCRT::CR || *buffer == nsCRT::LF || *buffer == 0) 
      continue; 

    PRUint32 len = PL_strlen(buffer);
    for (PRUint32 i = 0; i < len; i++) { 
      buffer[i] = toupper(buffer[i]); 
    } 

    if (PL_strstr(buffer, "/HEAD")) 
      break; 

    if (PL_strstr(buffer, "META") && 
        PL_strstr(buffer, "HTTP-EQUIV") && 
        PL_strstr(buffer, "CONTENT-TYPE") && 
        PL_strstr(buffer, "CHARSET")) { 
      char *cp = PL_strstr(PL_strstr(buffer, "CHARSET"), "=");
      char *newStr;
      char *token = cp ? nsCRT::strtok(cp + 1, " \"\'", &newStr) : nsnull;
      if (token) { 
        PL_strncpy(charset, token, sizeof(charset));
        charset[sizeof(charset)-1] = '\0';

        // this function cannot parse a file if it is really
        // encoded by one of the following charsets
        // so we can say that the charset label must be incorrect for
        // the .html if we actually see those charsets parsed
        // and we should ignore them
        if (!nsCRT::strncasecmp("UTF-16", charset, sizeof("UTF-16")-1) || 
            !nsCRT::strncasecmp("UTF-32", charset, sizeof("UTF-32")-1))
          charset[0] = '\0';

        break;
      } 
    } 
  } 

  return charset; 
} 

Here is the call graph for this function:

Here is the caller graph for this function:

NS_MSG_BASE nsresult nsMsgI18NSaveAsCharset ( const char *  contentType,
const char *  charset,
const PRUnichar inString,
char **  outString,
char **  fallbackCharset = nsnull,
PRBool isAsciiOnly = nsnull 
)

Convert from charset to unicode.

Also does substitution for unconverted characters (e.g. entity, '?').

Parameters:
contentType[IN] text/plain or text/html.
charset[IN] Charset name to convert.
inString[IN] Input unicode string to convert.
outString[OUT] Allocated and converted output C string. Need PR_FREE.
fallbackCharset[OUT] null if fallback charset is not needed. Otherwise, a fallback charset name may be set if that was used for the conversion. Caller is responsible for freeing the memory (or use nsXPIDLCString).
isAsciiOnly[OUT] null if non ASCII info is not needed. Otherwise, true is set if the input data is ASCII only false otherwise.
Returns:
nsresult.

Definition at line 414 of file nsMsgI18N.cpp.

{
  NS_ENSURE_ARG_POINTER(contentType);
  NS_ENSURE_ARG_POINTER(charset);
  NS_ENSURE_ARG_POINTER(inString);
  NS_ENSURE_ARG_POINTER(outString);

  *outString = nsnull;

  if (nsCRT::IsAscii(inString)) {
    if (isAsciiOnly)
      *isAsciiOnly = PR_TRUE;
    *outString = nsCRT::strdup(NS_LossyConvertUTF16toASCII(inString).get());
    return (nsnull != *outString) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
  }
  if (isAsciiOnly)
    *isAsciiOnly = PR_FALSE;

  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 <nsICharsetAlias> calias =
    do_GetService(NS_CHARSETALIAS_CONTRACTID, &res);
  NS_ENSURE_SUCCESS(res, res);

  nsCAutoString charsetName;
  res = calias->GetPreferred(nsDependentCString(charset),
                             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(charsetName.get(),
                     charsetName.EqualsLiteral("ISO-8859-1") ?
                     nsISaveAsCharset::attr_htmlTextDefault :
                     nsISaveAsCharset::attr_EntityAfterCharsetConv + nsISaveAsCharset::attr_FallbackDecimalNCR, 
                     nsIEntityConverter::html32);
  else
    // fallback for text/plain: first try transliterate then '?'
    res = conv->Init(charsetName.get(), 
                     nsISaveAsCharset::attr_FallbackQuestionMark + nsISaveAsCharset::attr_EntityAfterCharsetConv, 
                     nsIEntityConverter::transliterate);
  NS_ENSURE_SUCCESS(res, res);

  const PRUnichar *input = inString;

  // Mapping characters in a certain range (required for Japanese only)
  nsAutoString mapped;
  if (charsetName.EqualsLiteral("ISO-2022-JP")) {
    static PRInt32 sSendHankakuKana = -1;
    if (sSendHankakuKana < 0) {
      nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_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(prefBranch->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)) {
        res = textTransform->Change(inString, nsCRT::strlen(inString), mapped);
        if (NS_SUCCEEDED(res))
          input = mapped.get();
      }
    }
  }

  // Convert to charset
  res = conv->Convert(input, outString);

  // If the converer cannot encode to the charset,
  // then fallback to pref sepcified charsets.
  if (NS_ERROR_UENC_NOMAPPING == res && !bTEXT_HTML && fallbackCharset) {
    nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &res));
    NS_ENSURE_SUCCESS(res, res);

    nsCAutoString prefString("intl.fallbackCharsetList.");
    prefString.Append(charset);
    nsXPIDLCString fallbackList;
    res = prefBranch->GetCharPref(prefString.get(), getter_Copies(fallbackList));
    // do the fallback only if there is a pref for the charset
    if (NS_FAILED(res) || fallbackList.IsEmpty())
      return NS_ERROR_UENC_NOMAPPING;

    res = conv->Init(fallbackList.get(), 
                     nsISaveAsCharset::attr_FallbackQuestionMark + 
                     nsISaveAsCharset::attr_EntityAfterCharsetConv +
                     nsISaveAsCharset::attr_CharsetFallback, 
                     nsIEntityConverter::transliterate);
    NS_ENSURE_SUCCESS(res, res);

    // free whatever we have now
    PR_FREEIF(*outString);  

    res = conv->Convert(input, outString);
    NS_ENSURE_SUCCESS(res, res);

    // get the actual charset used for the conversion
    if (NS_FAILED(conv->GetCharset(fallbackCharset)))
      *fallbackCharset = nsnull;
  }
  // In case of HTML, non ASCII may be encoded as CER, NCR.
  // Exclude stateful charset which is 7 bit but not ASCII only.
  else if (isAsciiOnly && bTEXT_HTML && *outString &&
           !nsMsgI18Nstateful_charset(charsetName.get()))
    *isAsciiOnly = nsCRT::IsAscii(*outString);

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Check if given charset is stateful (e.g.

ISO-2022-JP).

Parameters:
charset[IN] Charset name.
Returns:
True if stateful

Definition at line 262 of file nsMsgI18N.cpp.

{
  //TODO: use charset manager's service
  return (nsCRT::strcasecmp(charset, "ISO-2022-JP") == 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_MSG_BASE void nsMsgI18NTextFileCharset ( nsACString &  aCharset)

Return charset name of text file (OS dependent).

Parameters:
aCharset[OUT] Text file charset name.

Definition at line 224 of file nsMsgI18N.cpp.

{
  nsresult rv;
  nsCOMPtr <nsIPlatformCharset> platformCharset =
    do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
  if (NS_SUCCEEDED(rv)) {
    rv = platformCharset->GetCharset(kPlatformCharsetSel_PlainTextInFile,
                                     aCharset);
  }

  if (NS_FAILED(rv))
    aCharset.Assign("ISO-8859-1");
}

Here is the call graph for this function:

Here is the caller graph for this function: