Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Internet Protocols Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

9.8 Program: Processing a Multipart MIME Message

Example 30 uses the MIME package to process a multipart MIME message and print the component parts to standard output. The message this program contains is essentially identical to the message created in Example 28. Although we've kept the example simple for demonstration purposes, notice that a recursive approach to processing MIME parts works well for multipart messages. Source for this program is in MultipartMimeMessageDecomposition.cpp in the examples\mime directory.


NOTE -- Sample programs are located in the examples directory created for your installation. For more information, see Installing and Building Your SourcePro C++ Products and Building Your Applications.

Example 30: Processing a multipart MIME message

//1Creates a constant string that contains the multipart MIME message.
//2The decomposePart() function contains all the code necessary to decompose either a simple MIME part or a multipart MIME part. For a simple MIME part, the function processes and displays the parts. For a multipart MIME part, the function extracts each part, then calls itself with the extracted subpart as the first argument.
//3The for loop on this line increments pos to index each header in the part. To find a specific header, you could also use the findHeader() function of RWMimePart.
//4Retrieves the header at position pos.
//5Prints the header label and value to standard output.
//6Checks to see if the part being processed has a multipart body. Lines through //9 process a multipart body. Line //10 and subsequent lines process a simple body.
//7Converts the RWMimePart to an RWMimeMultipart. The assignment on this line implicitly calls the conversion constructor of RWMimeMultipart to create the multipart.
//8Increments pos to index each part in the multipart.
//9Calls decomposePart(), passing the MIME part at pos as the first argument. The second argument increases the output indentation for the part by 5 spaces.
//10Retrieves the body of the part as an RWCString.
//11Locates the Content-Transfer-Encoding header of the part.
//12Retrieves the Content-Transfer-Encoding header.
//13Decodes the body string, using the value of the Content-Transfer-Encoding header as the encoding style. It's convenient to always decode() the body of any part with a Content-Transfer-Encoding header. The decode() function of RWMimeUtils returns the body string unchanged for the encoding styles 7bit, 8bit, and binary, so there's no risk of corrupting the data.
//14Converts the body string from canonical form to use single newlines as line separators. The example does this because the message contains only text parts. A production application would only do this conversion for body strings which have a text Content-Type.
//15Print the body string to standard output.

This program produces the following output (note that the longer lines are wrapped here):



Previous fileTop of DocumentContentsIndex pageNext file

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.