CMailMessage::EncodeText Method  
 
LONG EncodeText(
  LPCTSTR lpszInput,  
  LONG cchInput,  
  LPTSTR lpszOutput,  
  LONG cchOutput,  
  UINT nCharacterSet,  
  UINT nEncodingType  
);
LONG EncodeText(
  LPCTSTR lpszInput,  
  LONG cchInput,  
  CString& strOutput,  
  UINT nCharacterSet,  
  UINT nEncodingType  
);

The EncodeText method encodes a string using base64 or quoted-printable encoding.

Parameters

lpszInput
A pointer to a null terminated string which contains the encoded text. This parameter cannot be a NULL pointer.
cchInput
An integer value which specifies the number of characters of text in the input string which should be encoded. If this parameter is omitted or the value is -1, the entire length of the string up to the terminating null will be encoded.
lpszOutput
A pointer to a string buffer that will contain the encoded text. This buffer must be large enough to store all of the characters in the encoded text, including the terminating null character. This parameter cannot be NULL. An alternate version of this method accepts a CString object instead of a fixed-length string buffer.
cchOutput
An integer value which specifies the maximum number of characters which can be copied into the output string buffer. The buffer must be large enough to store all of the encoded text and terminating null character. This value must be greater than zero.
nCharacterSet
A numeric identifier which specifies the character set to use when encoding the input text. A value of zero specifies the character set is undefined and no Unicode text conversion is performed when the input string is encoded.
nEncodingType
An integer value that specifies the encoding method used. It may be one of the following values:
Value Description
MIME_ENCODING_QUOTED Quoted-printable encoding is designed for textual messages where most of the characters are represented by the ASCII character set and is generally human-readable. Non-printable characters or 8-bit characters with the high bit set are encoded as hexadecimal values and represented as 7-bit text. Quoted-printable encoding is typically used for messages which use character sets such as ISO-8859-1, as well as those which use HTML.
MIME_ENCODING_BASE64 Base64 encoding converts binary or text data to ASCII by translating it so each base64 digit represents 6 bits of data. This encoding method is commonly used with messages that contain binary data (such as binary file attachments), or when text uses extended characters that cannot be represented by 7-bit ASCII. It is recommended that you use base64 encoding with Unicode text.

Return Value

If the input buffer can be successfully encoded, the return value is the length of the encoded output string. If the method returns zero, then no text was encoded and the output string buffer will be empty. If the method fails, the return value is MIME_ERROR. To get extended error information, call GetLastError.

Remarks

This method provides a means to encode text using either base64 or quoted-printable encoding. It is not necessary to use this method to encode text when using the SetText method. The class will automatically encode message text which contains non-ASCII characters using the character set specified when the message is created.

If the nCharacterSet parameter parameter is non-zero, the method will encode the text using the specified character set. If the Unicode version of this method is called, the input text is converted to ANSI using the code page associated with the character set. If the ANSI version of this method is called, the input text is converted to Unicode using the system default code page, and then back to ANSI using the specified character set.

If the nCharacterSet parameter specifies the MIME_CHARSET_UTF16 character set, you must specify MIME_ENCODING_BASE64 as the encoding method. Other encoding methods are not supported for Unicode strings and will cause the method to fail. It is not recommended you encode text as UTF-16 unless there is a specific requirement to use that character set.

It is recommended that you use the MIME_CHARSET_UTF8 character set whenever possible. It is capable of encoding all Unicode code points, and is a standard for virtually all modern Internet applications. In most cases, it is preferable to use MIME_ENCODING_BASE64 as the encoding method, with quoted-printable encoding only used for legacy support.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools11.h
Import Library: csmsgv11.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

DecodeText, GetText, SetText