Pete Freitag Pete Freitag

CFIMAP Rocks - And so does IMAP

Updated on December 06, 2023
By Pete Freitag
coldfusionweb

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.

Enter CFIMAP

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#">
<cfelse>
	Error connecting to imap server: <cfoutput>#imap.errortext#</cfoutput>
</cfif&

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).



bluedragon cfml imap cfimap

CFIMAP Rocks - And so does IMAP was first published on April 05, 2005.

If you like reading about bluedragon, cfml, imap, or cfimap then you might also like:

Fixinator

The Fixinator Code Security Scanner for ColdFusion & CFML is an easy to use security tool that every CF developer can use. It can also easily integrate into CI for automatic scanning on every commit.


Try Fixinator

CFBreak
The weekly newsletter for the CFML Community


Comments

ColdFusion with cfx_imap4 (newmediadevelopment.net) 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.
by Reto Aeberli on 04/05/2005 at 12:03:36 PM UTC
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.
by Pete Freitag on 04/05/2005 at 12:13:17 PM UTC
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.
by Reto Aeberli on 04/05/2005 at 6:07:53 PM UTC
Don't forget about linux, and solaris either about 40% of CF developers use something other than windows, according to one of my polls.
by Pete Freitag on 04/05/2005 at 8:03:23 PM UTC
"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?
by Daniel on 11/09/2005 at 7:27:59 AM UTC
My Mailserver let me send mails directly to a folder using [email protected]. This way i send a bcc to [email protected] to archive sent messages using cfmail.
by Reto Aeberli on 11/09/2005 at 7:41:59 AM UTC
What mail server are you running? Doesn't look like I have that option.
by Daniel on 11/09/2005 at 9:40:52 AM UTC
We use iMail from Ipswitch.com. 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.
by Reto on 11/09/2005 at 9:55:18 AM UTC