Multipart Bodies
A MIME part body may contain nested MIME parts. In this case, each nested part contains its own set of headers and its own part body. The top-level part has the media type multipart.
The MIME specification defines four multipart subtypes. The MIME package also supports an additional multipart subtype, the multipart/related content type described in RFC 2387. All multipart types require that the header value contain a boundary parameter. The value of the boundary parameter delimits the parts of the message. For example, the message snippet below contains two parts delimited by __the_boundary__:
 
Content-Type: multipart/mixed; boundary="__the_boundary__"
 
--__the_boundary__
 
This is the first part, in plain text.
--__the_boundary__
Content-Type: text/plain; charset=us-ascii
 
This is the second part, also in plain text but with a
Content-Type header.
--__the_boundary__--
Since the MIME format uses the value of the boundary parameter to tell where parts begin and end, it’s important that the value does not occur in the content of any message part. This restriction includes parts which are themselves multiparts. In other words, if a message contains more than one multipart, each multipart in the message must use a different boundary. Otherwise, a recipient has no way to reconstruct the message accurately.
NOTE: An RWMimeMultipart must not contain itself, either directly or indirectly. A part that contains itself cannot be represented as a string.
The RWMimeUtils class provides a static getUniqueBoundary() function that generates strings unlikely to occur in message content.
The relationship between the parts of a multipart media type determines the subtype. The table below describe common multipart types:
Table 2 – MIME multipart subtypes
Multipart subtype
Relationship of parts
mixed
Parts are unrelated documents (for example, email attachments).
related
Parts are components of a single document (for example, an HTML page and the images in that page).
parallel
Parts should be displayed simultaneously (for example, audio and video).
alternative
Parts contain the same content in alternative formats (for example, an HTML page and a plain text equivalent).
digest
Parts are RFC 822 (email) messages.
A Content-Type of multipart/mixed is typically used for email attachments, and is therefore the most common multipart type. A default-constructed R-WMimeMultipartType object represents a multipart/mixed header value.
The value of a multipart/related Content-Type contains a boundary parameter, a required type parameter and two optional parameters, start and start-info. The type parameter matches the Content-Type of the part to be processed first. By default, an application begins processing a multipart/related body at the first contained part. If the start parameter is present, an application begins processing a multipart/related body at the part that contains a Content-ID value matching the value of the start parameter. If the start-info parameter is present, the value of the parameter provides information for the processing application. The MIME package provides class RWMimeMultipartRelatedType for convenience in working with the additional parameters in a multipart/related content type.