Parsing simple MIME files with C / C ++?

I searched the web for several days, but I cannot find a good solution to my problem:

For one of my projects, I am looking for a good (light) MIME parser. My client provides files in MIME format (linear, without hierarchy), which contain 3-4 "parts". The application should be able to separate these parts and process them independently.

Basically, these MIME files are similar to raw emails, but without SMTP headers. Instead, they begin with the MIME header "MIME-Version: 1.0", followed by the details.

I use C ++ for the application, so you can use the C ++ library. The C standard library is also welcome; but it must meet the following criteria:

  • Be open (at least LGPL), not true.
  • Compact - I just need a parser, SMTP / POP3 support
  • Cross-platform (oriented to Windows, Mac OS X and Linux)

After several days of searching, I found the following libraries and the reasons why they should not be used:

  • mimetic (C ++) --- Although this library seems complete for use in C ++, it is based on glib, which will not compile correctly on Windows.
  • Vmime (C ++) --- It seems that there is no official support for Windows. They also provide “dual licensing” (“commercial LGPL” + GPL). It seems to be included in Ubuntu and Debian, but licensing is confusing.
  • mime ++ --- Commerical, no Mac support.
  • Chilkat Software MIME C ++ Library --- Commerical and is Windows-oriented.

I do not want to write my own MIME parser. MIME is so widespread that there must be some kind of open library for the proper handling of this file format.

So, do you have any ideas, suggestions or links?

Thanks in advance!

+6
c ++ parsing mime
source share
5 answers

Some time has passed. Therefore, I will simply answer my question.

After spending some more time on this, I ended up writing my own implementation. MIME is pretty simple, and if you read the documentation, you have something up and 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 this is the real standard.

+4
source share

GMime is an LGML mime parser written in C. It depends on glib, but glib is available on Windows: 32bit and 64bit (and all Unix-based platforms, including Mac OS X). It also creates inside visual studio afaict, so I don't see what the problem is. I know that at least one commercial Windows vendor sends libgmime.dll and libglib.dll to its product (Kerio Connect, iirc). Nokia even sends it to some of its phones.

Actually there is no such thing as a "light" Mime steam pair if you really expect it to do more than split the headers into ":" and does a random analysis of the Content-Type header to find the boundary line a then continue to process non-nested multisets (sort of useless outside of parsing HTTP responses and pre-configured mime messages that you control composition).

The reason parsers such as GMime are as large as the lines of code fit is because they are for developers who really want the correct and reliable processing and decoding of mime-part and headers. Look at my story about decoding rfc2047 tokens with a coded word for the idea of ​​how difficult it is to get (by the way, besides GMime and MimeKit, I still have to find open source mime parsers that can handle all the boundary cases discussed in my application).

Even with all this additional robust processing, it is still as fast or faster than most lightweight mime parsers, probably given that most of them use the readline approach. I saw that the “light” guys guys prefer to parse 25MB email files in 2-3 seconds and think it's “fast”. My unit tests for GMime parse 2 mbox files filled with messages larger than 1.2 GB (yes, gigabytes) in less time.

My point is that “light weight” is the criterion for crap by people who don’t know what they are talking about.

How about a judgment based on something meaningful, such as rfc compliance? Or a combination of rfc compliance and performance? In any case, GMime will be the winner in any meaningful comparison that you make.

+6
source share

I have successfully used mimetic with my MSVC2010. He also works on windows. And has a MIT license.

+3
source share

I also created a mime library (windows only) with s / mime support. But if you do not want to use S / Mime, you can remove the special Windows features.

http://www.codeproject.com/Articles/1114232/Cplusplus-MIME-A-simple-single-header-parser-an

0
source share

I would suggest mimecpp , a CIM MIME implementation.

It is very small, well encapsulated and easy to use. In fact, the source code contains only 7 files.

0
source share

All Articles