This should solve the first two:
require "fileinto"; require "relational";
if address :is :domain "To" "dept.example.com" { fileinto "Dept"; }
if allof ( address :value "ne" :domain "To" "dept.example.com", anyof ( address :matches :domain "To" "*.example.com", address :is :domain "To" "example.com")) { fileinto "Company"; }
It doesn't work...
$ cat > Test.eml From: Yanko Hdez Alvarez myuser@dept.example.com To: Jorge Naranjo otheruser@dept.example.com, The Boss boss@example.com, Yanko Hernandez Alvarez yhdezalvarez@gmail.com Subject: This is a Test
This is a test ^d $ cat > Test.sieve require "fileinto"; require "relational";
if address :is :domain "To" "dept.example.com" { fileinto "Dept"; }
if allof ( address :value "ne" :domain "To" "dept.example.com", anyof ( address :matches :domain "To" "*.example.com", address :is :domain "To" "example.com")) { fileinto "Company"; } ^d $ sieve-test -t- -Tlevel=matching Test.sieve Test.eml
## Started executing script 'Test'
4: address test
4: starting :is' match with
i;ascii-casemap' comparator:
4: extracting To' headers from message 4: parsing address header value
Jorge Naranjo
otheruser@dept.example.com, The Boss boss@example.com, Yank...'
4: extracting domain' part from address
otheruser@dept.example.com'
4: matching value dept.example.com' 4: with key
dept.example.com' => 1
4: finishing match with result: matched
4: jump if result is false
4: not jumping
5: fileinto action
5: store message in mailbox Dept' 8: address test 8: starting
:value-ne' match with i;ascii-casemap' comparator: 8: extracting
To' headers from message
8: parsing address header value Jorge Naranjo <otheruser@dept.example.com>, The Boss <boss@example.com>, Yank...' 8: extracting
domain' part from address otheruser@dept.example.com' 8: matching value
dept.example.com'
8: with key dept.example.com' => 0 (8a): extracting
domain' part from address boss@example.com' 8: matching value
example.com'
(8b): with key dept.example.com' => 1 8: finishing match with result: matched 9: jump if result is false 9: not jumping 11: address test 11: starting
:matches' match with i;ascii-casemap' comparator: 11: extracting
To' headers from message
11: parsing address header value Jorge Naranjo <otheruser@dept.example.com>, The Boss <boss@example.com>, Yank...' (11a): extracting
domain' part from address otheruser@dept.example.com' 11: matching value
dept.example.com'
(11b): with key *.example.com' => 1 11: finishing match with result: matched 11: jump if result is true 11: jumping to line 13 13: fileinto action 13: store message in mailbox
Company'
## Finished executing script 'Test'
Performed actions:
- store message in folder: Dept
- store message in folder: Company
Implicit keep:
(none)
sieve-test(root): Info: final result: success
the rule (address :value "ne" :domain "To" "dept.example.com") is
tested against boss@example.com' (8a) successfully (8b), but the (address :matches :domain "To" "*.example.com") is not, is instead tested against
otheruser@dept.example.com' (11a) with success (11b),
but is not what we intended... ("To: Jorge Naranjo
otheruser@dept.example.com, Yanko Hernandez Alvarez
yhdezalvarez@gmail.com" would defeat this sieve script)...