Search code examples
regexdovecotsieve-language

Regex capture groups in Sieve script


I want to put emails that are forwarded to my main mailbox (from another domain) into specific sub-folders. For example: foo@bar goes to INBOX/bar/foo.

require ["fileinto", "envelope", "regex", "mailbox"];

if header :regex "delivered-to" "(.*)@(.*)" {
    if not envelope :is "to" "${1}@${2}" {
        fileinto :create "INBOX/${2}/${1}";
    }
}

The capture groups are not replaced in INBOX/${2}/${1}, why ?


Solution

  • Match group variables are not part of the regex capability, but the variables capability. Also require ["variables"]; to be able to use them.