jstedfast / MimeKit

A .NET MIME creation and parser library with support for S/MIME, PGP, DKIM, TNEF and Unix mbox spools.
http://www.mimekit.net
MIT License
1.82k stars 369 forks source link

TNEF encoding / winmail.dat #50

Closed princeoffoods closed 10 years ago

princeoffoods commented 10 years ago

Hello Jeff,

Is there any chance that support for decoding TNEF encoded messages will be added in the future or is this completely out of the scope of MimeKit?

jstedfast commented 10 years ago

I hadn't originally planned on implementing support for it, but you are the second person who has asked about it... perhaps I need to reconsider.

Let me do some research into this to figure out what it would involve...

In either case, it's probably worth keeping this open so other people can perhaps chime in.

princeoffoods commented 10 years ago

It seems like the damn TNEF just won't go away. Thank you for looking into this.

jstedfast commented 10 years ago

Looks like the spec can be found here: http://msdn.microsoft.com/en-us/library/cc425498%28v=exchg.80%29.aspx

jstedfast commented 10 years ago

I'm going to need some sample tnef files that I can use to make sure my code works and also, if possible, to include in the unit tests

princeoffoods commented 10 years ago

It's great how quickly you are implementing this! Can't publish customer emails, but I'll be happy to test all emails in our database.

I found tnef samples on the web, which can hopefully help to get testing started: http://sourceforge.net/p/tnef/git/ci/master/tree/tests/files/datafiles/

jstedfast commented 10 years ago

It's not quite ready for testing, but hopefully it will be soon. Thanks for the link to some test files.

jstedfast commented 10 years ago

What kind of info are you hoping to get out of the TNEF files, btw? I'm told modern clients don't put much of anything but some MAPI properties in them anymore?

princeoffoods commented 10 years ago

I just need to access the attachments contained in tnef files just like all other attachments.

When a potential new customer wants a quick quotation and sends specifications or drawings contained inside a tnef file it's not an option to lecture them on configuring vintage outlook clients or exchange servers :)

jstedfast commented 10 years ago

Getting close to having this working... hopefully you don't need to extract compressed rtf attachments? or if you do, is it enough to extract the compressed blob rather than decompressing them?

jstedfast commented 10 years ago

Got all of the unit tests passing except for 1 which is a TNEF stream embedded in a TNEF stream.

jstedfast commented 10 years ago

Give the new MimeKit.Tnef.TnefPart API a try...

You probably want MimeKit.Tnef.TnefPart.ExtractAttachments()

princeoffoods commented 10 years ago

Thank you very much for the updates!

I'm getting an exception when calling .ConvertToMessage() or .ExtractAttachments(). Looking into it...

System.NotSupportedException occurred HResult=-2146233067 Message=The stream does not support seeking Source=MimeKit StackTrace: at MimeKit.IO.FilteredStream.get_Position() at MimeKit.Tnef.TnefReader.ReadAhead(Int32 atleast) at MimeKit.Tnef.TnefReader.ReadInt32() at MimeKit.Tnef.TnefReader.DecodeHeader() at MimeKit.Tnef.TnefReader..ctor(Stream inputStream, Int32 defaultMessageCodepage, TnefComplianceMode complianceMode) at MimeKit.Tnef.TnefReader..ctor(Stream inputStream) at MimeKit.Tnef.TnefPart.ConvertToMessage()...

jstedfast commented 10 years ago

This should be fixed now

princeoffoods commented 10 years ago

Great. But I got another one :)

TnefPart.BodyParts contains too many items.

For example the one rtf is included twice and the single attachment of the message is included 7 times.

jstedfast commented 10 years ago

ok, try now

princeoffoods commented 10 years ago

Works great.

So far I tested about 50 emails with tnef encoded attachments and I'm happy to report MimeKit handled them all without any problems.

Jeff, I just want to thank you again for providing TNEF support. It's very well integrated and easy to use.

jstedfast commented 10 years ago

no prob, glad to hear it works!