[imapfilter-devel] Re: iterate on defined filters

Joel CARNAT joel at carnat.net
Wed Aug 18 11:53:44 EEST 2004


C'est alors (le Tue, 17 Aug 2004 17:56:04 -0500) que David DeSimone <fox at verio.net> dit :

> Note that here, ALERTS contains a TABLE, not a string value, so your
> statement 
> 
>     print("ALERTS is " .. ALERTS)
> 
> will fail because you cannot concatenate a string with a table.
> 
> Of course, that is just a debug statement, so you could hack it like so:
> 
>     print("ALERTS is " .. ALERTS[1])
> 
> Thus printing the first element from the table.
> 

the "not so nice" trouble with this is that it prints the first element of the first element of ALERTS contents.
I thought ALERTS[k] would say "spam", "virus", ... but no =)
In fact, it give the k index of the array (filter) named "spam", "virus", ...
That's not what I expected as I use the filter name to create an INBOX directory :)

Anyway, your pairs() did the thing ; thanks a lot !

Here's the final work (if any one is ever interested ;)

**********************************************************************************
-- Move admin_vc alerts

LIST = {"mailer_daemon", "nagios", "spam", "virus"}
for k,ALERTS in pairs({mailer_daemon, nagios, spam, virus}) do
--      print("k is " .. k)
--      print("ALERTS is " .. LIST[k])
        results = match(admin_vc, 'INBOX', ALERTS)
        headers = fetchheaders(admin_vc, 'INBOX', { 'date ' }, results)
        if headers ~= nil then
                for ID, HDR in pairs(headers) do
                        _, _, month, year = string.find(HDR, "Date: %a+, %d+ (%a+) (%d+)")
move(admin_vc, 'INBOX', admin_vc, year .. '.' .. month .. '.' .. LIST[k], results)
                end
        end
end
**********************************************************************************

I use the LIST array to get a decent string from the k index...
This means ALERTS[k] is the filter defined as foo and LIST[k] is the string "foo" (when LIST and ALERTS have things in the same order ;)

	Jo




More information about the Imapfilter-devel mailing list