[imapfilter-devel] imapfilter 2.2 broke this LUA function, help?

Rob Austein sra at hactrn.net
Mon Jun 7 22:21:18 EEST 2010


At Mon, 07 Jun 2010 20:44:49 +0200, Lefteris Chatzimparmpas wrote:
> 
> You can create an empty set and then add messages to it like this...

Yep, that did it.  Fixed version attached, in case anybody is addicted
to the imapfilter 0.x feature as I was.

Many thanks for a nice piece of software, not to mention recent help.


-- Archive old messages.  This is (sort of) a recreation of something
-- that existed in the original 0.x version of imapfilter, rewritten
-- in LUA.  Move old unflagged seen messages to archive mailboxes
-- named using the internal date of the message.

month = {
   ["Jan"] = "01", ["Feb"] = "02", ["Mar"] = "03", ["Apr"] = "04", ["May"] = "05", ["Jun"] = "06",
   ["Jul"] = "07", ["Aug"] = "08", ["Sep"] = "09", ["Oct"] = "10", ["Nov"] = "11", ["Dec"] = "12"
}

function archive(days, mailboxes)
   for _, mailbox in ipairs(mailboxes) do
      results = myserver[mailbox]:is_older(days) * myserver[mailbox]:is_seen() * myserver[mailbox]:is_unflagged()
      msgsets = {}
      for _, message in ipairs(results) do
	 mbox, uid = unpack(message)
	 date = mbox[uid]:fetch_date()
	 _, _, m, y = string.find(date, "%d+-(%a+)-(%d+)")
	 target = mailbox .. "." .. y .. "." .. month[m]
	 if msgsets[target] == nil then
	    msgsets[target] = Set {}
	 end
	 table.insert(msgsets[target], message)
      end
      for target, msgset in pairs(msgsets) do
	 msgset:move_messages(myserver[target])
      end
   end
end


More information about the Imapfilter-devel mailing list