Tnef Property ReaderOpen Embedded Message Method
Definition
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
public TnefReader OpenEmbeddedMessage()Return Value
TnefReaderThe embedded message reader.
Remarks
Opens a TnefReader for the embedded TNEF message contained within the current value (see IsEmbeddedMessage).
The returned reader has a Depth one greater than the reader that created it, and uses the same options and compliance logger. Its StreamOffset values are relative to the start of the outermost TNEF stream.
If the embedded message is nested more deeply than MaxNestingDepth allows, a NestingTooDeep issue is reported and the returned reader does not return any attributes.
The embedded reader is only valid until this reader is advanced to another value. Disposing it does not affect this reader.
Example
public static void DumpTnef (Stream stream)
{
using (var reader = new TnefReader (stream, null, leaveOpen: true))
DumpAttributes (reader);
}
static void DumpAttributes (TnefReader reader)
{
var indent = new string (' ', reader.Depth * 4);
while (reader.Read ()) {
Console.WriteLine ("{0}{1} {2} ({3} bytes) @ offset {4}", indent, reader.Level, reader.Tag, reader.Length, reader.StreamOffset);
switch (reader.Tag) {
case TnefAttributeTag.MessageClass:
case TnefAttributeTag.Subject:
Console.WriteLine ("{0} {1}", indent, reader.ReadValueAsString ());
break;
case TnefAttributeTag.DateSent:
case TnefAttributeTag.DateReceived:
Console.WriteLine ("{0} {1}", indent, reader.ReadValueAsDateTime ());
break;
case TnefAttributeTag.RecipientTable:
var recipients = reader.GetPropertyReader ();
// The recipient table is a list of rows, each of which has its own list of properties.
while (recipients.ReadNextRow ()) {
Console.WriteLine ("{0} Recipient:", indent);
DumpProperties (recipients, indent + " ");
}
break;
case TnefAttributeTag.MapiProperties:
case TnefAttributeTag.Attachment:
DumpProperties (reader.GetPropertyReader (), indent + " ");
break;
}
// Note: There is no need to read the value of every attribute; any value that is
// not read is skipped (and its checksum is still verified) by the next Read ().
}
}
static void DumpProperties (TnefPropertyReader prop, string indent)
{
while (prop.ReadNextProperty ()) {
var name = prop.Name.HasValue ? prop.Name.Value.ToString () : prop.Tag.Id.ToString ();
if (prop.IsEmbeddedMessage) {
Console.WriteLine ("{0}{1} = <embedded message>", indent, name);
using (var embedded = prop.OpenEmbeddedMessage ())
DumpAttributes (embedded);
continue;
}
if (prop.ValueCount == 0) {
Console.WriteLine ("{0}{1} = <no values>", indent, name);
continue;
}
// Note: The reader is already positioned on the first value of the property.
do {
var value = prop.ReadValue ();
if (value is byte[] bytes)
Console.WriteLine ("{0}{1} = <{2} bytes>", indent, name, bytes.Length);
else
Console.WriteLine ("{0}{1} = {2}", indent, name, value);
} while (prop.ReadNextValue ());
}
}
Exceptions
| ObjectDisposedException | The TnefReader has been disposed. |
| InvalidOperationException |
The TnefReader has been advanced to another attribute. -or- The reader is not positioned on a value. -or- The value is not an embedded message. -or- The value has already been read. |