Domanda

I used OpenPop.NET for parsing Email (MIME) messages, stored in a database.

Most of the messages are being parsed well, but in some of them the message body isn't getting parsed.

I get the body as a multi-part formatted text, like this:

This is a multi-part message in MIME format.

------=_NextPart_000_0027_01C98F52.9826A710
Content-Type: text/plain;
    charset="windows-1255"
Content-Transfer-Encoding: base64

8eHh5CwNCg0K4PDpIPHl7uv6IPLs6eog+fr08unsIOD6IPfx7unqLi4uLi4uLi4uDQoNCiANCg0K
8OX46fog4e8g5Pjl+Q0KDQrg6e709+gg7vL46+X6IPrl6/DkDQoNCiANCg0KICBfX19fXyAgDQoN
CkZyb206IFlvc2kgTGV2eSBbbWFpbHRvOnlfbGV2eUByYW1iYW0uaGVhbHRoLmdvdi5pbF0gDQpT
...
...

I noticed that in those messages the header does not define the message as "Content-Type: multipart/mixed;". When I save the entire message and try to open it in Thunderbird, for example, the message body is the multi-part message, not parsed.

I wish to parse the multi-parted message body alone, not as a part of an Email message. How can I do that? I use .NET 3.5 (even though I'll adopt .NET 4 solution as well).

Thank you!

This is a problematic sample file.

È stato utile?

Soluzione

There aren't any MIME parsers that will handle this particular type of brokenness out of the box. What you could do is search for a line beginning with "--", then read the rest of that line (trimming off the first 2 dashes) to use as a boundary string.

Then, once you've got that, prepend:

string.Format ("Content-Type: multipart/mixed; boundary=\"{0}\"\r\n", boundary);

Then try parsing it again.

BTW, if you are parsing a lot of messages, I'd recommend looking at MimeKit as it is 25x faster than OpenPOP's parser and also a lot more RFC-compliant.

Hope that helps.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top