TnefPropertyWriterOpenEmbeddedMessage(Int32) Method

Open a writer for an embedded message.

Definition

Namespace: MimeKit.Tnef
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public TnefWriter OpenEmbeddedMessage(
	int codepage
)

Parameters

codepage  Int32
The codepage that the embedded message writer uses to encode 8-bit strings.

Return Value

TnefWriter
The embedded message writer.

Remarks

Opens a TnefWriter for writing an embedded message as the value of an Object property, such as AttachData. The value begins with the IID_IMessage interface identifier, which is written automatically.

The embedded message inherits the TemporaryStreamFactory of the TnefWriter that this property writer belongs to.

The value is completed when the embedded message writer is disposed. No other value or property may be written until then.

Example

C#
                    public static void WriteEmbeddedMessage (TnefWriter writer, TnefMessage message)
{
    var renderData = new byte[] { 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

    writer.WriteAttribute (TnefAttributeTag.AttachRenderData, renderData);

    using (var properties = writer.OpenPropertyWriter (TnefAttributeTag.Attachment)) {
        properties.WritePropertyTag (TnefPropertyTag.AttachMethod);
        properties.WriteValue ((int) TnefAttachMethod.EmbeddedMessage);

        // An embedded message is the value of a PidTagAttachDataObject property.
        properties.WritePropertyTag (TnefPropertyTag.AttachDataObj);

        using (var embedded = properties.OpenEmbeddedMessage ()) {
            if (message.MessageClass != null)
                embedded.WriteAttribute (TnefAttributeTag.MessageClass, message.MessageClass);

            // Copy the properties of an existing TnefMessage unchanged.
            using (var embeddedProperties = embedded.OpenPropertyWriter (TnefAttributeTag.MapiProperties)) {
                foreach (var property in message.Properties)
                    embeddedProperties.WriteProperty (property);
            }
        }
    }
}
                  

Exceptions

ArgumentOutOfRangeException codepage is not a supported codepage, or is a codepage that encodes characters using zero bytes.
ObjectDisposedException The property writer has been disposed.
InvalidOperationException

The current property is not an Object property.

-or-

The current property already has a value.

-or-

The stream or writer for the previous value has not been disposed.

See Also