Skip to content

Instantly share code, notes, and snippets.

@jsit
Last active May 9, 2023 05:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsit/b19b12176d5a4cefba3779d25aba53e1 to your computer and use it in GitHub Desktop.
Save jsit/b19b12176d5a4cefba3779d25aba53e1 to your computer and use it in GitHub Desktop.
Notifications / mailing lists / bulk email sieve code (for e.g. Fastmail et al.)
if
# Tests for "Mailing Lists"
anyof(
header :is "X-ME-VSCategory" "community:mailing-list",
header :contains "X-Mailer" "Sympa",
exists [
"List-Id",
"List-Help",
"List-Subscribe",
"List-Unsubscribe",
"List-Post",
"List-Owner",
"List-Archive"
],
allof(
not header :contains ["From", "Reply-To", "Received-From", "Return-Path"] [
"github.com", # github.com notifications use "list-archive" et al.
"substack.com" # substack notifications use "list-archive" et al.
],
header :contains [
"List-Archive",
"List-Post",
"X-no-archive"
] ""
)
)
{
fileinto "INBOX.Mailing Lists";
}
elsif
# these are DEFINITELY notifications
allof(
anyof(
header :contains "X-ME-CMCategory" "notification",
header :contains "X-ME-VSCategory" "transactional"
),
# unless they're from substack, which does "transactional" for some reason
not header :contains ["From", "Reply-To", "Received-From", "Return-Path"] [
"substack.com"
]
)
{
fileinto "INBOX.Notifications";
}
elsif # Tests for "Newsletters"
allof(
anyof(
exists "X-Mailgun-Batch-Id",
header :is "X-Mailgun-Tag" "bulk-email",
exists "x-bulkmail",
exists "X-EmailOctopus-List-Id",
header :is "Precedence" "bulk",
header :contains "List-Unsubscribe" "convertkit",
allof(
header :is "precedence" "list",
header :contains [
"x-abuse-info",
"x-complaints-to"
] ""
),
allof(
exists [
"List-Id",
"List-Unsubscribe"
],
header :contains ["From", "Reply-To", "Received-From", "Return-Path"] [
"buttondown.email",
"tinyletterapp.com"
]
),
allof(
header :contains "X-ME-VSCategory" "commercial:mce",
anyof(
allof(
header :contains "X-ME-CMCategory" "promotion",
anyof(
# exists "List-Unsubscribe", # too greedy
exists [
"List-Unsubscribe",
"X-CSA-Complaints"
]
)
),
header :contains ["From", "Reply-To", "Received-From", "Return-Path"] "ghost.io",
# header :contains [ # too greedy
# "list-unsubscribe",
# "list-id"
# ] "",
exists [
"List-Unsubscribe",
"List-Id",
"X-CSA-Complaints"
],
exists [
"list-unsubscribe",
"X-Report-Abuse"
]
)
),
header :contains [
"X-Campaign",
"X-campaignid",
"X-Feedback-ID",
"X-maillist-guid",
"X-maillist-id",
"X-MC-User",
"X-Feedback-ID",
"X-Unsubscribe-Web",
"X-rpcampaign",
"List-Unsubscribe-Post"
] "",
allof(
exists [
"List-ID",
"List-Unsubscribe"
],
header :contains [
"X-CSA-Complaints",
"X-Direct-Mail-Bounce",
"X-Direct-Mail-Abuse"
] ""
)
)
)
{
fileinto "INBOX.Newsletters";
}
elsif
# Tests for Notifications
anyof(
allof(
header :contains "X-ME-VSCategory" "community:social",
header :value "gt" :comparator "i;ascii-numeric" "X-ME-VSScore" "9"
),
allof(
# usually list-unsubscribe is for mailing lists, but we've
# already done our filter for that
header :contains "X-ME-VSCategory" "mce",
exists "list-unsubscribe"
),
allof(
header :contains "X-ME-CMCategory" "promotion",
header :contains "X-ME-VSCategory" "clean"
),
header :contains "X-ME-VSCategory" "commercial:mce",
exists "X-Auto-Response-Suppress", # Xfinity
exists "X-eBay-MailTracker",
header :contains ["Return-Path", "Received"] [
"ddsservicebureau",
"opensolutionsasp",
"messageprovider.com",
"billsupport.com",
"edelivery@ms-bounce.broadridge.com"
],
header :contains "X-Mailer" [
"MIME-tools",
"PHPMailer"
],
header :contains "X-Spam-source" "reflexion.net",
header :contains [
"List-Unsubscribe",
"Auto-Submitted",
"List-ID",
"X-CSA-Complaints",
"X-Complaints-To"
] "",
header :contains ["From", "Return-Path", "Received", "Reply-To"] [
"amazonses.com",
"att-mail.com",
"customercenter.net",
"customeriomail.com",
"diginsite.net",
"emailnotify.net",
"exacttarget.com",
"lithium.com",
"mailgun",
"mcdlv.net",
"pphosted.com",
"reflexion.net",
"rsgsv.net",
"sac.fedex.com",
"salesforce.com",
"sendgrid.net",
"service@paypal.com",
"sparkpost",
"wordfly.com"
],
address :is :localpart ["from", "all"] [
"do-not-reply",
"do_not_reply",
"DoNotRespond",
"donotreply",
"no-reply",
"noreply",
"donotrespond",
"notification",
"notifications"
]
)
{
fileinto "INBOX.Notifications";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment