TnefMessageConvertToMime Method

Convert the message to MIME.

Definition

Namespace: MimeKit.Tnef
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public TnefConversionResult ConvertToMime(
	TnefConversionOptions? options = null,
	CancellationToken cancellationToken = default
)

Parameters

options  TnefConversionOptions  (Optional)
The conversion options, or to use Default.
cancellationToken  CancellationToken  (Optional)
The cancellation token.

Return Value

TnefConversionResult
The result of the conversion.

Remarks

Converts the TNEF message to a MimeMessage.

If the message has a MimeSkeleton property, the MIME structure and headers are taken from the skeleton and its empty parts are filled in with the message's bodies and attachments. If the skeleton cannot be parsed or does not match the message's bodies and attachments, it is discarded and a InvalidMimeSkeleton loss is reported.

Otherwise, the MIME message is built from the message's properties:

  • The Received headers are taken from the TransportMessageHeaders, followed by the headers that correspond to the message's properties (such as From, Date, Subject, Message-Id, To and Cc), and then the headers stored in the InternetHeaders named properties. No header is generated that does not correspond to a property.
  • The plain text and HTML bodies become a multipart/alternative, in that order, if there is more than one. When the best body ([MS-OXBBODY]) is the compressed RTF body, both are generated from the RTF using RtfToText and RtfToHtml, as recommended by [MS-OXCMAIL] 2.1.3.3.5. The RTF itself is never added as a text/rtf part.
  • If the message is a calendar item or a meeting message and GenerateCalendar is enabled, an iCalendar text/calendar part is generated from its properties and added as the last alternative of the body. The embedded messages that hold the exceptions to a recurring appointment become part of the calendar rather than attachments.
  • The attachments follow the body within a multipart/mixed.

The information that could not be represented in MIME is listed in Losses.

The converted message is independent of the TnefMessage, which may be disposed afterwards.

Example

C#
                    public static MimeMessage ConvertToMime (TnefPart part)
{
    // Load the content of the application/ms-tnef (winmail.dat) part.
    using (var tnef = part.LoadTnefMessage ()) {
        // By default, embedded messages are converted into nested TnefParts. Set ConvertEmbeddedMessages
        // to convert them into message/rfc822 MessageParts instead.
        var options = new TnefConversionOptions { ConvertEmbeddedMessages = true };

        // Convert the TNEF message into a MimeMessage. The converted message does not depend on the
        // TnefMessage, so it may still be used after the TnefMessage has been disposed.
        var result = tnef.ConvertToMime (options);

        // Anything that could not be represented in MIME is reported as a conversion loss.
        foreach (var loss in result.Losses)
            Console.WriteLine ("TNEF conversion loss: {0}: {1}", loss.Kind, loss.Description);

        // Note: Disposing the result would also dispose result.Message, so don't dispose it
        // if you want to keep using the message.
        return result.Message;
    }
}
                  

Exceptions

ObjectDisposedException The TnefMessage has been disposed.
OperationCanceledException The operation was canceled via the cancellation token.

See Also