pym thoughts

Using sieve filters with Proton Mail

Intro

Sieve is a programming language allowing fine control to create server side filtering rules for emails way more powerful than just relying on "from", "to", "subject" etc. You can match anything in the email header and apply pretty nice rules. Various emails providers support sieve filtering (I know at least Fastmail and Proton Mail supporting this).

Documentation

Proton has a comprehensive documentation to experiment with more stuff than what I'll be talking about here, see https://proton.me/support/sieve-advanced-custom-filters. Literally everything I'll explain here is available in that documentation.

Warning : sieve filters applies on incoming and outgoing emails, be sure to properly match the emails you want to filter.

My use case

There are newsletters or emails I'd like to receive but I don't want to keep them in my inbox after a certain time if I missed them because they're not that important. Prime examples are : Uber receipts : it's handy to have them after a ride or a food order if you need it. But if you didn't need it at that time you want it to be deleted and you can always log back into your Uber acount to get the info later. Or some websites (like Peak Design), will send you a link via email every time you want to sign in (instead of login using username and password), so you end up having lots of these emails in your inbox if you don't clean them up everyday.

So long story short, I want to keep some emails for a few days and have them automatically gone after some time so I don't need to frequently do some inbox cleaning.

For this particular use case some people do a rule that move emails to a specific folder with a retention policy : every mail in that folder is deleted after some time. I prefer having all my emails in the same folder so I can see everything in the same place, and only delete the ones I want automatically. This is why I use these filters.

Note : The action of deleting emails after some time is something that is specific to Proton Mail and not a standard sieve extension (As far as I know)

Where to setup Sieve filters in Proton Mail ?

Go to All settings > Filters > Add Sieve Filter

My Filters

First you need to list all the sieve extensions you will need, for my filters I use :

require ["vnd.proton.expire", "fileinto"];

vnd.proton.expire : is a proton specific action that allow you to set up an expiration time on your emails so that they're automatically deleted once this time expire.

fileinto : is a standard sieve action that allow you to add a label on emails (so you can make emails that have been flagged for expiration to stand out more in your proton mail inbox)

Here are my expiration sieve filters :

# Load the extension we will need for all filters below
require ["vnd.proton.expire", "fileinto"]; 

# Filter 1
# permanently delete all incoming and outgoing emails after 10 days for some senders addresses
if address :is "from" ["marketing@somedomain.tld", "newsletter@someotherdomain.tld"]
{ 
    expire "day" "10";
    fileinto "expiration set";
}

# Filter 2
# permanently delete all incoming and outgoing emails after 10 days for some recipients addresses
# Let's say in this example that my-alias-1@aleeas.com is the email alias you use for your Uber account where you receive Uber eats order receipts
if address :is "to" "my-alias-1@aleeas.com"
{ 
    expire "day" "10";
    fileinto "expiration set";
}

# Filter 3
# permanently delete all incoming and outgoing emails after 10 days from some domains
#anything@news.*
if header :matches "from" "*@news.*"
{ 
    expire "day" "10";
    fileinto "expiration set";
}

# Filter 4
# permanently delete all incoming and outgoing emails after 10 days for some subjects
if header :contains "subject" ["Your link to sign in to XYZ Website", "Another email subject you see often"]
{ 
    expire "day" "10";
    fileinto "expiration set";
}

Note : You may need to create the label (in this howto : expiration set) before using it in the filters, I don't know what happens with the filters if you try to apply a non-existent label.
Also you can see that expire is in a red box as it's not recognized as a valid sieve option by the syntax highlighter because this is not a standard sieve option and only works with proton mail as far as I know.

This is how it looks like in the inbox. proton_sieve

The label expiration set is not mandatory as you can see the sandglass as well as the remaining 10 d expiration time on the right side. But I think the label makes it stand out a bit more. Also the expiration time will update everyday. In the example above, the next day, 10 d will be replaced by 9 d an so on until it goes in the Trash.

Email from my friend John Doe didn't match any filter and won't be deleted.

There you go, it's not rocket science and as I wrote above, everything mentioned here can be found in the Proton Mail post about Sieve filters here https://proton.me/support/sieve-advanced-custom-filters.

The possibilities with Sieve filtering are endless, play with it and enjoy (but be careful, do a lot of tests before playing with filters that automatically delete emails, just in case).