# Sieve ### Rule to automatically sort mails by alias This Sieve rule filters mails by the mail alias they were sent to. Specifically, it uses a custom suffix separated by a dot: `.([0-9a-zA-Z]*)` It automatically creates a directory for that alias and moves the mail there. Then it stops processing. ``` require ["fileinto","mailbox","regex","variables"]; if allof (header :regex "to" "^.([0-9a-zA-Z]*)@$") { set :lower :upperfirst "target" "${1}"; fileinto :create "${target}"; stop; } ``` ### Rule to change Subject of a mail on server My alma mater introduced a change that subjects of all "external" mails are prefixed with `[Extern]`. I don't like that so I wrote a Sieve rule to remove it. The rule relies on some functions which need to be `required`. ``` require ["fileinto", "editheader", "variables", "regex"]; if allof (header :contains "subject" "[Extern]") { # Match the subject w/o "[Extern]" if header :regex "Subject" "^\\[Extern\\] (.*)$" { # Delete header deleteheader "Subject"; # Add stripped header again addheader :last "Subject" "${1}"; } } ```