Tnef MessageProperties Property
Get the message's MAPI properties.
Definition
Namespace: MimeKit.Tnef
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
The properties.
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public TnefPropertySet Properties { get; }Property Value
TnefPropertySetThe properties.
Remarks
Gets the message's MAPI properties, including the properties that were decoded from the legacy message attributes.
The message bodies (the Body, BodyHtml and RtfCompressed properties and the legacy Body attribute) are not included; use TextBody, HtmlBody and RtfBody instead.
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);
}
}
}