Tnef Property Set Class
A set of MAPI properties 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 sealed class TnefPropertySet : IReadOnlyList<TnefProperty>,
IEnumerable<TnefProperty>, IEnumerable, IReadOnlyCollection<TnefProperty>- Inheritance
- Object TnefPropertySet
Remarks
A TnefPropertySet is an immutable snapshot of the MAPI properties contained within a MapiProperties or Attachment attribute, or within a single row of a RecipientTable attribute.
Property sets are read using ReadPropertySet(CancellationToken) and ReadRowsAsPropertySets(CancellationToken).
The properties are kept in the order in which they appeared in the TNEF stream.
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
Methods
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| GetBoolean | Get the value of the specified property as a boolean. |
| GetBytes | Get the value of the specified property as a byte array. |
| GetDateTime | Get the value of the specified property as a date and time. |
| GetEnumerator | Get an enumerator for the properties. |
| GetGuid | Get the value of the specified property as a GUID. |
| GetHashCode | Serves as the default hash function. (Inherited from Object) |
| GetInt32 | Get the value of the specified property as a 32-bit integer. |
| GetInt64 | Get the value of the specified property as a 64-bit integer. |
| GetString | Get the value of the specified property as a string. |
| GetType | Gets the Type of the current instance. (Inherited from Object) |
| ToString | Returns a string that represents the current object. (Inherited from Object) |
| TryGetValue(TnefNameId, TnefProperty) | Try to get the named property with the specified name. |
| TryGetValue(TnefPropertyTag, TnefProperty) | Try to get the property with the specified tag. |