MIME and Internationalized Messages
The MIME package supports the creation of messages in character sets beyond just US-ASCII. When combined with the Internationalization Module of SourcePro Core, they provide a complete solution for creating MIME messages for other character sets. Example 33 illustrates the use of MIME with the Internationalization Module.
NOTE: The following example uses classes from the Internationalization Module of SourcePro Core. For more information on the Internationalization Module, refer to the Internationalization Module User’s Guide and SourcePro API Reference Guide.
Example 33 – Using MIME with the Internationalization Module
// Create the subject and body of the MIME message.
RWCString subject("Hello World");
RWCString body("This is the message body.");
 
// Create strings representing the charsets we're
// working in.
RWCString origCharset("US-ASCII");
RWCString newCharset("UTF-16");
 
// Create a string representing the transfer encoding.
RWCString transferEncoding("base64");
 
// Create unicode converts for converting to and from
// RWUStrings.
RWUToUnicodeConverter toUnicode(origCharset);
RWUFromUnicodeConverter fromUnicode(newCharset);
 
// Convert our original strings in RWUStrings.
RWUString uSubject(subject, toUnicode);
RWUString uBody(body, toUnicode);
 
// Convert the ustrings to RWCString buffers of the
// appropriate encoding.
RWCString nSubject = uSubject.toBytes(fromUnicode);
RWCString nBody = uBody.toBytes(fromUnicode);
 
// Construct a MIME Subject header.
nSubject = RWMimeUtils::headerEncode(nSubject, newCharset, "B");
RWMimeGenericHeader subjectHeader("Subject", nSubject);
 
// Construct a MIME Part, with an appropriate content type.
RWMimePart message(RWMimeTextType("plain", newCharset));
 
// Associate the headers with the MIME part.
message.insertHeader(subjectHeader);
message.insertHeader(RWMimeVersionHeader());
message.insertHeader(RWMimeContentTransferEncodingHeader(transferEncoding));
 
// Associate the body with the MIME part.
nBody = RWMimeUtils::encode(nBody, transferEncoding);
message.setBody(nBody);
 
cout << message.asString() << endl;