Multipart MIME Parts
If the part contains multipart content, create an RWMimeMultipart from the part. This conversion simply creates a new handle to the underlying implementation. For example,
 
if (message.isMultipart())
{
RWMimeMultipart multipart(message);
// ... process multipart
}
An RWMimeMultipart contains an indexed collection of MIME parts. The multipart provides several methods for working the part collection. The getPartCount() function returns the number of parts the multipart contains. To retrieve a part from the multipart, use the getPart() function with the position of the part. If you try to retrieve a part that doesn’t exist (for example, asking for the part at position 10 in a multipart body that only has 3 parts), the getPart() function throws RWBoundsErr. To retrieve every part in a message, use code like the following:
 
// ... message is an RWMimePart that contains a multipart message
 
RWMimeMultipart multipart(message);
 
for (size_t pos = 0; pos < multipart.getPartCount(); ++pos)
{
 
RWMimePart part = multipart.getPart(pos);
 
// ... process the part
 
}
A multipart also provides the findPart() function for locating a part that contains a specific header. The function accepts a header, searches through the multipart body’s header collection, and returns the location of the first part with a matching header. If no parts match, the function returns RW_NPOS. Since MIME header labels aren’t case-sensitive, f-indPart() uses case-insensitive comparisons for header labels. Comparisons for values depend on the header type. Once you’ve found the location of a part, use getPart() to retrieve the part from the collection, as shown below:
 
// ... message is an RWMimePart that contains a multipart message
 
RWMimeMultipart multipart(message);
 
RWMimeContentIdHeader cid("<part004@roguewave.example>");
 
size_t partPos = multipart.findPart(cid);
 
if (partPos != RW_NPOS)
{
RWMimePart part = multipart.getPart(partPos);
// ... process the part
}
else
{
// ... the message does not contain a part with the content id
// <part004@roguewave.example>
}
Notice that the part retrieved from the multipart body is a MIME part that also requires processing. Example 31 in Program: Processing a Multipart MIME Message demonstrates one approach for processing multipart bodies.