Tnef Property Structure
A MAPI property read from a TNEF stream.
Definition
Namespace: MimeKit.Tnef
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public readonly struct TnefPropertyRemarks
A TnefProperty is an immutable snapshot of a MAPI property and all of its values. Unlike the values exposed by a TnefPropertyReader, its values may be read any number of times and in any order, and remain valid after the TnefReader has been advanced or disposed.
Properties are read using ReadProperty(CancellationToken) or, as a group, using ReadPropertySet(CancellationToken).
Binary values are held in memory as byte arrays. To read large values (such as attachment data) without buffering them, use OpenValueStream 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);
}
}
}
Properties
| Count | Get the number of values. |
| IsMultiValued | Get whether the property is multi-valued. |
| Name | Get the name of the property. |
| PropertyType | Get the type of the property's values. |
| Tag | Get the property tag. |
| Value | Get the value of the property. |
Methods
| Equals | Indicates whether this instance and a specified object are equal. (Inherited from ValueType) |
| GetHashCode | Returns the hash code for this instance. (Inherited from ValueType) |
| GetType | Gets the Type of the current instance. (Inherited from Object) |
| ToString |
Return a string that represents the property.
(Overrides ValueTypeToString) |
| TryGetBoolean | Try to get the value as a boolean. |
| TryGetBytes | Try to get the value as a byte array. |
| TryGetDateTime | Try to get the value as a date and time. |
| TryGetDouble | Try to get the value as a double. |
| TryGetFloat | Try to get the value as a float. |
| TryGetGuid | Try to get the value as a GUID. |
| TryGetInt16 | Try to get the value as a 16-bit integer. |
| TryGetInt32 | Try to get the value as a 32-bit integer. |
| TryGetInt64 | Try to get the value as a 64-bit integer. |
| TryGetString | Try to get the value as a string. |
| TryGetValuesT | Get the values of a multi-valued property. |