Post By Email Update: Horde library!
After much wailing and gnashing of teeth, I was finally able to get the Post By Email plugin working against the Horde IMAP Client Library.
It’s a bit of a hack right now — I still need to clean up the code and pull a lot of it out into helper functions — but with this in place, I’ve laid the groundwork for supporting SSL and IMAP connections (without requiring PHP to be compiled with IMAP support).
A couple of technical oddities…
- The Horde framework is massive, and while the IMAP library is available as a standalone PEAR package, it still has a ton of dependencies to the rest of Horde. I solved the problem in a quick-and-dirty way by copying any missing files into the plugin’s includes directory. Horde uses an autoloader to include the classes it needs; I’m planning to experiment with that, but for now I just wrote a wrapper (so I only have to include one file in the plugin class). (Does anyone know whether autoloading plays nicely with WP?)
- Instead of copying over the translation classes, I stubbed out one of them in a “bogus” way that uses WP’s translation functions instead. Might poke around and see whether I can do this with any of the others, as well.
The good news is that, once I got this working, I was able to scrap the whole preexisting deal with reading each message line by line and processing it with (buggy) regexes… and move to letting Horde abstract parsing out headers, decoding MIME, etc. This will also make it much easier to deal with HTML emails, attachments, and so on in the future.
For now it still supports only POP3, but unlike the previous iteration, it doesn’t lose all the text and create blank posts — certainly an improvement. :)
Next steps: Refactor check_email into helper functions and add support for IMAP, then SSL connections.