Sieve rule for catch-all email setup: Filter into folders based on alias

0

I'm running a catch-all email setup with my own domain (mydomain.tld). My hoster offers me to create arbitrary Sieve mail filter rules. I would like to create a rule that moves all incoming mail to a folder that equals the alias of the recipient (under my domain), even if the alias is unknown before.

In practice: If I receive an email via <alias>@mydomain.tld, I want a Sieve rule that automatically creates a folder named alias (if non existing) and moves the email into that folder.

A) Is this possible with Sieve?

B) Could you provide the necessary Sieve rule?

new2f7

Posted 2019-04-30T10:46:00.987

Reputation: 1

Answers

0

It is that easy using the Sieve variables extension, which matches the regex * to a useable variable:

require ["fileinto", "variables", "mailbox"];
if header :matches "Delivered-To" "*@mydomain.tld" {
    fileinto :create "${1}";
}

EDIT: it is better to use "Delivered-To" (the envelope) than "To"

new2f7

Posted 2019-04-30T10:46:00.987

Reputation: 1