ImapDecodeMailboxName Function  
 
INT WINAPI ImapDecodeMailboxName(
  INT nCodePage,  
  LPCSTR lpszMailboxName,  
  LPTSTR lpszDecodedName,  
  INT nMaxLength  
);

The ImapDecodeMailboxName function decodes a UTF-7 encoded mailbox name using the specified code page.

Parameters

nCodePage
An integer value which specifies the code page which should be used when decoding the mailbox name. If the ANSI version of this function is called, this parameter can be any valid code page, or the constant CP_ACP which specifies the current active code page for the locale. If the Unicode version of this function is called, this parameter should always be zero.
lpszMailboxName
A null-terminated string which contains the UTF-7 encoded name of the mailbox. The encoded string must use the modified UTF-7 format defined in the IMAP4 protocol standard. This parameter cannot be a NULL pointer or an empty string.
lpszDecodedName
A null-terminated string buffer which will contain the decoded mailbox name. This parameter cannot be NULL and must be large enough to contain the entire name.
nMaxLength
An integer value which specifies the maximum number of characters which can be copied into the lpszDecodedName string buffer. This value must be greater than zero and the buffer must be large enough to store the entire name.

Return Value

If the function succeeds, it returns the number of characters in the decoded mailbox name. If an error occurs, the function returns zero. To get extended error information, call ImapGetLastError.

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 function is used to convert a UTF-7 encoded mailbox name using the current locale, primarily for display purposes.

For example, if the lpszMailboxName parameter specifies the string "&A5QDvwO6A7kDvAOu-", this function will convert it to the Greek word "Δοκιμή" and return that value in the lpszDecodedName buffer. It is recommended you use the Unicode version of this function whenever possible to ensure the mailbox name is decoded correctly.

The ANSI version of this function should only be used with legacy applications which do not support Unicode. The decoded mailbox name will be converted 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 decode correctly if the Unicode version of the function is used, but the ANSI version of the function will only decode it correctly if the code page is specified as 1253 (Greek).

This function 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 UTF-7 encoded string to Unicode, use the Win32 API function MultiByteToWideChar.

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