Skip to content

Instantly share code, notes, and snippets.

@lilyball
Created December 4, 2015 05:43
Show Gist options
  • Save lilyball/a74001b3766e40d3c39c to your computer and use it in GitHub Desktop.
Save lilyball/a74001b3766e40d3c39c to your computer and use it in GitHub Desktop.
require ["envelope", "imapflags", "fileinto", "reject", "notify", "vacation", "regex", "relational", "comparator-i;ascii-numeric", "body", "copy"];
# Spam processing
if not header :contains ["X-Spam-known-sender"] "yes" {
if allof (
header :contains ["X-Backscatter"] "yes",
not header :matches ["X-LinkName"] "*"
) {
discard;
stop;
}
if header :value "ge" :comparator "i;ascii-numeric" ["X-Spam-score"] ["8"] {
discard;
stop;
}
if header :value "ge" :comparator "i;ascii-numeric" ["X-Spam-score"] ["4"] {
fileinto "INBOX.Junk Mail";
stop;
}
if header :is ["X-Spam-charsets"] "from='koi8-r', subject='koi8-r', plain='koi8-r'" {
fileinto "INBOX.Junk Mail";
stop;
}
}
# Mailing Lists
if header :contains ["List-ID", "List-Post"] "[redacted]" {
fileinto "INBOX.Mailing Lists.[redacted]";
stop;
}
if header :contains ["List-ID", "List-Post"] "[redacted]" {
fileinto "INBOX.Mailing Lists.[redacted]";
stop;
}
if header :contains ["List-ID", "List-Post"] "<rust-dev.mozilla.org>" {
fileinto "INBOX.Mailing Lists.rust-dev";
stop;
}
if header :contains "List-ID" "<swift-evolution.swift.org>" {
fileinto "INBOX.Swift.swift-evolution";
stop;
}
if header :contains "List-ID" "<swift-users.swift.org>" {
fileinto "INBOX.Swift.swift-users";
stop;
}
if header :contains "List-ID" "<swift-corelibs-dev.swift.org>" {
fileinto "INBOX.Swift.swift-corelibs-dev";
stop;
}
if header :contains "List-ID" "<swift-dev.swift.org>" {
fileinto "INBOX.Swift.swift-dev";
stop;
}
if header :contains "List-ID" "<swift-build-dev.swift.org>" {
fileinto "INBOX.Swift.swift-build-dev";
stop;
}
if header :contains "List-ID" "<swift-evolution-announce.swift.org>" {
fileinto "INBOX.Swift.swift-evolution-announce";
stop;
}
# GitHub
if allof (
address :is :domain "Message-ID" "github.com",
address :regex :localpart "Message-ID" "^[^/]*/[^/]*/(pull|issues|issue|commit)/"
) {
# Message-IDs:
# PR: <rust-lang/rust/pull/11967@github.com>
# PR comment: <rust-lang/rust/pull/11967/r9364118@github.com>
# PR event: <rust-lang/rust/pull/17195/issue_event/165199273@github.com>
# Commit comment: <rust-lang/rust/commit/a8a4de50592d97f576064948751b41a5e75092fa/5245928@github.com>
# Issue: <fish-shell/fish-shell/issues/1682@github.com>
# Issue comment: <rust-lang/rust/issues/9575/33858796@github.com>
# Issue event: <rust-lang/rust/issue/9314/issue_event/165582501@github.com>
#
# Comments on issues I'm participating in have X-GitHub-Reason that includes the reason
# that I'm participating (author, comment, mention).
# Save all issue events in a folder so we can see them in conversations.
if address :regex :localpart "Message-ID" "^[^/]+/[^/]+/(pull|issue)/[^/]+/issue_event/" {
setflag "\\Seen";
fileinto "INBOX.GitHub.events";
stop;
}
# Flag comments on things I authored
if header :is ["X-GitHub-Reason"] "author" {
setflag "\\Flagged";
}
# fish-shell
if address :matches :localpart "Message-ID" "fish-shell/*" {
# fish-shell
if address :matches :localpart "Message-ID" "fish-shell/fish-shell/*" {
# PRs
if address :matches :localpart "Message-ID" "fish-shell/fish-shell/pull/*" {
if allof (
address :matches :localpart "Message-ID" "fish-shell/fish-shell/pull/*/*",
not exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.fish-shell.fish-shell.pulls.replies";
} else {
fileinto "INBOX.GitHub.fish-shell.fish-shell.pulls";
}
}
# Issues
elsif address :matches :localpart "Message-ID" "fish-shell/fish-shell/issues/*" {
if allof (
address :matches :localpart "Message-ID" "fish-shell/fish-shell/issues/*/*",
not exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.fish-shell.fish-shell.issues.replies";
} else {
fileinto "INBOX.GitHub.fish-shell.fish-shell.issues";
}
}
# Commit comments
elsif address :matches :localpart "Message-ID" "fish-shell/fish-shell/commit/*" {
fileinto "INBOX.GitHub.fish-shell.fish-shell.comments";
}
# Issue events are handled above
# Unknown formats (may be thrown out later, save them for now)
else {
fileinto "INBOX.GitHub.unknown";
}
}
# anything else
else {
fileinto "INBOX.GitHub.fish-shell.other";
}
}
# rust-lang
elsif address :matches :localpart "Message-ID" "rust-lang/*" {
# bors
if header :is ["From"] "bors <notifications@github.com>" {
# keep failure comments
if not body :text :contains "failure:" {
# temporarily store bors activity into a folder for testing later
fileinto "INBOX.GitHub.rust-lang.bors";
stop;
}
}
# rust
if address :matches :localpart "Message-ID" "rust-lang/rust/*" {
# PRs
if address :matches :localpart "Message-ID" "rust-lang/rust/pull/*" {
if allof (
address :matches :localpart "Message-ID" "rust-lang/rust/pull/*/*",
not exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.rust-lang.rust.pulls.replies";
} else {
fileinto "INBOX.GitHub.rust-lang.rust.pulls";
}
}
# Issues
elsif address :matches :localpart "Message-ID" "rust-lang/rust/issues/*" {
if allof (
address :matches :localpart "Message-ID" "rust-lang/rust/issues/*/*",
not exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.rust-lang.rust.issues.replies";
} else {
fileinto "INBOX.GitHub.rust-lang.rust.issues";
}
}
# Commit comments
elsif address :matches :localpart "Message-ID" "rust-lang/rust/commit/*" {
fileinto "INBOX.GitHub.rust-lang.rust.comments";
}
# Issue events are handled above
# Unknown formats (may be thrown out later, save them for now)
else {
fileinto "INBOX.GitHub.unknown";
}
}
# rfcs
elsif address :matches :localpart "Message-ID" "rust-lang/rfcs/*" {
# PRs
if address :matches :localpart "Message-ID" "rust-lang/rfcs/pull/*" {
if allof (
address :matches :localpart "Message-ID" "rust-lang/rfcs/pull/*/*",
not exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.rust-lang.rfcs.pulls.replies";
} else {
fileinto "INBOX.GitHub.rust-lang.rfcs.pulls";
}
}
# Issues
elsif address :matches :localpart "Message-ID" "rust-lang/rfcs/issues/*" {
if allof (
address :matches :localpart "Message-ID" "rust-lang/rfcs/issues/*/*",
not exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.rust-lang.rfcs.issues.replies";
} else {
fileinto "INBOX.GitHub.rust-lang.rfcs.issues";
}
}
# Commit comments
elsif address :matches :localpart "Message-ID" "rust-lang/rfcs/commit/*" {
fileinto "INBOX.GitHub.rust-lang.rfcs.comments";
}
# Issue events are handled above
# Unknown formats (may be thrown out later, save them for now)
else {
fileinto "INBOX.GitHub.unknown";
}
}
# guidelines
elsif address :matches :localpart "Message-ID" "rust-lang/guidelines/*" {
# PRs
if address :matches :localpart "Message-ID" "rust-lang/guidelines/pull/*" {
if allof (
address :matches :localpart "Message-ID" "rust-lang/guidelines/pull/*/*",
not exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.rust-lang.guidelines.pulls.replies";
} else {
fileinto "INBOX.GitHub.rust-lang.guidelines.pulls";
}
}
# Issues
elsif address :matches :localpart "Message-ID" "rust-lang/guidelines/issues/*" {
if allof (
address :matches :localpart "Message-ID" "rust-lang/guidelines/issues/*/*",
not exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.rust-lang.guidelines.issues.replies";
} else {
fileinto "INBOX.GitHub.rust-lang.guidelines.issues";
}
}
# Commit comments
elsif address :matches :localpart "Message-ID" "rust-lang/guidelines/commit/*" {
fileinto "INBOX.GitHub.rust-lang.guidelines.comments";
}
# Issue events are handled above
# Unknown formats (may be thrown out later, save them for now)
else {
fileinto "INBOX.GitHub.unknown";
}
}
# everything else
else {
# PRs
if address :regex :localpart "Message-ID" "^rust-lang/[^/]+/pull/" {
if anyof (
address :regex :localpart "Message-ID" "^rust-lang/[^/]+/pull/[^/]+$",
exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.rust-lang.other.pulls";
} else {
fileinto "INBOX.GitHub.rust-lang.other.pulls.replies";
}
}
# Issues
elsif address :regex :localpart "Message-ID" "^rust-lang/[^/]+/issues/" {
if anyof (
address :regex :localpart "Message-ID" "^rust-lang/[^/]+/issues/[^/]+$",
exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.rust-lang.other.issues";
} else {
fileinto "INBOX.GitHub.rust-lang.other.issues.replies";
}
}
# Commit comments
elsif address :regex :localpart "Message-ID" "^rust-lang/[^/]+/commit/" {
fileinto "INBOX.GitHub.rust-lang.other.comments";
}
# Issue events are handled above
# Unknown formats (may be thrown out later, save them for now)
else {
fileinto "INBOX.GitHub.unknown";
}
}
}
# rust-lang-nursery
elsif address :matches :localpart "Message-ID" "rust-lang-nursery/*" {
# PRs
if address :regex :localpart "Message-ID" "^rust-lang-nursery/[^/]+/pull/" {
if anyof (
address :regex :localpart "Message-ID" "^rust-lang-nursery/[^/]+/pull/[^/]+$",
exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.rust-lang-nursery.pulls";
} else {
fileinto "INBOX.GitHub.rust-lang-nursery.pulls.replies";
}
}
# Issues
elsif address :regex :localpart "Message-ID" "^rust-lang-nursery/[^/]+/issues/" {
if anyof (
address :regex :localpart "Message-ID" "^rust-lang-nursery/[^/]+/issues/[^/]+$",
exists ["X-GitHub-Reason"]
) {
fileinto "INBOX.GitHub.rust-lang-nursery.issues";
} else {
fileinto "INBOX.GitHub.rust-lang-nursery.issues.replies";
}
}
# Commit comments
elsif address :regex :localpart "Message-ID" "^rust-lang-nursery/[^/]+/commit/" {
fileinto "INBOX.GitHub.rust-lang-nursery.comments";
}
# Issue events are handled above
# Unknown formats
else {
fileinto "INBOX.GitHub.rust-lang-nursery.unknown";
}
}
# Any other GitHub emails can stay in the inbox
else {
keep;
}
# Also keep anything that mentions me by name
if body :text :contains "@kballard" {
keep;
}
stop;
}
# Patreon
if address :is :all "From" "bingo@patreon.com" {
fileinto "INBOX.#Patreon";
stop;
}
# Kickstarter Project Updates
if allof (
address :is :all "From" "no-reply@kickstarter.com",
header :matches ["Subject"] "Project Update #*"
) {
fileinto "INBOX.#Kickstarter";
stop;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment