TnefMessage Class

A TNEF message.

Definition

Namespace: MimeKit.Tnef
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public sealed class TnefMessage : IDisposable
Inheritance
Object    TnefMessage
Implements
IDisposable

Remarks

A TnefMessage is an in-memory representation of a TNEF stream, as specified by [MS-OXTNEF]: the message's MAPI properties, its recipients, its bodies and its attachments.

The legacy TNEF attributes (such as Subject and From) are decoded into the MAPI properties that they correspond to, as specified by [MS-OXTNEF] section 2.1.3.4. When a TNEF stream contains both a legacy attribute and the corresponding MAPI property, the MAPI property takes precedence.

The bodies and attachment content are buffered in memory, subject to the limits specified by TnefOptions. A TnefMessage should be disposed once it is no longer needed.

Malformed TNEF streams are read on a best-effort basis. The problems that were encountered are reported to the ComplianceLogger, if any.

Example

C#
                    public static void PrintMessageProperties (string fileName)
{
    using (var stream = File.OpenRead (fileName))
    using (var tnef = TnefMessage.Load (stream)) {
        // The most commonly used properties have convenience accessors.
        Console.WriteLine ("Message-Class: {0}", tnef.MessageClass);
        Console.WriteLine ("Subject: {0}", tnef.Subject);
        Console.WriteLine ("Message-Id: {0}", tnef.InternetMessageId);

        // Any other property may be looked up by its tag. Note that a string lookup matches both the
        // String8 and the Unicode variant of the property tag.
        var sender = tnef.Properties.GetString (TnefPropertyTag.SenderEmailAddressW);
        var submitted = tnef.Properties.GetDateTime (TnefPropertyTag.ClientSubmitTime);
        var importance = tnef.Properties.GetInt32 (TnefPropertyTag.Importance);

        Console.WriteLine ("Sender: {0}", sender);
        Console.WriteLine ("Submitted: {0} (UTC)", submitted);
        Console.WriteLine ("Importance: {0}", importance);

        // Named properties are looked up by their TnefNameId.
        if (tnef.Properties.TryGetValue (TnefNameId.Location, out var location) && location.TryGetString (out var where))
            Console.WriteLine ("Location: {0}", where);

        // Multi-valued properties have more than one value.
        if (tnef.Properties.TryGetValue (TnefNameId.Keywords, out var keywords) && keywords.TryGetValues<string> (out var categories))
            Console.WriteLine ("Categories: {0}", string.Join (", ", categories));

        // Or simply enumerate every property.
        foreach (var property in tnef.Properties) {
            var name = property.Name.HasValue ? property.Name.Value.ToString () : property.Tag.Id.ToString ();
            var value = property.Value;

            if (value is byte[] bytes)
                value = string.Format ("<{0} bytes>", bytes.Length);
            else if (value is Array array)
                value = string.Join (", ", array.Cast<object> ());

            Console.WriteLine ("{0} ({1}) = {2}", name, property.PropertyType, value);
        }
    }
}
                  

Properties

Attachments Get the attachments of the message.
Codepage Get the codepage of the message.
HtmlBody Get the HTML body of the message.
InternetMessageId Get the Internet message identifier of the message.
LegacyKey Get the legacy key from the TNEF stream header.
MessageClass Get the message class.
Properties Get the message's MAPI properties.
Recipients Get the recipients of the message.
RtfBody Get the compressed RTF body of the message.
Subject Get the subject of the message.
TextBody Get the plain text body of the message.

Methods

ConvertToMime Convert the message to MIME.
Dispose Release all resources used by the TnefMessage object.
Equals Determines whether the specified object is equal to the current object.
(Inherited from Object)
GetHashCode Serves as the default hash function.
(Inherited from Object)
GetType Gets the Type of the current instance.
(Inherited from Object)
Load(TnefReader, CancellationToken) Load a TNEF message using the specified reader.
Load(Stream, TnefOptions, CancellationToken) Load a TNEF message from the specified stream.
LoadAsync(TnefReader, CancellationToken) Asynchronously load a TNEF message using the specified reader.
LoadAsync(Stream, TnefOptions, CancellationToken) Asynchronously load a TNEF message from the specified stream.
ToString Returns a string that represents the current object.
(Inherited from Object)

See Also