Simple MIME Parts
To process the body of a simple MIME part, use the getBody() function to retrieve the body of the part as a string. For example:
 
RWMimePart message;
 
// ... fill message from a string, determine that the message
// is not a multipart message
 
RWCString body = message.getBody();
The getBody() function returns the body exactly as contained in the original data string. Depending on the Content-Transfer-Encoding of the message, you may need to decode the body. For convenience, the static decode() function of RWMimeUtils accepts all legal MIME encodings. Rather than checking the value of the Content-Transfer-Encoding to determine if decoding is necessary, it’s easier to always decode the message, as shown:
 
RWMimePart message;
 
// ... fill message from a string, determine that message
// is not multipart
 
RWCString body = message.getBody();
 
size_t encPos =
message.findHeader(RWMimeContentTransferEncodingHeader::Label);
 
if (encPos != RW_NPOS)
{
RWMimeContentTransferEncodingHeader cTEHead =
message.getHeader(encPos);
 
try
{
body = RWMimeUtils::decode(body, cTEHead.getEncoding());
}
catch (const RWMimeError& msg)
{
// Invalid content transfer encoding value, or
// the value does not match the format of the body.
}
}
The snippet above skips the decoding step if the part has no Content-Transfer-Encoding header. Since the MIME specification states that parts without a Content-Transfer-Encoding header are unencoded 7-bit ASCII, this approach is safe for any valid MIME message.
Depending on the Content-Type, the body of the part may be in canonical form. This is most common for text messages. To convert a text message from canonical form to a platform-specific format, use the static replaceLineDelimiters() function of RWMimeUtils. For example, to convert text from canonical form to UNIX text:
 
body = RWMimeUtils::replaceLineDelimiter(body, "\n");