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

Lefteris Chatzimparmpas lefcha at hellug.gr
Sun Jun 6 12:23:11 EEST 2010


Hello,

Try with something like this:

   function archive(days, mailboxes)
      for _, mailbox in ipairs(mailboxes) do
	results = myserver[mailbox]:is_older(days) *
		  myserver[mailbox]:is_seen() *
		  myserver[mailbox]:is_unflagged()
	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]
	   Set{message}:copy_messages(myserver[target])
	end
      end
   end

L.


On 06/04/2010 06:48 PM, Rob Austein wrote:
> The following function worked until I upgraded to imapfilter 2.2.
> I understand that the underlying problem is that the search results
> table format has changed significantly, but it's far from obvious how
> to achieve anything like the same result with 2.2.  Which is a pity,
> as the ability to do this kind of thing from a nightly cron job has
> always been one of the best things about imapfilter.  Any suggestions?
>
>
> -- 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.  The double inner
> -- loop cuts down on the number of IMAP operations.
>
> 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 pairs(mailboxes) do
>        msgs = myserver[mailbox]:fetch_date(myserver[mailbox]:is_older(days) *
>                                            myserver[mailbox]:is_seen() *
>                                            myserver[mailbox]:is_unflagged())
>        if msgs then
>           mbxs = {}
>           for msg, date in pairs(msgs) do
>              _, _, m, y = string.find(date, "%d+-(%a+)-(%d+) ")
>              mbx = mailbox .. "." .. y .. "." .. month[m]
>              if mbxs[mbx] == nil then
>                 mbxs[mbx] = {}
>              end
>              mbxs[mbx][msg] = true
>           end
>           for mbx, msgs in pairs(mbxs) do
>              myserver[mailbox]:move_messages(myserver[mbx], msgs)
>           end
>        end
>     end
> end
>
> archive(120, { "inbox", "ietf", "nanog" })
> _______________________________________________
> Imapfilter-devel mailing list
> Imapfilter-devel at lists.hellug.gr
> http://lists.hellug.gr/mailman/listinfo/imapfilter-devel


More information about the Imapfilter-devel mailing list