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.1 Preparing Data

Although the MIME specification allows a message to contain nearly any content, MIME messages are typically transmitted over protocols that have stricter requirements. By following a few simple guidelines, you can easily construct message bodies that meet the requirements of nearly all protocols.

To create a message body, follow these steps:

  1. Create an RWCString containing the data.

  2. Convert text to canonical form.

  3. Encode the string, if necessary.

Each step is discussed in more detail below. Section 9.3, "Program: Creating a Simple MIME Message," presents a complete example program that creates a simple MIME message.

9.1.1 Create an RWCString

The exact process for creating the data depends on the specific application. No matter how the data is originally created, store the data for the body in an RWCString. Since an RWCString can efficiently store any sequence of bytes, including embedded nulls, the class works well to represent a message body regardless of the content.

9.1.2 Convert Text to Canonical Form

Data within a MIME message should always be converted to the format defined by MIME for that data type, the canonical form (see Section 10.2.1). For most data formats, the canonical form is identical to the normal format of the data.

One common case where the canonical form may not be identical to the normal data format is text. For text, the canonical form represents a line break as a carriage return (ASCII 13) followed by a line feed (ASCII 10). RWMimeUtils provides a static replaceLineDelim() function for translating text to and from canonical form. When provided with only an RWCString as an argument, the function returns a copy of the string converted to canonical form. To convert text to canonical form:

When a second argument is provided, the function translates each line break in the original string to the character sequence in the second argument. For example, UNIX platforms use a single newline character for a line break. To translate the line breaks in a canonical form string to UNIX line breaks, provide a newline as the second argument to replaceLineDelim(), as shown in the following code:

9.1.3 Encode the Data

If the message is 7-bit ASCII text or the transport protocol preserves binary messages, it's most efficient to use an identity encoding – an encoding that describes the data but does not alter the data. Otherwise, the best encoding depends on the data.

Notice that base 64 encoding is the only safe choice for transmitting binary data over a protocol that does not preserve binary data, such as SMTP.

For text messages, the best encoding depends on the number of 8-bit characters. Quoted-printable encoding preserves 7-bit ASCII characters, while base 64 more efficiently encodes 8-bit characters. The practical result is that base 64 encoding is a good choice for text with a relatively large number of 8-bit characters, whereas quoted-printable encoding produces shorter, mostly human-readable messages for text that contains mostly 7-bit characters.

Convert data to canonical form before encoding the data (see Section 9.1.2). To encode the data, use the static encode() function from RWMimeUtils. For example, to encode binary data using the base64 encoding:

Encodings are discussed in detail in Section 10.3, "Transfer Encodings,"



Previous fileTop of DocumentContentsNo linkNext 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.
Provide feedback to Rogue Wave about its documentation.