Created
August 28, 2014 14:44
-
-
Save fanf/1dc796e7a44a96b8d2cb to your computer and use it in GitHub Desktop.
imapfilter config for server with IDLE support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if_dir = os.getenv('HOME') .. '/.imapfilter/' | |
--------------- | |
-- Options -- | |
--------------- | |
-- time in second before deciding the server timeouted | |
options.timeout = 120 | |
-- auto-subscribe to new directories | |
options.subscribe = true | |
-- verbose mode | |
options.info = true | |
-- use tls | |
options.starttls = true | |
-- time before terminating and reissuing the IDLE command, to avoid | |
-- server reset due to inactivity and so keep the session alive. | |
options.keepalive = 29 | |
---------------- | |
-- Accounts -- | |
---------------- | |
normation = IMAP { | |
server = 'mail.provider.com' | |
, username = ‘[email protected]' | |
, password = 'your password' | |
} | |
-- other accounts can be configured here | |
-- and now, the filtering part! | |
------------------------ | |
-- Filters: Normation -- | |
------------------------ | |
-- the main loop | |
repeat | |
-- only a subset of filters are presented, and a lot of other logic | |
-- combinators are possible to decide what to do | |
-- check on “from” contents from the INBOX folder of “normation” account | |
-- defined above. contain_{bcc, cc, from, suject, to, field, | |
-- body, message} are available. | |
-- “field” is any header, neat for mailing list! | |
-- | |
-- syntax is “varname_where_storing_result = filter_action” | |
x = normation.INBOX:contain_from('[email protected]') | |
-- action to perform: syntax is “varname_where_storing_result:action” | |
x:move_messages(normation['products.rudder-project.github-notifications']) | |
-- “or” between several predicates with “+” | |
-- and “&” is used for “and”. | |
x = normation.INBOX:contain_subject('[Aful]') | |
+ normation.INBOX:contain_to('[email protected]') | |
+ normation.INBOX:contain_to('[email protected]') | |
x:move_messages(normation['veille, r-et-d, opensource/aful']) | |
-- I mainly move emails around, but you can do a whole bunch | |
-- of action: create accounts, delete messages, mark seen, etc etc | |
-- Check “man imapfilter_config” to discover all the possibilities. | |
x = normation.INBOX:contain_field('x-list-administrivia', 'yes') | |
-- subfilter are denoted with “.” or “/” | |
x:move_messages(normation['mailing-lists.mailman-moderation']) | |
-- I only use “x”, because it’s a short, non sensible variable name | |
-- and allow nice-looking indentation with “+/&/etc”. It could | |
-- lead to strange result if I forget an action, so feel free to | |
-- use new variable name for each filter. | |
-- an example with a named field. In place of “contain_” | |
-- you can also “match_” to use regular expressions | |
x = normation.INBOX:contain_field('List-Post', '<mailto:[email protected]>') | |
x:move_messages(normation['produits/rudder-project/ml-oss-rudder-user']) | |
-- an so on, and so on for dozens of similar filters :) | |
-- end of the loop. With that, imapfilter opens an IDLE connection | |
-- to the server, allowing to receive emails as soon as they are published. | |
until not normation.INBOX:enter_idle() | |
-- end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment