CFIMAP Rocks - And so does IMAP

April 05, 2005

BlueDragon's CFIMAP tag is awesome! I use IMAP for my email, and because of that I tend to store a lot of mail, especially old mailing list messages. I was telling our linux dude, Steve, that I wanted a way to remove messages in certain folders that are older than, say 30 days.

We are running XMS as our MTA (which also rocks! but doesn't support IMAP yet, but it is very powerful for filtering incoming mail! we have load balanced Virus Scanning, and Spam Assassin filters! anyways...), which forwards local mail to Cyrus IMAP. So my initial thought was to just run a unix script to delete all files older a certain day from my mail folder with this command:

find /var/spool/mymail -mtime +30 -exec rm -rf {} \; 

A clever solution, I thought, but it turns out that cyrus also has index files, and header files that are binary, so the messages will still be in the mailbox, but they are empty, and you get an error when you try to delete them.


So next I told our linux dude that BlueDragon has a CFIMAP tag, I wonder how hard it would be to do this with CFIMAP? We already had BlueDragon installed on our Mail Server, so I went over to my computer, opened up the docs for BD, and started coding. Less than a half hour later I had the code working to delete my old messages. Most of that time was spent trying to figure out which PDF the docs were in, I hate PDFs!

I showed the code to Steve, and he was impressed that I did this so quickly, and also with only about 30 lines of code. Steve said he has accessed IMAP with Java before, and it was complicated. The beauty of abstraction, and CFML!

Here's some code to dump out a list of imap folders:

<cfset conn = "myConnectionName">
<cfimap action="open" service="imap" connection="#conn#" 
	server="localhost" username="user" password="pass">
<cfif imap.succeeded>
	<cfimap action="listallfolders" connection="#conn#" name="folders">
	<cfdump var="#folders#">
	<cfimap action="close" connection="#conn#">
	Error connecting to imap server: <cfoutput>#imap.errortext#</cfoutput>

My only grudges are that the result variable from the cfimap tag is called imap, and not cfimap, the reason I have issue with this, is because I know if Macromedia ever implements this tag, they will choose cfimap as the scope, because that's what other tags that return result like this do, cfhttp, cfcatch, etc. But I would hope that they would keep things somewhat compatible otherwise.

I also ran into a problem when I tried deleting over 3,000 messages at once, but I think the error was returned by Cyrus, and not BD.

Another cool feature in BlueDragon, is that you can tell CFMAIL to archive sent messages in an IMAP folder (eg Sent Folder). That is great if your going to implement web mail, something I am considering doing. I am looking for a very basic web mail client, we currently use Squirrel Mail, and it is nuts - slow, and ugly.

Thanks - New Atlanta, here's a case where we might be able to migrate a php application to CFML.

IMAP rocks too! It is a mystery to me why more people don't use it. I love that my mail is the same no matter what computer I go to, I have access to all my email (both inboxes and sent folders).

Related Entries

2 people found this page useful, what do you think?


ColdFusion with cfx_imap4 ( rocks too. And i'm really happy that MM spent the time to build new things (Reports, Charts, Forms) instead to implement what i can get as a excellent third party tag.
Reto, CFX_Imap4 is written in Delphi and I think only runs on windows servers. I have no problem with third party tags, I have written lots of them, but sometimes it's nice to have builtin support for such things, especially if they are protocol level tags.
I was already in the train when i was thinking about this, because i remembered your new mac. On non Windows machines this is really a good feature of Bluedragon, you are right.
Don't forget about linux, and solaris either about 40% of CF developers use something other than windows, according to one of my polls.
"Another cool feature in BlueDragon, is that you can tell CFMAIL to archive sent messages in an IMAP folder" Any idea how this could be accomplished using MM?
My Mailserver let me send mails directly to a folder using This way i send a bcc to to archive sent messages using cfmail.
What mail server are you running? Doesn't look like I have that option.
We use iMail from But, if you are using the cfx_imap pro from new media development you can use cfx_imap4 to send out emails. You can specify the outbox and sent folder names.

Post a Comment


Spell Checker by Foundeo

Recent Entries


did you hack my cf?