TNEF embedded message format

884 views Asked by At

In my scenario I need to read MAPI properties of exchange message to get information about attachments like name, size, etc. For embedded messages I need to get more information.

So my question is how to read embedded message info?

Can anyone give me link to an article or specification documentation about how to read embedded message of an message on Exchange server. I use following classes:

  • Microsoft.Exchange.Data.ContentTypes.Tnef.TnefReader
  • Microsoft.Exchange.Data.Transport.Email.EmailMessage

Here is simplified code:

EmailMessage email;
MemoryStream mStream = new MemoryStream(File.ReadAllBytes(@"filename"));

byte[] buffer;
email = EmailMessage.Create(mStream);
using (TnefReader reader = new TnefReader(email.TnefPart.GetContentReadStream()))
{
    //loop through all properties
    while (reader.ReadNextAttribute())
    {
        if (reader.AttributeTag == TnefAttributeTag.Attachment)
        {
            bool IsEmbeddedMessage = false;
            while (reader.PropertyReader.ReadNextProperty())
            {

                switch (reader.PropertyReader.PropertyTag.Id)
                {

                    case TnefPropertyId.AttachMethod:
                        IsEmbeddedMessage = reader.PropertyReader.ReadValueAsInt64() == 5;
                        break;
                    case TnefPropertyId.AttachData:
                        if (IsEmbeddedMessage)
                        {
                            // here i read embedded message content,
                            // but do not know how to read its TNEF properties
                            buffer = new byte[reader.PropertyReader.RawValueLength];
                            reader.PropertyReader.ReadRawValue(buffer, 0, 
                                reader.PropertyReader.RawValueLength);
                        }
                        break;
                    // ....
                }
            }
        }
    }
}

I know that i can use following code to get some information about embedded message:

email.Attachments[0].EmbeddedMessage

but i need to use approach similar to the code above in order to get all possible properties.

1

There are 1 answers

0
jstedfast On

Presumably you need to do something like this after you've read the data:

using (var ereader = new TnefReader (new MemoryStream (buffer, false))) {
    // now start all over again and read the properties...
}