Skip to content

Instantly share code, notes, and snippets.

@hiway
Created February 6, 2014 15:12
Show Gist options
  • Save hiway/8846043 to your computer and use it in GitHub Desktop.
Save hiway/8846043 to your computer and use it in GitHub Desktop.
IMAPfilter configuration file
-- Created with much inspiration from:
-- https://gist.github.com/dylanwh/408810
-- http://gaillourdet.net/2011/05/server-side-imap-filtering-done-right/
-- Todo: include this: https://chris-lamb.co.uk/posts/rotating-email-your-inbox-using-imapfilter
options.timeout = 120
options.subscribe = true
options.expunge = true
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Main: one config to rule them all
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function main()
local home = IMAP {
server = 'imap.emailserver.com',
port = 993,
username = 'email@provider.com',
password = os.getenv('EMAIL_PASSWORD'),
ssl = 'ssl3'
}
local filterinbox = "FilterInbox"
local service = "Service"
local social = "Social"
local dev = "Dev"
repeat
-- Dev
move(home, filterinbox, dev, in_from('github.com'))
-- Social
move(home, filterinbox, social, in_from('gravatar.com'))
-- move(home, filterinbox, social, in_from('facebookmail.com'))
-- move(home, filterinbox, social, in_from('storify.com'))
-- move(home, filterinbox, "Social/Tweets", in_from('appspotmail.com'))
-- move(home, filterinbox, social, in_from('twitter.com'))
-- move(home, filterinbox, social, in_from('ch.eer.io'))
-- move(home, filterinbox, social, in_from('mention.net'))
-- move(home, filterinbox, social, in_from('twilert.com'))
-- move(home, filterinbox, social, in_from('linkedin.com'))
-- move(home, filterinbox, social, in_from('app.net'))
-- move(home, filterinbox, social, in_from('geekli.st'))
-- move(home, filterinbox, social, in_from('path.com'))
-- move(home, filterinbox, social, in_from('plus.google.com'))
-- move(home, filterinbox, social, in_from('coderwall.com'))
-- Accounts
-- move(home, filterinbox, service, in_from('noreply@'))
-- move(home, filterinbox, service, in_from('no-reply'))
-- move(home, filterinbox, service, in_from('donotreply@'))
-- move(home, filterinbox, service, in_from('do-not-reply@'))
-- move(home, filterinbox, service, in_from('pleasereply@'))
-- move(home, filterinbox, service, in_from('account@'))
-- move(home, filterinbox, service, in_from('accounts@'))
-- move(home, filterinbox, service, in_from('info@'))
-- move(home, filterinbox, service, in_from('contact@'))
-- move(home, filterinbox, service, in_from('sales@'))
-- move(home, filterinbox, service, in_from('support@'))
-- move(home, filterinbox, service, in_from('news@'))
-- move(home, filterinbox, service, in_from('newsletter@'))
-- move(home, filterinbox, service, in_from('feedback@'))
-- move(home, filterinbox, service, in_from('admin@'))
-- move(home, filterinbox, service, in_from('specialoffers@'))
-- spam(home, filterinbox, in_from('allschoolstuff.com'))
-- spam(home, filterinbox, in_from('zivame.com'))
-- spam(home, filterinbox, in_from('DealsAndYou'))
-- spam(home, filterinbox, in_from('payback.in'))
-- spam(home, filterinbox, in_from('library4kids'))
-- spam(home, filterinbox, in_from('letsintern'))
-- spam(home, filterinbox, in_from('digidevils.com'))
-- spam(home, filterinbox, in_from('smslane.com'))
-- spam(home, filterinbox, in_from('mycalendarmail.com'))
-- spam(home, filterinbox, in_from('onering.in'))
-- spam(home, filterinbox, in_from('geeksphone.com'))
-- spam(home, filterinbox, in_from('care4free.net'))
-- spam(home, filterinbox, in_from('saleskart.co.in'))
-- spam(home, filterinbox, in_from('skillpagesmail.com'))
-- spam(home, filterinbox, in_from('avaaz.org'))
move(home, filterinbox, dev, in_subject('github'))
-- Move emails into Inbox
move(home, filterinbox, "INBOX", in_from('@'))
until not home.FilterInbox:enter_idle()
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Functions to act on selected messages
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Move messages from one label to another
function move(imap, from_name, to_name, f)
local from = imap[from_name]
local to = imap[to_name]
from:move_messages(to, f(from))
end
-- Copy messages
function copy(imap, from_name, to_name, f)
local from = imap[from_name]
local to = imap[to_name]
from:copy_messages(to, f(from))
end
-- Archive messages from a label. To actually delete, use trash()
function archive(imap, from_name, f)
local from = imap[from_name]
from:delete_messages(f(from))
end
-- Shortcut to move messages to trash (for permanent deletion)
function trash(imap, name, f)
move(imap, name, 'Trash', f)
end
-- Shortcut to mark messages as spam
function spam(imap, name, f)
move(imap, name, 'Spam', f)
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Functions to select messages
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Search text in message subject
function in_subject(text)
return function (_) return _:contain_subject(text) end
end
-- Search text in from-field
function in_from(text)
return function (_) return _:contain_from(text) end
end
-- Search text in message body
function in_body(text)
return function (_) return _:contain_body(text) end
end
-- Older than age (in days) and is not starred
function is_older(age)
return function (_) return _:is_older(age) * _:is_unflagged() end
end
-- Selects unflagged emails over a week old that match subject.
function older_subject(age, text)
return function(_) return _:is_older(age) * _:is_unflagged() * _:contain_subject(text) end
end
-- Selects unflagged emails over a week old that match from.
function older_from(age, text)
return function(_) return _:is_older(age) * _:is_unflagged() * _:contain_from(text) end
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Finally, run the main function.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment