Discussion:
[imapfilter-devel] filters for archiving mail
Philippe LeCavalier
2011-01-23 20:07:13 UTC
Permalink
This may seem ridiculously easy once I have the answer but ever since I
stumbled upon this project over a month ago I've been trying to create a
simple rule to archive my mail. Here's what I've come up with -which
doesn't work- Ideally, I'd like to build upon that so I don't have to
revist it ie have a function that substracts 1 from the current year and
performs the archive. Even better would be to create the folders in the
archive to replicate the tree :-) Anyway.

55 --ARCHIVING
56 --Pre-2009
57 --[[
58 results = account1.INBOX:arrived_before('01-Jan-2009') -
59 (account1['rec'] +
60 account1['archives'])
61 results:move_messages(account2['archives/pre_2009'])
62
63 --2009
64 results = account1.INBOX:arrived_since('01-Jan-2009') *
65 account1.INBOX:arrived_before('01-Jan-2010') -
66 (account1['rec'] +
67 account1['archives'])
68 results:move_messages(account2['archives/2009'])
69 --]]

i) rather than specify each mailbox and subfolder thereof, how can I
have it look through all mailboxes under INBOX recursively. 'INBOX.*'
kind of thing?

ii) if i) then how can I exclude the 'rec' and 'archive' folders?

Thanks for any advice.
Phil
Lefteris Chatzimparmpas
2011-01-25 19:39:25 UTC
Permalink
Post by Philippe LeCavalier
58 results = account1.INBOX:arrived_before('01-Jan-2009') -
59 (account1['rec'] +
60 account1['archives'])
61 results:move_messages(account2['archives/pre_2009'])
62
63 --2009
64 results = account1.INBOX:arrived_since('01-Jan-2009') *
65 account1.INBOX:arrived_before('01-Jan-2010') -
66 (account1['rec'] +
67 account1['archives'])
68 results:move_messages(account2['archives/2009'])
You can't include folders in your results like this or combine them with
search functions like arrived_before(). If you want to exclude all mail
in those 2 mailboxes then use select_all().

You're supposed to call specific functions to do searching. See the
imapfilter_config(5) man page section SEARCHING.
Post by Philippe LeCavalier
i) rather than specify each mailbox and subfolder thereof, how can I
have it look through all mailboxes under INBOX recursively. 'INBOX.*'
kind of thing?
Have a look at the LISTING section in the man page.
Post by Philippe LeCavalier
ii) if i) then how can I exclude the 'rec' and 'archive' folders?
You have to use a some Lua and to string comparisons based on the output
of the listing functions.
Philippe LeCavalier
2011-01-25 20:31:21 UTC
Permalink
Post by Lefteris Chatzimparmpas
Post by Philippe LeCavalier
58 results = account1.INBOX:arrived_before('01-Jan-2009') -
59 (account1['rec'] +
60 account1['archives'])
61 results:move_messages(account2['archives/pre_2009'])
62
63 --2009
64 results = account1.INBOX:arrived_since('01-Jan-2009') *
65 account1.INBOX:arrived_before('01-Jan-2010') -
66 (account1['rec'] +
67 account1['archives'])
68 results:move_messages(account2['archives/2009'])
You can't include folders in your results like this or combine them with
search functions like arrived_before(). If you want to exclude all mail
in those 2 mailboxes then use select_all().
You're supposed to call specific functions to do searching. See the
imapfilter_config(5) man page section SEARCHING.
Post by Philippe LeCavalier
i) rather than specify each mailbox and subfolder thereof, how can I
have it look through all mailboxes under INBOX recursively. 'INBOX.*'
kind of thing?
Have a look at the LISTING section in the man page.
Post by Philippe LeCavalier
ii) if i) then how can I exclude the 'rec' and 'archive' folders?
You have to use a some Lua and to string comparisons based on the output
of the listing functions.
Thanks Lefteris.

hm. What you mention makes sense to me but I doubt I'll be able to 'take
it from here' :-)

I'll keep searching for a working example...Surely someone is using this
project for this.

Phil
Lefteris Chatzimparmpas
2011-01-26 21:44:44 UTC
Permalink
Post by Philippe LeCavalier
hm. What you mention makes sense to me but I doubt I'll be able to 'take
it from here' :-)
I'll keep searching for a working example...Surely someone is using this
project for this.
I suggest that you search at the list archives, you might find similar
examples. Also, I guess if someone in this list has something similar it
would be nice to reply to.

Reading the imapfilter_config(5) man page and sample.config.lua and
sample.extend.lua, could help you get a grasp of imapfilter's
capabilities and how it can be combined with Lua.
Post by Philippe LeCavalier
From a point on, studying some Lua from the available documentation is
probably the only way to go... I know it isn't that simple to do, but if
you want to write complicated filtering functions you have to know a bit
of Lua... At least some simple stuff such as variables, functions,
loops, etc.

Continue reading on narkive:
Loading...