Simple C++ Mime Parser

Parsing simple MIME files from C/C++?

It's been a while. So I'll just answer my own question.

After spending some more time on this, I ended up writing my own implementation. MIME is quite simple indeed, and if you read the documentation, you have something up and running in a short time.

However, I think there should be something like vMime, but open source. I can't believe that so few people have to deal with MIME structures as it's a real standard.

Are there .NET Framework methods to parse an email (MIME)?

I know you said no external libraries, but I have a library posted on codeplex:

https://bitbucket.org/otac0n/mailutilities

MimeMessage msg = new MimeMessage(/* string, stream, or Byte[] */);

It has been tested with over 40,000 real-world mail messages.

I'm not too happy with my namespace choice, but... I'm too lazy to change it.


PS:

Internally, my library uses these regexes as a parser:

internal static string FullMessageMatch =
@"\A(?<header>(?:[^\r\n]+\r\n)*)(?<header_term>\r\n)(?<body>.*)\z";
internal static string HeadersMatch =
@"^(?<header_key>[-A-Za-z0-9]+)(?<seperator>:[ \t]*)(?<header_value>([^\r\n]|\r\n[ \t]+)*)(?<terminator>\r\n)";
internal static string HeaderSeperator =
"\r\n";
internal static string KeyValueSeparator =
@"\A:[ \t]*\z";


Related Topics



Leave a reply



Submit