TnefPartLoadTnefMessage Method

Load the TNEF message contained within the part.

Definition

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

Parameters

options  TnefOptions  (Optional)
The options to use, or to use the default options.
cancellationToken  CancellationToken  (Optional)
The cancellation token.

Return Value

TnefMessage
The TNEF message.

Implements

ITnefPartLoadTnefMessage(TnefOptions, CancellationToken)

Remarks

Decodes the content of the part and loads the TNEF message that it contains.

If options is and the Content-Type of the part has a charset parameter, the codepage of that charset is used as the DefaultCodepage.

The returned message is independent of the part and must be disposed by the caller. Use ConvertToMime(TnefConversionOptions, CancellationToken) to convert it to a MimeMessage.

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 TnefPart has been disposed.
InvalidOperationException The part does not have any content.
TnefException The content does not begin with the TNEF signature.
OperationCanceledException The operation was canceled via the cancellation token.
IOException An I/O error occurred.

See Also