imapfilter and magical archives
Thursday, September 14th, 2006After figuring out how to filter my mail I set about figuring out howto use imapfilter to archive old mail in my INBOX. This is actuallyquite simple.
oldmail = { 'old', 'not_since ' .. date_before(7)}results = match(myAccount, 'INBOX', oldmail)move(myAccount, 'INBOX', myAccount, 'INBOX-archive', results)
First off this code matches any old mail (read, seen, whatever) thatarrived more than 7 days ago. Then it moves this mail off to the sideto a folder called ‘INBOX-archive’. It’s put off to the side becauseof some deficiencies with mutt. But I don’t sync -archive foldersanyway so it’s not a big deal, it’s just there if I ever need it.Of course, this still lets the mail in my local folders for all mymailing lists (which constitute most of my mail) pile up. Thesolution? Well I’m subscribed to all the mailing list mailboxes, andit turns out that imapfilter gives me a really nice list of all mysubscribed mailboxes.
print("Archiving mail recieved before " .. date_before(7) .. ".")subscriptions = lsub(myAccount, '')for n in subscriptionsdo print('Archiving in ' .. subscriptions[n]) mailbox = subscriptions[n] results = match(myAccount, mailbox, oldmail) move(myAccount, mailbox, myAccount, mailbox .. ‘-archive’, results)end
Of course this doesn’t work. Atleast not out of the box on imapfilter1.2.2. At one point the following essentially occurs
prefix = NULL;/* read a bunch of stuff off of the network */strlen(prefix);EXC_BAD_ACCESS
Apparently imapfilter doesn’t exactly know how to do deal with myimap server, and prefix stays NULL, causing a not very nice Bus Error.The below patch fixes the problem, though not in the nicest waypossible. It merely does what the original author did and sprinklternary operators liberally.
--- old-namespace.c 2006-09-13 22:41:20.000000000 -0700+++ namespace.c 2006-09-13 22:42:15.000000000 -0700@@ -60,8 +60,8 @@ buffer_reset(&nbuf); o = 0;- if (!strncasecmp(mbox, prefix, strlen(prefix)))- o = strlen(prefix);+ if (!strncasecmp(mbox, prefix, strlen((prefix ? prefix : ""))))+ o = strlen((prefix ? prefix : "")); n = snprintf(nbuf.data, nbuf.size + 1, "%s", mbox + o); if (n > (int)nbuf.size) {
I’ll probably submit this patch to the upstream, or at the very leastnotify them of the bug. imapfilter is a pretty handy little app. Sohandy that it got me to actualy debug C code for the first time inyears.