mail fetching and MIME e-mail handling

This week, I had a client who needed a webbased e-mail client as part of a bigger solution.

My first thought was to leverage an existing webmail client, but it turns out they are all licensed under GPL, and hence would not allow us to do the tight integration required for this proprietary software project.

I looked around for e-mail client libraries, but found nothing really complete or up to date.

So we started down the hard path of developing from scratch, using the IMAP extension for PHP, which turns out to be pretty handy, though not very well documented. And despite it’s name, it does not only IMAP, but also POP3, and supports SSL. Very nice.

About 10 hours into the actual work, I had a pair of classes that would connect to a POP3 or IMAP server, and let me list and iterate through the messages on the server. At which point, one of our Ruby/Rails developers came in and told us, hey, I can do that in a couple of hours - I was a bit baffled, but sure enough, with about three hours of work, he had not only e-mail fetching, but also a MIME parser up and a running.

With Rails, you simply write a handler for incoming e-mail, and it can decode MIME attachments for you and everything, so all you have to do is decide what you want to do with the content and implement that. Super easy.

I would have liked to stay in PHP for this project, but it appears that none of the PHP frameworks offer anything similar to this. Looking at various open-source webmail clients, they all seem to implement their own (extremely complex) MIME handling systems to cover all of the differences in e-mail from various exotic clients and servers.

This is kind of frustrating.

How come Ruby and Rails people get this functionality right out of the box, and the rest of us have to work like dogs to support mail fetching and MIME handling?

I would love to see Yii offering generic e-mail features. This sort of stuff should not need to be this complicated - it’s the kind of stuff you’d like to see implemented once, and done right, rather than trying to reinvent the wheel for every project.

I never got as far as to decode MIME attachments - the IMAP extension takes care of fetching attachments, but doesn’t seem to help with attachment decoding. From looking at various webmail client codebases, is extremely complicated, often some 5-10k lines of code, to handle every kind of message properly, including all the proprietary crap that comes out of Microsoft and Apple products.

I would be happy to do some cleanup and documentation of my e-mail fetching classes, if there’s any interest.

But I’m afraid that’s baby steps towards a framework with a full MIME message handling stack.

Love to hear any of your thoughts or ideas on this topic, as well as pointers if I missed some library out there?

Oohhh man !

It is nice to see that I am not the only one who crashes front-to-front with this problem. Right now I am dealing with the same situation that you already had, developing a email client and adding some other functions to integrate with other existing applications for a non-profit organization.

I didn’t find anything really useful nor understandable/easily maintainable open source email client with MIME capabilities for an IMAP server.

Did you finally build / found something nice to manage IMAP mail?

TIA.

They are GPL licensed for a reason: pay them for a commercial license if you need one.

Old topic but has anyone ever over come this problem?

Currently reading up on:

Ezcomponet, zend mail, eticket, osticket And flourish

Strange that ruby almost getsbthis out pf the box and php is left to fend for it’s own :(

Please note that PHP native imap function are based on old IMAP2 protocol, so for example, you can not search messaged by date and time(you can only by date), you can search by UID(for example get all messages that have UID higher then 1234). So consider those limitation carefully before you choose to use PHP imap functions.

Zend_Mail also have very limited options, you are even not able to use search options(in specifications there is notice that search function is only for internal use, so like this feature is not completed).

Last option is Horde_Imap, which is very complex library, without any tutorial how to use it.

lvica,

what a wonderful work you guys did with Zurmo. I cannot believe you did it. By the way do you have done a a library to give email notification of mails fetched from external server.

test