From 3e8f920ac3b6708c62e4ee8e8ef75df14bafa3c3 Mon Sep 17 00:00:00 2001 From: Michael Schlapa Date: Mon, 7 Oct 2024 17:09:42 +0200 Subject: [PATCH] Added sieve rule to change mail subject --- mailserver/sieve.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mailserver/sieve.md b/mailserver/sieve.md index 3753286..d6a6805 100644 --- a/mailserver/sieve.md +++ b/mailserver/sieve.md @@ -1,6 +1,6 @@ # Sieve -### Sieve rule to automatically sort mails by alias +### 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]*)` @@ -17,3 +17,23 @@ if allof (header :regex "to" "^.([0-9a-zA-Z]*)@$") 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}"; + } +} +```