Skip to content

Instantly share code, notes, and snippets.

@ligurio ligurio/Gemfile
Last active Feb 15, 2018

Embed
What would you like to do?
GMail mail filters

Gmail Filters

A collection of GMail filters that I use for personal emails. The XML filters to be imported into GMail are generated using gmail-britta.

Instructions

To generate the GMail filters in XML format, just run ruby filters.rb. The filters will be printed to stdout. Pipe this output to a file and import into [Gmail][settings]. Voilà!

Further Information

See https://bronevichok.ru/blog/2015/01/23/gmail-filters.html.

require 'gmail-britta'
fs = GmailBritta.filterset(:me => ['estetus@gmail.com',
'ligurio@yandex.ru',
]) do
# OpenBSD
filter {
has [{:or => [
'misc@openbsd.org',
'bugs@openbsd.org',
'ports@openbsd.org',
'dmesg@openbsd.org',
].map{|email| "from:#{email}"}}]
label 'OpenBSD'
}
# Invoices
filter {
has [{:or => [
{:or => [
'Payment Receipt',
'Tax Invoice',
'Receipt for Purchase',
'Order Receipt',
].map{|subject| "subject:\"#{subject}\""}},
{:or => [
'Tax Invoice',
].map{|text| "\"#{text}\""}},
# Blacklisted senders
{:or => [
# eBay
[
'from:billing@ebay.com',
'subject:"eBay Invoice Notification"',
],
[
'from:ebay@ebay.com',
'subject:"Your invoice for eBay purchases"',
],
# PayPal
[
'from:service@paypal.com',
'subject:"Receipt for your payment"',
],
]},
]}]
label 'Invoices'
mark_important
star
}
# Newsletters
filter {
has [{:or => [
'"Add us to your address book"',
'"Do not reply to this email"',
'"Email not displaying correctly?"',
'"Forward this email to a friend"',
'"Forward to a friend"',
'"If you no longer want us to contact you"',
'"If you wish to be unsubscribed"',
'"Rather not receive future emails"',
'"Remove me from this list"',
'"Remove yourself from this list"',
'"This newsletter"',
'"To stop receiving emails"',
'"Trouble viewing this email"',
'"Unsubscribe from our mailing list"',
'"Unsubscribe from this list"',
'"Unsubscribe from this mailing list"',
'"Unsubscribe here"',
'"Update subscription preferences"',
'"We hope you enjoyed receiving this message"',
].combination(3).to_a}]
archive
label 'Newsletters'
mark_unimportant
}
# Orders
filter {
has [{:or => [
{:or => [
'Confirmation number',
'Order confirmation',
'Order details',
'Order has shipped',
'Shipping confirmation',
'Tracking number',
].map{|text| "\"#{text}\""}},
# Blacklisted senders
{:or => [
'auto-confirm@amazon.com',
'order-update@amazon.com',
'ship-confirm@amazon.com',
].map{|email| "from:#{email}"}},
]}]
label 'Orders'
}
# Projects (GitHub)
github = filter {
has ['from:notifications@github.com']
label 'Projects'
}.archive_unless_directed
# Projects (Travis)
travis = filter {
has ['from:notifications@travis-ci.org']
label 'Projects'
}.archive_unless_directed
# Social: Calendar
filter {
has ['filename:invite.ics']
label 'Social/Calendar'
star
}.also {
label 'Social'
}
# Social: Facebook
filter {
has [{:or => [
'facebookmail.com',
].map{|email| "from:#{email}"}}]
archive
label 'Social/Facebook'
}
# Social: Foursquare
filter {
has [{:or => [
'noreply@foursquare.com',
].map{|email| "from:#{email}"}}]
archive
label 'Social/Foursquare'
}
# Social: Google+
filter {
has [{:or => [
'plus.google.com',
].map{|email| "from:#{email}"}}]
archive
label 'Social/Google+'
}
# Social: LinkedIn
filter {
has [{:or => [
'group-digests@linkedin.com',
'hit-reply@linkedin.com',
'invitations-noreply@linkedin.com',
'member@linkedin.com',
'messages-noreply@linkedin.com',
'notifications-noreply@linkedin.com',
].map{|email| "from:#{email}"}}]
label 'Social/LinkedIn'
}.also {
has_not [{:or => [
'hit-reply@linkedin.com',
'member@linkedin.com',
].map{|email| "from:#{email}"}}]
archive
}
# Social: Twitter
filter {
has [{:or => [
'postmaster.twitter.com',
].map{|email| "from:#{email}"}}]
archive
label 'Social/Twitter'
}
# Web: Amazon Web Services
filter {
has [{:or => [
'aws-anz-marketing@amazon.com',
'aws-marketing-email-replies@amazon.com',
'no-reply-aws@amazonaws.com',
].map{|email| "from:#{email}"}}]
label 'Web/Amazon Web Services'
}.archive_unless_directed.also {
label 'Web'
}
end
puts fs.generate
source 'https://rubygems.org'
gem 'gmail-britta', '~>0.1.6'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.