TnefFile Class
Reads and writes TNEF streams ([MS-OXTNEF]): the winmail.dat attachments (application/ms-tnef) Outlook and Exchange send with a message. The item of a stream is read with the types of the items of Outlook data files: a MapiMessage, or a MapiContact, MapiAppointment, MapiTask or MapiDistributionList.
public static class TnefFileExample
var message = TnefFile.Load(path);
// The class of the old versions of Microsoft Mail (IPM.Microsoft Mail.Note) is read as its MAPI class
Assert.Equal("IPM.Note", message.MessageClass);
foreach (var attachment in message.Attachments)
{
File.WriteAllBytes(Path.Combine(directory.FullName, Path.GetFileName(attachment.Name ?? "attachment")), attachment.GetContent());
}Methods
| Name | Description |
|---|---|
| HasSignature(ReadOnlySpan<byte>) | Gets whether data starts with the signature of a TNEF stream. |
| Load(Stream, PstReadOptions?) | Reads the item of a TNEF stream, until its end. |
| Load(ReadOnlySpan<byte>, PstReadOptions?) | Reads the item of a TNEF stream. |
| Load(string, PstReadOptions?) | Reads the item of a TNEF file, such as a winmail.dat file. |
| Save(MapiMessageBuilder, Stream) | Writes an item as a TNEF stream, with Unicode strings. |
| Save(MapiMessageBuilder, string) | Writes an item as a TNEF file, such as a winmail.dat file. |
| ToByteArray(MapiMessageBuilder) | Returns the TNEF stream of an item. |
HasSignature(ReadOnlySpan<byte>)
TnefFile.csGets whether data starts with the signature of a TNEF stream.
public static bool HasSignature(ReadOnlySpan<byte> data)Load overloads
Load(Stream, PstReadOptions?)
TnefFile.csReads the item of a TNEF stream, until its end.
public static MapiMessage Load(Stream stream, PstReadOptions? options = null)Parameters
streamStream- The stream.
optionsPstReadOptions?- The options, or
nullfor the default options.
Returns
MapiMessage The item.
Exceptions
InvalidEmailDataException- The data is not a TNEF stream, or its structures are malformed.
EmailResourceLimitException- A property is larger than
PstReadOptions.MaxPropertySize.
Load(ReadOnlySpan<byte>, PstReadOptions?)
TnefFile.csReads the item of a TNEF stream.
public static MapiMessage Load(ReadOnlySpan<byte> data, PstReadOptions? options = null)Parameters
dataReadOnlySpan<byte>- The content of the stream.
optionsPstReadOptions?- The options, or
nullfor the default options.PstReadOptions.VerifyChecksumschecks the checksums of the attributes,PstReadOptions.MaxPropertySizelimits the size of a property, andPstReadOptions.MaxEmbeddedMessageDepththe depth of the embedded messages.
Returns
MapiMessage The item.
Exceptions
InvalidEmailDataException- The data is not a TNEF stream, or its structures are malformed.
EmailResourceLimitException- A property is larger than
PstReadOptions.MaxPropertySize.
Load(string, PstReadOptions?)
TnefFile.csReads the item of a TNEF file, such as a winmail.dat file.
public static MapiMessage Load(string path, PstReadOptions? options = null)Parameters
pathstring- The path of the file.
optionsPstReadOptions?- The options, or
nullfor the default options.
Returns
MapiMessage The item.
Exceptions
InvalidEmailDataException- The data is not a TNEF stream, or its structures are malformed.
EmailResourceLimitException- A property is larger than
PstReadOptions.MaxPropertySize.
Save overloads
Save(MapiMessageBuilder, Stream)
TnefFile.csWrites an item as a TNEF stream, with Unicode strings.
public static void Save(MapiMessageBuilder item, Stream stream)Parameters
itemMapiMessageBuilder- The item: a message, a contact, an appointment, a task or a distribution list.
streamStream- The stream.
Save(MapiMessageBuilder, string)
TnefFile.csWrites an item as a TNEF file, such as a winmail.dat file.
public static void Save(MapiMessageBuilder item, string path)Parameters
itemMapiMessageBuilder- The item.
pathstring- The path of the file.
ToByteArray(MapiMessageBuilder)
TnefFile.csReturns the TNEF stream of an item.
public static byte[] ToByteArray(MapiMessageBuilder item)