Processing IMAP email in PHP

戏子无情 提交于 2020-01-01 19:30:14

问题


I need to process an email inbox, monitor it for messages with a particular subject line. If it finds a match I need to get the body content, manipulate, and insert into a database. Ideally would mark the message as read and move it to another IMAP folder as well.

I'm poking around PHP documentation imap_open (http://us2.php.net/imap_open) and found a link http://www.linuxscope.net/articles/mailAttachmentsPHP.html#_jmp0_

Before I get too far, I'm wondering if anyone is aware of an existing PHP class that's a good wrapper for the basics I'm looking for:

IMAP:

  • connect
  • list folders
  • list messages
  • read messages - from, to, subject, body
  • move messages to server folders
  • read/unread status

Thank you!


回答1:


I've not used it for anything but sending mail, but it appears that the Zend_Mail component will get you at least most of the way there. It doesn't seem to support moving messages on the server, but you could probably extend it fairly simply.




回答2:


I've tried Zend_Mail for IMAP and have some highs and lows. I could connect and read, move emails but it is quite buggy. You can check for subject or sender, parse headers, reach attachment by parsing different parts.

Zend_Mail_Protocol_Imap is not using any of the PHP imap/ext function. (Why?) Reading folders with thousands of emails is slow. The internal order of a folder is not actually chronological, which is so strange. Probably depends on how the storage was implemented (I parsed a google.pro account). Sometimes the connection closes unexpectedly and debugging it is quite heavy.

There is also a Pear_IMAPv2, which is beta and I could not even succeed in installing. The alternative will be to install imap/ext and do everything by yourself.

Good luck.



来源:https://stackoverflow.com/questions/1603637/processing-imap-email-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!