Question about sieve language
Hello!
I need to match all messages sent from some specific domain and all its sub-domains. I can achieve this with:
if address :match :domain "From" [ "domain.com", "*.domain.com" ] { ... }
But it looks ugly, especially if repeated for 5-6 domains.
Is here way better? :match ["*domain.com"]
will match "notdomain.com" and `:is [ "domain.com" ] doesn't match sub-domains.
I understand, that it is (slightly?) off-topic, but I can not find any sieve-specific resources (all google find ins questions about PronotMail and FastMail filters, and these questions are very basic).
Thank you.
-- // Black Lion AKA Lev Serebryakov
- Lev Serebryakov:
I need to match all messages sent from some specific domain and all its sub-domains.
I prefer using regular expressions for this kind of tests:
if address :regex "From" "[@.]example\.(com|org)$" {...}
This will match all addresses for example.com, example.org and their respective subdomains.
-Ralph
On 13-03-2024 17:36, Ralph Seichter via dovecot wrote:
- Lev Serebryakov:
I need to match all messages sent from some specific domain and all its sub-domains.
I prefer using regular expressions for this kind of tests:
if address :regex "From" "[@.]example\.(com|org)$" {...}
This will match all addresses for example.com, example.org and their respective subdomains.
Or in readable sieve:
if anyof ( address :domain :is "From" "example.org", address :domain :contains "From" ".example.org" ) { keep; }
Which might match "subdomain.example.org.gotcha.com", but how often would that happen?
Kind regards,
Tom
- Tom Hendrikx via dovecot:
Or in readable sieve: [...]
Do you mean to imply that regular expressions are not readable? ;-) All it takes is a little practice. Besides, regex are more efficient. It is well worth learning about them, and regex are really not as bad as some make them out to be.
-Ralph
On 14-03-2024 12:51, Ralph Seichter via dovecot wrote:
- Tom Hendrikx via dovecot:
Or in readable sieve: [...]
Do you mean to imply that regular expressions are not readable? ;-) All it takes is a little practice. Besides, regex are more efficient. It is well worth learning about them, and regex are really not as bad as some make them out to be.
In general, I think regular expressions are fine, but less readable than simple statements (I'm well versed in regex).
The one thing that made me fall in love with sieve is the fact that the syntax is so wonderfully clear and self-documenting, almost readable as normal language. I never need to add comments to a sieve script explaining to my future self what a specific rule tries to achieve.
And given the amount of work that a sieve script does, I don't think that optimization is something you should strive for, when you have to trade it for readability and clarity.
Just my preference :)
Kind regards, Tom
participants (3)
-
Lev Serebryakov
-
Ralph Seichter
-
Tom Hendrikx