Skip to content

Instantly share code, notes, and snippets.

@nelson
Created November 22, 2022 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelson/ba764899cf3caa2374b9219fdcafeccf to your computer and use it in GitHub Desktop.
Save nelson/ba764899cf3caa2374b9219fdcafeccf to your computer and use it in GitHub Desktop.
Fastmail sieve - put email aliases into their own subfolder
#
# My custom sieve script for putting emails into their own subfolder
# Ref: https://www.reddit.com/r/fastmail/comments/qahdf3/my_custom_sieve_script_for_putting_emails_into/
#
if exists "X-Delivered-to" {
# An email addressed to
# "website@user.domain.com" will be put in the folder "Website"
# "my-website@user.domain.com" will be put in the folder "My Website"
if header :regex "X-Delivered-to" "([A-z0-9]+)-?([A-z0-9]+)?@user.domain.com" {
if string :is "${2}" "" {
# Only first word is being used
set :lower :upperfirst "website" "${1}";
} else {
# Two words are being used, let's capitalize both of them
set :lower :upperfirst "one" "${1}";
set :lower :upperfirst "two" "${2}";
set "website" "${one} ${two}";
}
# Move email into its own folder under the inbox
fileinto :create "INBOX.${website}";
}
}