CFOpenMail / ImapCFC project page
Earlier this week, I decided it would be fun to build a webmail application. Of course, any good webmail application connects to an IMAP mail server, so I needed to figure out how to use imap in Coldfusion.
Although Bluedragon has a CFIMAP tag, Coldfusion (currently) does not. I wanted to go open source, and didn't want to require any DLL installations or anything so most of the custom tag options out there were not options (like CFX_IMAP, CFX_IMAP4, etc). But I did find a project on sourceforge called cfimap-cfc. Sweet.
I started cranking away, and I've made a LOT of changes to imap.cfc, enhancing its functionality, fixing bugs, etc. Some of the major changes so far:
- an authenticated imap session can be stored in memory (the session scope), so you don't have to authenticate every time you try to do something. This was a HUGE performance increase.
- the "view" method was incompatible with multipart mime messages with parts whose content type was multipart/*. In otherwise, a message might have two parts, but one of those parts might also have multiple parts as well. Curiously, the old imap.cfc worked with such messages but only grabbed the first subpart in such situations. This required taking part of the view() method out and putting it into a separate method called getParts(), which calls itself recursively for multipart parts.
- I've properly var scoped *EVERYTHING*. Version 1.0 of imap.cfc was not var scoped at all, and you could have easily experienced all kinds of variable problems.
- The old imap.cfc attempted to put HTML and text attachments inline. Personally, in a web based application, I'd just rather see them as attachments, and so that's what it does now.
- The download method was enhanced by adding an includeData argument, which, when false, causes the returned structure to not include the actual binary file contents. The method also now returns file size as well, so you can publish the list of attachments along with their content type and size.
- Added a slew of try/catch statements because some folders can't contain messages, so you can't open them. I don't really know why for sure, but I've got one such folder in my Sent folder, so I added error trapping.
- I also added code hints, changed some variable names and column names, and did some commenting of the code too.
It's worth mentioning that I've never worked with the JavaMail API before, so this was fun and challenging.
There's still a lot of work to do, particularly with regards to the send() feature. I also haven't yet tested the deleting, creating, or renaming of folders, nor have I tested the copyMessages() method either.