MimeGetAllHeaders Function  
 
INT WINAPI MimeGetAllHeaders(
  HMESSAGE hMessage,  
  LPTSTR lpszHeaders,  
  INT nMaxLength  
);

The MimeGetAllHeaders function returns the complete RFC 822 header values in a string buffer.

Parameters

hMessage
Handle to the message.
lpszHeaders
Pointer to string buffer which will contain the header values for the specified message. This parameter may be NULL, in which case the function will calculate the number of characters needed to store the complete header block.
nMaxLength
An integer value which specifies the maximum number of characters that can be stored in the lpszHeaders string. If the lpszHeaders parameter is NULL, this value must be zero. If the lpszHeaders parameter is not NULL, this value must be large enough to store the entire list of addresses.

Return Value

If the function succeeds and the lpszHeaders parameter is NULL, the return value is the minimum number of characters that should be allocated to store all of the header values, including the terminating null character. If the lpszHeaders parameter is not NULL, then the return value is the number of characters copied into the string, not including the terminating null character. If the function fails, the return value is MIME_ERROR. To get extended error information, call MimeGetLastError.

Remarks

The MimeGetAllHeaders function will return all of the RFC 822 header values in a string buffer. This includes the message headers that are most commonly referred to, such as the To, From and Subject headers. Each header and its value are separated by a colon, and terminated with a carriage return and linefeed (CRLF) pair.

The headers and their values returned by this function will not be identical to the header block in the original message. If a header value is split across multiple lines, this function will fold the text, returning the complete header value on a single line of text and removing any extraneous whitespace. If the header value has been encoded by the mail client, this function will return the decoded value, not the original encoded value.

Example

LPTSTR lpszHeaders = NULL;
INT nLength;

// Determine the number of characters that should be allocated to store
// the RFC822 headers

nLength = MimeGetAllHeaders(hMessage, NULL, 0);

// Allocate the memory for the string buffer that is large enough and
// call MimeGetAllHeaders again

if (nLength > 0)
{
    lpszHeaders = (LPTSTR)LocalAlloc(LPTR, nLength * sizeof(TCHAR));
    if (lpszHeaders == NULL)
        return; // Virtual memory exhausted

    nLength = MimeGetAllHeaders(hMessage, lpszHeaders, nLength);  
}

// The lpszHeaders string now contains all of the RFC822 headers for the
// message, with each header terminated by a CRLF sequence

if (lpszHeaders != NULL)
{
    LocalFree((HLOCAL)lpszHeaders);
    lpszHeaders = NULL;
}

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

MimeGetFirstMessageHeader, MimeGetMessageHeader, MimeGetNextMessageHeader, MimeSetMessageHeader