Filtering Spam Emails with Custom Sieve Filters in Proton Mail
April 22, 2026
I've been using a catch-all email address for all emails for a while now, but one thing has always irritated me. My email somehow finds its way into a bunch of unrelated marketing lists that are not likely to respect my wishes to unsubscribe. Now luckily for me, I have been putting the name of the company in all the emails I've used over the years. Not only do I know who has sold me out over the years, I now have a very effective way of filtering out the spam.
See, I'm also a Proton Mail user and they let you write your own custom sieve filters which allow you to super charge email filters with a set of rules and functions that run on every incoming message. I am sharing my filter just in case anyone else has a similar system.
This script will strip the local part (the part before the @) of an incoming email's to address and make sure it is within the domain of the from address (or the part after the @). If they match, great, it's a normal marketing email and we can apply normal marketing rules. If they don't match, accelerate its expiry because I likely don't care for it since a company sold my email off to someone else.
require ["fileinto", "envelope", "regex", "variables", "vnd.proton.expire"];
# Bypass filtering on my special email address
if envelope :all "to" "<redacted>@brittg.com" { stop; }
# Get Recipent's local part
if envelope :localpart :regex "to" "(.*)" {
set "expected_domain" "${1}";
# Get Sender's domain name
if envelope :domain :regex "from" "(.*)" {
set "actual_domain" "${1}";
# If the local part shows up in the domain, great! Let them in.
if string :contains "${actual_domain}" "${expected_domain}" {
fileinto "Marketing";
expire "day" "180";
# If there is a mismatch, woof! Throw them aside.
} else {
fileinto "Marketing/Noncompliant";
expire "day" "30";
}
}
}
You will note that I don't outright delete emails, because even legitimate emails can get caught in this system, so I want to at least give myself a chance to flag emails as good before they are reaped. One common case is Square receipts, which seem to always prefer the last email address that is put into one of their terminals and tie that to the card being used in the transaction. An annoyance but I can live with that.
Combine this with the fact that only a special email address actually gets through to notifying me and my inbox has come back into being manageable, even when the bad actors start signing me up for other marketing lists.
Big shoutout to https://sieve-tester.com/ for testing the filters before I put them into action.