3

For a web application I need to read mails from an imap server with php.

So far i have used a very simple script and the php imap extension, but because i need a robust solution (i also tried pear imap packages, but it was not very reliable with different encodings), that supports more features like pgp encrypted emails, i have been thinking about using the horde framework/imap client instead.

I don't know if it's worth to install and use the (rather complex) horde framework just for the imap functions. Are there any alternatives or suggestions? what would be the advantages/disadvantages of using horde vs the php imap extension?

(The application is not supposed to provide any webinterface, i just need to parse mails and save contents/attachements to a database)

UPDATE I tried the Horde Imap Client, it's easy to install and use, but the performance seems a little bit slow compared to the php imap extension (on php5.3+eAccelerator). Login on imap server + fetch headers takes 8 seconds (login 4.5s + fetch headers 3.5s), compared to less than 4 seconds with php imap extension (login 3s + fetch headers 0.5s). I'm still trying to figure out wether i'm doing something wrong or this is just the normal difference between a native php library vs php imap extension.

Ruu
  • 33
  • 1
  • 4
  • What did you end up using? Horde or? I'm developing an app where I need to fetch emails from IMAP for several hundred users every minute so I'm looking for a PHP IMAP library thats optimized for performance. – eozzy Dec 01 '14 at 10:04

3 Answers3

2

You could use the Zend_Mail component from Zend Framework. I dunno if its more/less complex than Horde, but you can grab just that component and its dependencies you dont need all of ZF.

Reading messages with Zend_Mail

prodigitalson
  • 60,050
  • 10
  • 100
  • 114
2

You can install the Horde IMAP library without setting up the whole framework too:

$ pear channel-discover pear.horde.org
$ pear install horde/horde_imap_client
  • It works quite well, i'm just a little bit worried about the performance. Just connect to the imap server and fetch email headers takes almost 8s (php imap extension ~4s, i use php5.3+eAccelerator). is this difference normal (pure php, overhead of the framework etc.) or am i doing something wrong? – Ruu Jul 13 '11 at 05:39
  • I suggest you ask for support on the Horde developer mailing list. This should be much quicker. http://www.horde.org/community/mail – Jan Schneider Jul 13 '11 at 17:11
  • You should also consider installing Horde_Nls (for handling codepage/UTF-8 issues in encoded mime parts) and Horde_Cache (for significantly speeding up the connection to the server). – braindigitalis Mar 15 '18 at 16:10
1

The horde libraries do some basic housekeeping and queries when they log onto the mail server, the big one being "ENQUIRE INBOX", which can take a significant amount of time with a large folder.

The IMAP extension that comes with PHP does not do this. You can speed up these queries by installing and using Horde_Cache.

The IMAP extension that comes with PHP has many gotchas, for example it can struggle to log into exchange servers, gmail, etc. I have found from experience that it's worth learning and using the horde library to get around these problems, it should take you a couple of hours to produce something that works. When it comes to things like extracting mime attachments from an email body, i personally have found horde to be easier for this. your mileage may vary.

Hope this helps!

braindigitalis
  • 524
  • 7
  • 19