Retrieve the Headers as Necessary
An
RWMimePart contains a body and an indexed collection of headers. The part provides several functions for working with headers. The
-getHeaderCount() function returns the number of headers the part contains. To retrieve a header from the part, use the
getHeader() function with the position of the header. If you try to retrieve a header that doesn’t exist (for example, asking for the header at position 10 in a part that only has 3 headers), the
getHeader() function throws
RWBoundsErr. For example, to retrieve the first header from a message:
if (message.getHeaderCount() > 0) // Make sure there’s a header
{
RWMimeHeader firstHeader = message.getHeader(0);
// ... do something with the first header
}
A message also provides the findHeader() function for locating a header with a given label. The function searches through the messages header collection and returns the location of the first header with a matching label. If no headers match, the function returns RW_NPOS. Since MIME header labels aren’t case-sensitive, f-indHeader() uses case-insensitive comparisons to find a match. Once you’ve found the location of a header, use getHeader() to retrieve the header from the collection, as shown below:
size_t idPos = message.findHeader(RWMimeContentIdHeader::Label);
if (idPos != RW_NPOS)
{
RWMimeContentIdHeader idHeader = message.getHeader(idPos);
// ... do something with the Content-ID header
}
else
{
// ... the message does not contain a Content-ID header
}