Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to handle email parsing/decoding in PHP?

Currently I'm using the PEAR library's mimeDecode.php for parsing incoming emails. It seems to have a lot of issues and fails to decode a lot of messages, so I'd like to replace it with something better.

I'm looking for something that is able to properly separate parts of the message, such as to, from, body, etc. Ideally it would be able to handle all common encoding methods such as base64, uuencode, quoted printable, etc.

In situations where both plain text and html versions of the same message are contained in a single email, I would ideally like it to know the difference between them so I could choose which part I wished to display.

I'm not worried about attachments at this point in time, but it would be nice for it to have knowledge of them in case I want to implement that in the future.

I saw PHP has a group of functions that start with the word imap that appear they may do what I would like, but I am unsure without trying them out.

Currently I am doing on-the-fly decoding of the messages in PHP, which is why I am looking for a PHP replacement solution.

Does anyone have an experience with this that could point me in the right direction? I'd hate to start using something that would end up not doing what I need in the long run.

like image 476
Sgraffite Avatar asked Jan 18 '11 07:01

Sgraffite


1 Answers

I have recently developed a PHP mail parser and I have been using it on production.
I have very happy with it and some developers has forked it:

https://github.com/plancake/official-library-php-email-parser

like image 88
Dan Avatar answered Sep 28 '22 02:09

Dan