[imapfilter-devel] Dated archive

Rob Austein sra at hactrn.net
Sun Feb 27 17:48:29 EET 2011


This is what I use, after Lefteris straightened me out on a few of the
details.  Hack as necessary.


-------------- next part --------------

myserver = IMAP {
   server   = "myserver.example.org",
   username = "me",
   password = "secret",
   ssl      = "tls1"
}

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"
}

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

function archive(days, mailboxes)
   for _, mailbox in ipairs(mailboxes) do
      results = myserver[mailbox]:is_older(days) * myserver[mailbox]:is_seen() * myserver[mailbox]:is_unflagged()
      targets = {}
      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 targets[target] == nil then
	    targets[target] = Set {}
	 end
	 table.insert(targets[target], message)
      end
      for target, msgset in pairs(targets) do
	 msgset:move_messages(myserver[target])
      end
   end
end

archive(120, { "fee", "fie" })
archive(14,  { "foe", "fum" })


More information about the Imapfilter-devel mailing list