CMailMessage::EnumHeaders Method  
 
INT EnumHeaders();
INT EnumHeaders(
  LPCTSTR* lpHeaderList,  
  INT nMaxHeaders  
);

The EnumHeaders method returns a list of pointers to all header field names in the current message part. This can be used in conjunction with the GetHeader method to retrieve the values for every header in the message.

Parameters

lpHeaderList
Pointer to an array of pointers to null terminated header field names. If this parameter is NULL, the method only returns the number of headers in the current message part.
nMaxHeaders
The maximum number of header fields which may be returned in the lpHeaderList parameter.

Return Value

If the method succeeds, the return value is the total number of headers that are defined in the current message part. If the method fails, the return value is MIME_ERROR. To get extended error information, call GetLastError.

Remarks

The values returned in the header list array must not be directly modified by the application. There is no specific order in which the header fields are enumerated by this method. The header fields from an imported message may not be returned in the same order as which they appear in the message. An application should never make an assumption about the order in which one or more header fields are defined.

If this method is called without any arguments, it returns the number of headers in the current message part but does not return any data. This is useful for determining how much memory must be allocated for the lpHeaderList argument.

Example

// Determine the total number of headers in the current
// message part

nHeaders = pMessage->EnumHeaders();
if (nHeaders > 0)
{

    // Allocate memory for the list of headers

    lpHeaderList = (LPCTSTR *)malloc(nHeaders * sizeof(LPCTSTR));
    assert(lpHeaderList != NULL);

    // Retrieve the list of headers in the current
    // message part, and get their values

    pMessage->EnumHeaders(lpHeaderList, nHeaders);
    for (nIndex = 0; nIndex < nHeaders; nIndex++)
    {

         LPCTSTR lpszValue;
         lpszValue = pMessage->GetHeader(lpHeaderList[nIndex]);
         assert(lpszValue != NULL);

         printf("%s: %s\n", lpHeaderList[nIndex], lpszValue);

    }
}

Requirements

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

See Also

GetFirstHeader, GetHeader, GetNextHeader, SetHeader