Program: Processing a Simple MIME Message
Example 30 uses the MIME package to process a simple MIME message and print the components of the message to standard output. The message processed is essentially identical to the message generated in
Example 28. We’ve taken shortcuts to keep the example simple. A production application would normally check to make sure that the message received is actually a simple MIME message before processing the message (see
“Process the Body”). Source for this program is in
BasicMimeMessageDecomposition.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 Products and Building Your Applications.
Example 30 – Processing a simple MIME message
#include <rw/mime/RWMimePart.h>
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
// This is roughly equivalent to the message generated in
// the BasicMimeMessageComposition example.
const RWCString messageStr(
"MIME-Version: 1.0\r\n"
"To: <developer@yourcompany.com>\r\n"
"From: <developer@roguewave.com>\r\n"
"Subject: Sample MIME Message from Rogue Wave\r\n"
"Content-Type: text/plain\r\n"
"\r\n"
"This is a simple MIME Message generated with the\r\n"
"Internet Protocols Module of SourcePro Net.\r\n"); //1
int main(void)
{
// Create a RWMimePart object.
RWMimePart message; //2
// extract the message from the string.
message.fromString(messageStr); //3
cout << "MIME Message Extraction" << endl << endl;
// Show header information for the message.
cout << "...Headers" << endl << endl;
for (size_t pos = 0; pos < message.getHeaderCount(); ++pos) //4
{
RWMimeHeader header = message.getHeader(pos); //5
cout << header.asString() << endl; //6
}
// Display the body of the message. Normally, you would
// convert line delimiters into local form for your OS
// before displaying a text body. But for this example,
// we'll just print it out in canonical form.
cout << endl << "...Body" << endl << endl << message.getBody() << endl; //7
return 0;
}
This program generates the following output:
MIME Message Extraction
...Headers
MIME-Version: 1.0
To: <developer@yourcompany.com>
From: <developer@roguewave.com>
Subject: Sample MIME Message from Rogue Wave
Content-Type: text/plain
...Body
This is a simple MIME Message generated with the
Internet Protocols Module of SourcePro Net.