Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
comi18n.h File Reference
#include "msgCore.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define kMAX_CSNAME   64

Functions

char * MIME_DecodeMimeHeader (const char *header, const char *default_charset, PRBool override_charset, PRBool eatContinuations)
 Decode MIME header to UTF-8.
char * MIME_EncodeMimePartIIStr (const char *header, PRBool structured, const char *mailCharset, const PRInt32 fieldNameLen, const PRInt32 encodedWordSize)
 Encode an input string into RFC 2047 form.
char * NextChar_UTF8 (char *str)
 Get a next character position in an UTF-8 string.
nsresult MIME_detect_charset (const char *aBuf, PRInt32 aLength, const char **aCharset)
nsresult MIME_get_unicode_decoder (const char *aInputCharset, nsIUnicodeDecoder **aDecoder)
nsresult MIME_get_unicode_encoder (const char *aOutputCharset, nsIUnicodeEncoder **aEncoder)

Define Documentation

#define kMAX_CSNAME   64

Definition at line 47 of file comi18n.h.


Function Documentation

char* MIME_DecodeMimeHeader ( const char *  header,
const char *  default_charset,
PRBool  override_charset,
PRBool  eatContinuations 
)

Decode MIME header to UTF-8.

Uses MIME_ConvertCharset if the decoded string needs a conversion.

Parameters:
header[IN] A header to decode.
default_charset[IN] Default charset to apply to ulabeled non-UTF-8 8bit data
override_charset[IN] If PR_TRUE, default_charset used instead of any charset labeling other than UTF-8
eatContinuations[IN] If PR_TRUE, unfold headers
Returns:
Decoded buffer (in C string) or return NULL if the header needs no conversion

Definition at line 745 of file comi18n.cpp.

{
  nsresult rv;
  nsCOMPtr <nsIMIMEHeaderParam> mimehdrpar = do_GetService(NS_MIMEHEADERPARAM_CONTRACTID, &rv);
  if (NS_FAILED(rv))
    return nsnull;
  nsCAutoString result;
  rv = mimehdrpar->DecodeRFC2047Header(header, default_charset, override_charset, 
                                       eatContinuations, result);
  if (NS_SUCCEEDED(rv))
    return nsCRT::strdup(result.get());
  return nsnull;
}  

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult MIME_detect_charset ( const char *  aBuf,
PRInt32  aLength,
const char **  aCharset 
)

Definition at line 776 of file comi18n.cpp.

{
  nsresult res = NS_ERROR_UNEXPECTED;
  nsXPIDLString detector_name;
  *aCharset = nsnull;

  NS_GetLocalizedUnicharPreferenceWithDefault(nsnull, "intl.charset.detector", EmptyString(), detector_name);

  if (!detector_name.IsEmpty()) {
    nsCAutoString detector_contractid;
    detector_contractid.AssignLiteral(NS_STRCDETECTOR_CONTRACTID_BASE);

    AppendUTF16toUTF8(detector_name, detector_contractid);
    nsCOMPtr<nsIStringCharsetDetector> detector = do_CreateInstance(detector_contractid.get(), &res);
    if (NS_SUCCEEDED(res)) {
      nsDetectionConfident oConfident;
      res = detector->DoIt(aBuf, aLength, aCharset, oConfident);
      if (NS_SUCCEEDED(res) && (eBestAnswer == oConfident || eSureAnswer == oConfident)) {
        return NS_OK;
      }
    }
  }
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* MIME_EncodeMimePartIIStr ( const char *  header,
PRBool  structured,
const char *  mailCharset,
const PRInt32  fieldNameLen,
const PRInt32  encodedWordSize 
)

Encode an input string into RFC 2047 form.

This is a replacement for INTL_EncodeMimePartIIStr. Unlike INTL_EncodeMimePartIIStr, this does not apply any charset conversion. Use MIME_ConvertCharset in advance if the encoding string needs a conversion.

Parameters:
header[IN] A header to encode (utf-8 Cstring).
structured[IN] A boolean to swtich between structured field body and non-structured field body.
mailCharset[IN] Charset name (in C string) to convert.
fieldNameLen[IN] Header field name length (e.g. "From: " -> 6)
encodedWordSize[IN] Byte length limit of the output, ususally 72 (use kMIME_ENCODED_WORD_SIZE).
Returns:
Encoded buffer (in C string) or NULL in case of error.

Definition at line 762 of file comi18n.cpp.

{
  return apply_rfc2047_encoding(header, structured, mailCharset, fieldNameLen, encodedWordSize);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult MIME_get_unicode_decoder ( const char *  aInputCharset,
nsIUnicodeDecoder **  aDecoder 
)

Definition at line 803 of file comi18n.cpp.

{
  nsresult res;

  // get charset converters.
  nsCOMPtr<nsICharsetConverterManager> ccm = 
           do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res); 
  if (NS_SUCCEEDED(res)) {

    // create a decoder (conv to unicode), ok if failed if we do auto detection
    if (!*aInputCharset || !nsCRT::strcasecmp("us-ascii", aInputCharset))
      res = ccm->GetUnicodeDecoderRaw("ISO-8859-1", aDecoder);
    else
      res = ccm->GetUnicodeDecoder(aInputCharset, aDecoder);
  }
   
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult MIME_get_unicode_encoder ( const char *  aOutputCharset,
nsIUnicodeEncoder **  aEncoder 
)

Definition at line 824 of file comi18n.cpp.

{
  nsresult res;

  // get charset converters.
  nsCOMPtr<nsICharsetConverterManager> ccm = 
           do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res); 
  if (NS_SUCCEEDED(res) && *aOutputCharset) {
      // create a encoder (conv from unicode)
      res = ccm->GetUnicodeEncoder(aOutputCharset, aEncoder);
  }
   
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* NextChar_UTF8 ( char *  str)

Get a next character position in an UTF-8 string.

Example: s = NextChar_UTF8(s); // get a pointer for the next character

Parameters:
str[IN] An input C string (UTF-8).
Returns:
A pointer to the next character.

Definition at line 769 of file comi18n.cpp.

{
  return (char *) utf8_nextchar((unsigned char *) str);
}

Here is the call graph for this function: