The ImapGetMessage function is used to retrieve a message
from the server and copy it into a local buffer. The function may
be used in one of two ways, depending on the needs of the
application. The first method is to pre-allocate a buffer large
enough to store the contents of the message. In this case, the
lpvMessage parameter will point to the buffer that was
allocated, the value that the lpdwLength parameter points to
should be initialized to the size of that buffer.
The second method that can be used is have the lpvMessage
parameter point to a global memory handle which will contain the
message data when the function returns. In this case, the value
that the lpdwLength parameter points to must be initialized
to zero. It is important to note that the memory handle returned by
the function must be freed by the application, otherwise a memory
leak will occur.
This function will cause the current thread to block until the
transfer completes, a timeout occurs or the transfer is canceled.
During the transfer, the IMAP_EVENT_PROGRESS event will be
periodically fired, enabling the application to update any user
interface controls. Event notification must be enabled, either by
calling ImapEnableEvents, or by registering a callback
function using the ImapRegisterEvent function.
To determine if a message is a multipart MIME message, use the
ImapGetMessageParts function. The return value specifies the
number of parts in the message, with a value greater than one
indicating that it is a multipart message. Combining the
IMAP_SECTION_HEADER and IMAP_SECTION_BODY options will only return
the header and body for the specified message if the
nMessagePart parameter is zero. Due to a limitation of the
IMAP FETCH command, if a message part is specified then only the
body of that message part will be returned.
Note that unlike the SocketTools MIME API which considers the
first message part to be zero, the IMAP protocol defines the first
message part to be one.