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 31 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 29. 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.


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 31: Processing a multipart MIME message

//1

Creates a constant string that contains the multipart MIME message.

//2

The 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.

//3

The 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.

//4

Retrieves the header at position pos.

//5

Prints the header label and value to standard output.

//6

Checks 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.

//7

Converts the RWMimePart to an RWMimeMultipart. The assignment on this line implicitly calls the conversion constructor of RWMimeMultipart to create the multipart.

//8

Increments pos to index each part in the multipart.

//9

Calls decomposePart(), passing the MIME part at pos as the first argument. The second argument increases the output indentation for the part by 5 spaces.

//10

Retrieves the body of the part as an RWCString.

//11

Locates the Content-Transfer-Encoding header of the part.

//12

Retrieves the Content-Transfer-Encoding header.

//13

Decodes 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.

//14

Converts 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.

//15

Print 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.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.