As part of maintaining Fetch I have to install the php imap extension quite a bit. Although this is pretty trivial on most variants of linux it's kind of a pain for OSX- you have to find a few dependancies, compile the imap c library from source, create the extension against your currently installed version of php (which typically won't include it's source on the system), and then take that one resulting file and set it up.
After doing this for the millionth time I decided to script it, and like any good programmer I looked to see what was already out there. I found a script by Ivan Vucica for an older version of OSX and then polished it up. My version should work on more than just OSX, although in most cases you'll want to use the system package manager in that case anyways.
I've posted the code and a Readme on Github, and have thrown together a first release. Please let me know if you find it useful!