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.2 Creating a Simple MIME Part

This section describes the process for creating a simple MIME part that can also be transmitted as a standalone message.

A MIME part that contains simple data (rather than another MIME part) is the basic building block of the MIME format. Even the most complicated MIME message boils down to a collection of simple MIME parts. Since the MIME specification defines a MIME message as any MIME part that contains a MIME-Version header, the procedure in this section applies equally to creating a MIME part.

To create a simple MIME message:

  1. Prepare the data, as described in Section 9.1.

  2. Create headers for the message (Section 9.2.1).

  3. Create an RWMimePart (Section 9.2.2).

  4. Insert the headers into the message (Section 9.2.3).

  5. Insert the message body into the message (Section 9.2.4).

  6. Create a MIME string (Section 9.2.5).

9.2.1 Create Headers for the Part

Create headers describing the content of the message. Create any protocol-specific headers the part requires.

MIME parts often require protocol-specific headers in addition to MIME headers. For example, email messages require a Date header and a From header. The RWMimeGenericHeader class represents a general-purpose header. If the part requires headers that aren't part of the MIME format, use instances of RWMimeGenericHeader for those headers. For example, the line below creates a From header for an email message:

9.2.2 Create an RWMimePart

Now that the content and the headers are created, construct an RWMimePart object, as shown below:

9.2.3 Add the Headers to the Part

Add the headers to the part using the insertHeader() function, for example:

The MIME specification requires that a MIME message contain a MIME-Version header. Be sure to insert the header into a part that will be used as a top-level message, as shown below:

9.2.4 Add the String to the Part

Add the string to the MIME part using the setBody() function. This function sets the body of the MIME part to the provided string. For example:

For a MIME part with simple content, the setBody() function does not process the provided string at all. The programmer is responsible for making sure that the headers of the part accurately describe the content in the string.

9.2.5 Create a MIME String

The MIME part is now complete and ready to use. To send the part over a network, convert the message into a MIME string using the asString() function, as shown:

The function doesn't enforce a particular part style, or even guarantee that the part is correct MIME. The function does contain some safeguards that prevent a program from generating an unintelligible part. If the function can't create a structurally correct MIME string, the function throws RWMimeError.



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.