CImapClient::EncodeMailboxName Method  
 
INT EncodeMailboxName(
  LPCTSTR lpszMailboxName,  
  LPTSTR lpszEncodedName,  
  INT nMaxLength,  
  INT nCodePage  
);
INT EncodeMailboxName(
  LPCTSTR lpszMailboxName,  
  CString& strEncodedName,  
  INT nCodePage  
);

The EncodeMailboxName method encodes a mailbox name using modified UTF-7 encoding.

Parameters

lpszMailboxName
A null-terminated string which contains the name of the mailbox. If the application does not use Unicode, this string is automatically converted to Unicode using the code page specified by the nCodePage parameter. This parameter cannot be a NULL pointer or an empty string.
lpszEncodedName
A null-terminated string buffer which will contain the UTF-7 encoded mailbox name. This parameter cannot be NULL and must be large enough to contain the entire name. The string will be null-terminated and will only contain printable ASCII characters. An alternate form of the method accepts a CString object which will contain the decoded mailbox name when the method returns.
nMaxLength
An integer value which specifies the maximum number of characters which can be copied into the lpszEncodedName string buffer. This value must be greater than zero and the buffer must be large enough to store the entire name.
nCodePage
An optional integer value which specifies the code page used when decoding the mailbox name. If the application does not use Unicode, this parameter can be any valid code page. The default value is CP_ACP which specifies the current active code page for the locale. Applications which are built using Unicode should always use the default value.

Return Value

If the method succeeds, it returns the number of characters in the encoded mailbox name. If an error occurs, the method returns zero. To get extended error information, call GetLastError.

Remarks

Mailbox names which contain non-ASCII characters must be converted to a modified version of UTF-7 encoding as defined by the IMAP4 protocol. This encoding allows applications to reference mailbox names which contain Unicode characters and provides support for languages other than English. This method is used to convert a mailbox name which contains non-ASCII characters to the UTF-7 encoded required by IMAP servers.

For example, if the lpszMailboxName parameter specifies the string "Δοκιμή", this method will encode it as "&A5QDvwO6A7kDvAOu-" and return that value in the lpszEncodedName buffer. It is recommended you compile the application using the Unicode character set whenever possible to ensure the mailbox name is encoded correctly.

If the application is not compiled using Unicode, the mailbox name will be automatically converted to Unicode using the code page specified by the nCodePage parameter. If the code page does not support the characters used in the mailbox name, this can result in an incorrect conversion. Using the previous example, the mailbox name will always encode correctly if the Unicode version of the method is used, but the ANSI version of the method will only encode it correctly if the code page is specified as 1253 (Greek).

This method should not be used to convert strings between Unicode and UTF-7. The encoding format is specifically intended for use with the IMAP4 protocol and should never be used for general purpose encoding or decoding. If you need to convert a Unicode string to UTF-7, use the Win32 API function WideCharToMultiByte.

Requirements

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

See Also