Platform SDK: CDO for Windows 2000

BodyPart Content Streams

Each object contains a content stream that can be requested using IBodyPart.GetDecodedContentStream and IBodyPart.GetEncodedContentStream. The encoding mechanism used is defined by the urn:schemas:mailheader:content-transfer-encoding property in the Fields collection. This corresponds to the Content-Transfer-Encoding mail header field defined by the MIME specification.

A body part containing the message in HTML format, for example, within a multipart/alternative hierarchy, could have the following encoded or decoded (decoded in this case) content stream:

<html><p>Here is a simple <b>message</b>.

A body part containing a binary attachment or file, such as an image or word file, contains radically different streams for the encoded and decoded content stream. In the first case, the binary stream is encoded using a mechanism such as the base64 encoding mechanism and is returned as US-ASCII text. In the second, a raw binary stream is returned. Note that the ADO Stream object has a Type property (_Stream.Type) that indicates whether the content is binary or text. For text streams, the character set is identified using the _Stream.Charset property.

The content is returned in an ADO Stream object that exposes an ADO _Stream interface. You can use this object to populate, manipulate, or examine the contents of the body part. Changes made to the stream can be committed back to the body part using the _Stream.Flush method. In a sense, the Stream object is bound to the body part as if the body part is its storage location. In most cases, you will use the decoded content stream to manipulate the content. For binary content, the default is the base64 encoding mechanism.

In the CDO object model, body parts that have their content type set to multipart do not have an associated content stream. These parts exist solely to create a hierarchy and relationships between child body parts. Requesting their content streams raises an exception. You can request the stream but not the content stream for these objects.

See Also

IBodyPart.GetDecodedContentStream Method

IBodyPart.GetEncodedContentStream Method