[imapfilter-devel] Question about config file syntax in 2.0
Lefteris Chatzimparmpas
lefcha at hellug.gr
Fri Sep 28 01:44:36 EEST 2007
Bernd Kuemmerlen wrote:
> Hello there,
>
> I have been using imapfilter 1.3 for some time now, and I wanted to
> upgrade to 2.0.
>
> I have some questions regarding the 2.0 config-file syntax:
>
> 1. Is the old (1.3) syntax still supported? It looks as if this is the
> case, I just wanted to be sure.
Hello Bernd,
Yes, version 2.x can read old 1.x configuration files.
> 2. I am using flags for some special vacation handling, and I would like
> to know how this is done in 2.0:
>
> account1 = {
> server = 'mailserver',
> username = 'name at domain',
> password = 'XXXXX',
> }
>
> -- Vacation filter, insert start and end date of vacation
> -- for 'since' and 'before'
> vacation = {
> 'not keyword "vacation"',
> 'since 20-Jul-2007',
> 'before 05-Aug-2007',
> }
>
> -- Get messages which have not yet been auto-replied to
> results = match(account1, 'INBOX', vacation)
> messages = fetchmessage(account1, 'INBOX', results)
>
> if messages then
> for msgid, msgtxt in pairs(messages) do
> pipe_to('/usr/local/share/vacation/vacation.pl username', msgtxt)
> end
> -- set keyword to distinguish handled mails
> flag(account1, 'INBOX', 'add', { keywords = true, 'vacation' }, results)
> end
>
>
> I have not found a quick way to check for the flag or "keyword" in 2.0. I
> guess I could fetch all the flags with fetch_flags(messages), but I don't
> know lua well enough to know how to then check the flags.
You found the one thing that was missing from the new configuration! It
seems that "keyword" has been lost in the translation...
I added it to 2.0.4 version, which I just released, in the form of the
has_flag() searching method.
Your example would translate in something like:
account1 = IMAP {
server = 'mailserver',
username = 'name at domain',
password = 'XXXXX',
}
results = account1.INBOX:arrived_since('20-Jul-2007') *
account1.INBOX:arrived_before('05-Aug-2007') -
account1.INBOX:has_flag('vacation')
messages = account1.INBOX:fetch_message(results)
if messages then
for msgid, msgtxt in pairs(messages) do
pipe_to('/usr/local/share/vacation/vacation.pl username', msgtxt)
end
account1.INBOX:add_flags({ 'vacation' }, results)
end
> 3. In 1.3, I liked the way you could define the filters in one section
> (like the "vacation" filter in the example above) and use it later in the
> actions. Is it possible to do this in the 2.0 syntax as well, i.e. define
> the rules at one place and use them at another?
It cannot be done exactly the same way as before, but it can surely be done
by using some Lua code like this:
myfilter = function ()
return account1.INBOX:arrived_since('20-Jul-2007') *
account1.INBOX:arrived_before('05-Aug-2007') -
account1.INBOX:has_flag('vacation')
end
And everytime you need to get the result of "myfilter" you just do it like this:
results = myfilter()
If you want to make the filter more generic so you can specify a mailbox to
which you want it applied you can modify slightly the above code:
myfilter = function (mailbox)
return mailbox:arrived_since('20-Jul-2007') *
mailbox:arrived_before('05-Aug-2007') -
mailbox:has_flag('vacation')
end
And then you do:
results1 = myfilter(account1.INBOX)
results2 = myfilter(account2.INBOX)
...
>
> Thanks for any help
> Bernd
No problem, and thanks for reporting this searching method that was missing.
L.
More information about the Imapfilter-devel
mailing list