[Dovecot] Sieve script problem (don't know if is it possible to do this)
Hello:
I'm loosing my mind trying to classify my outgoing messages with sieve-test (2.0.9, centos 6.4). It came to the point I think it's not even possible with a sieve script.
I need to classify my outgoing messages in three folders:
1- To my department (@dept.example.com) 2- To my company (@example.com, @anyotherdept.example.com) (anyotherdept.example.com as in a way to say "any other domain that ends with 'example.com', but not 'dept.example.com'") 3- To the rest of the word (@any.other.domain)
The problematic requirement is I need to make a copy in EVERY IMAP folder that applies. For instance: for an email such as
From: myuser@dept.example.com To: user@dept.example.com, user@example.com, user@other.domain ...
I need to make a copy to all folders: Dept (because of user@dept.example.com), Company (because of user@example.com) and Rest (because of user@other.domain).
Rule for #1 is simple:
if address :matches :domain "To" "dept.example.com" { fileinto: "Dept"; }
Rule for #2, I don't know how to declare it: I don't know how to make a rule that matches "example.com" (or anyotherdept.example.com) and not "dept.example.com".
if allof(address :matches :domain "To" "example.com", not address :matches :domain "To" "dept.example.com") { fileinto: "Company"; } ... doesn't work, because user@dept.example.com matches (address :matches :domain "To" "example.com"), but it doesn't matches (not address :matches :domain "To" "dept.example.com").
"user@example.com" matches both conditions, but sieve-test stops on the first email address with a "not matches"
As for Rule #3: I don't know how to do it either, it should be the same as Rule #2, (with different parameters of course).
A sieve script should be capable to do this, but it seems that I'm loosing something. Does any one knows how to do this?
Kind regards Yanko
PS: English is not my native language. Please forgive me any mistakes/misspellings/etc I made.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Am 14.11.2013 19:17, schrieb Yanko Hernández Álvarez:
Hello:
I'm loosing my mind trying to classify my outgoing messages with sieve-test (2.0.9, centos 6.4). It came to the point I think it's not even possible with a sieve script.
I need to classify my outgoing messages in three folders:
stop here , filter outgoing mail is not possible yet with sieve, at my current info level, but it may come in future ( but thats a different story )
but your mail client may do copy in different imap folders at send time, or your mailserver may do some kind of sort/copy with i.e bcc feature etc
equal stuff was asked before on the list i think , search archive
however if i dont unterstand you in the right way, and you want to sort incomming mail feel free to ask again
1- To my department (@dept.example.com) 2- To my company (@example.com, @anyotherdept.example.com) (anyotherdept.example.com as in a way to say "any other domain that ends with 'example.com', but not 'dept.example.com'") 3- To the rest of the word (@any.other.domain)
The problematic requirement is I need to make a copy in EVERY IMAP folder that applies. For instance: for an email such as ---- From: myuser@dept.example.com To: user@dept.example.com, user@example.com, user@other.domain ... ---- I need to make a copy to all folders: Dept (because of user@dept.example.com), Company (because of user@example.com) and Rest (because of user@other.domain).
Rule for #1 is simple: ----- if address :matches :domain "To" "dept.example.com" { fileinto: "Dept"; } -----
Rule for #2, I don't know how to declare it: I don't know how to make a rule that matches "example.com" (or anyotherdept.example.com) and not "dept.example.com".
if allof(address :matches :domain "To" "example.com", not address :matches :domain "To" "dept.example.com") { fileinto: "Company"; } ... doesn't work, because user@dept.example.com matches (address :matches :domain "To" "example.com"), but it doesn't matches (not address :matches :domain "To" "dept.example.com").
"user@example.com" matches both conditions, but sieve-test stops on the first email address with a "not matches"
As for Rule #3: I don't know how to do it either, it should be the same as Rule #2, (with different parameters of course).
A sieve script should be capable to do this, but it seems that I'm loosing something. Does any one knows how to do this?
Kind regards Yanko
PS: English is not my native language. Please forgive me any mistakes/misspellings/etc I made.
Best Regards MfG Robert Schetterer
[*] sys4 AG
http://sys4.de, +49 (89) 30 90 46 64 Franziskanerstraße 15, 81669 München
Sitz der Gesellschaft: München, Amtsgericht München: HRB 199263 Vorstand: Patrick Ben Koetter, Axel von der Ohe, Marc Schiffbauer Aufsichtsratsvorsitzender: Florian Kirstein -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJShSf0AAoJEP8jBObu0LlEJtAH/127BkvFTC/00eK6j7xOnGtP NoIGbtYih/ySDMD0COklazVe+36+QWawmIkKLtUmDAYPo5TaSJw5GN40vTl3NYHl mEQpzjAlHW8kPyIvlPiZIKju6PGSzHtJXnOQovFmN2327HwvM2B+nEhccWIhDy0a NtnR3URu5iiFN1yZis2wpCBrriCmT4aFCo7DnTLnED5I4dvychbNehGYUhCi0z69 +IKSl4tplV//lVo4BsHzi/Hk+ewVSZsMgimXVOm6namS8m1l1vAGnsrWbOK4S5KN KTHpE9yrt/cBw+0Cr/ZDry3NEcQw1KxYNyq61oLFYWYPYSvCuBloll2AbSAp8ys= =AhDy -----END PGP SIGNATURE-----
Am 14.11.2013 19:17, schrieb Yanko Hernández Álvarez:
Hello:
I'm loosing my mind trying to classify my outgoing messages with sieve-test (2.0.9, centos 6.4). It came to the point I think it's not even possible with a sieve script.
I need to classify my outgoing messages in three folders:
stop here , filter outgoing mail is not possible yet with sieve, at my current info level, but it may come in future ( but thats a different story )
but your mail client may do copy in different imap folders at send time, or your mailserver may do some kind of sort/copy with i.e bcc feature etc
Well my email only filters/classifies at receive time (IMAP check), not sending (SMTP), so I'm scr... on that front.
equal stuff was asked before on the list i think , search archive
however if i dont unterstand you in the right way, and you want to sort incomming mail feel free to ask again
Incomming mail is a piece of cake, there is only one sender (in opposition to several recipients) so simple rules and "if" nesting is enough (pseudocode):
if from dept.example.com copy to dept; else if from *.example.com or example.com copy to company else copy to restoftheworld;
and it works, because there is only one address (the sender)... The problem appears when there are many addresses (many recipients) and the requirement to leave a copy in every folder that applies...
I used to have a a very long and inefficient bash script -bash, you know- in "cron.hourly" that classified sent emails and moved them to the right folder.
Now I want to do the same using sieve-test instead -faster, native code, more declarative code,...- , and get rid of the ugly bash script, but so far, without success. :-(
But if you want, you can see it as incoming mail filtering problem. Just ignore the "From" address and use only the recipients addresses ("To") to do the classification and the problem stays just the same
kind regards Yanko
Maybe you can do it with postdrop?
On 14 Nov 2013 20:18, "Yanko Hernández Álvarez" yhdezalvarez@gmail.com wrote:
Hello:
I'm loosing my mind trying to classify my outgoing messages with sieve-test (2.0.9, centos 6.4). It came to the point I think it's not even possible with a sieve script.
I need to classify my outgoing messages in three folders:
1- To my department (@dept.example.com) 2- To my company (@example.com, @anyotherdept.example.com) (anyotherdept.example.com as in a way to say "any other domain that ends with 'example.com', but not 'dept.example.com'") 3- To the rest of the word (@any.other.domain)
The problematic requirement is I need to make a copy in EVERY IMAP folder that applies. For instance: for an email such as
From: myuser@dept.example.com To: user@dept.example.com, user@example.com, user@other.domain ...
I need to make a copy to all folders: Dept (because of user@dept.example.com), Company (because of user@example.com) and Rest (because of user@other.domain).
Rule for #1 is simple:
if address :matches :domain "To" "dept.example.com" { fileinto: "Dept"; }
Rule for #2, I don't know how to declare it: I don't know how to make a rule that matches "example.com" (or anyotherdept.example.com) and not "dept.example.com".
if allof(address :matches :domain "To" "example.com", not address :matches :domain "To" "dept.example.com") { fileinto: "Company"; } ... doesn't work, because user@dept.example.com matches (address :matches :domain "To" "example.com"), but it doesn't matches (not address :matches :domain "To" "dept.example.com").
"user@example.com" matches both conditions, but sieve-test stops on the first email address with a "not matches"
As for Rule #3: I don't know how to do it either, it should be the same as Rule #2, (with different parameters of course).
A sieve script should be capable to do this, but it seems that I'm loosing something. Does any one knows how to do this?
Kind regards Yanko
PS: English is not my native language. Please forgive me any mistakes/misspellings/etc I made.
On 11/14/2013 7:17 PM, Yanko Hernández Álvarez wrote:
Hello:
I'm loosing my mind trying to classify my outgoing messages with sieve-test (2.0.9, centos 6.4). It came to the point I think it's not even possible with a sieve script.
Outgoing? Sieve is currently only applicable to incoming e-mail. If you managed to do something like this, I'd be interested to find out how. :)
I need to classify my outgoing messages in three folders:
1- To my department (@dept.example.com) 2- To my company (@example.com, @anyotherdept.example.com) (anyotherdept.example.com as in a way to say "any other domain that ends with 'example.com', but not 'dept.example.com'") 3- To the rest of the word (@any.other.domain)
The problematic requirement is I need to make a copy in EVERY IMAP folder that applies. For instance: for an email such as
From: myuser@dept.example.com To: user@dept.example.com, user@example.com, user@other.domain ...
I need to make a copy to all folders: Dept (because of user@dept.example.com), Company (because of user@example.com) and Rest (because of user@other.domain).
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"; }
Unfortunately, I cannot find a way to do #3. Perhaps some extremely convolved regular expression, but I wouldn't want to go there. Basically one needs to test that at least one of the addresses in the message does not match *.example.com, but I don't see how that could be achieved.
Regards,
Stephan.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Thu, 14 Nov 2013, Stephan Bosch wrote:
1- To my department (@dept.example.com) 2- To my company (@example.com, @anyotherdept.example.com) (anyotherdept.example.com as in a way to say "any other domain that ends with 'example.com', but not 'dept.example.com'") 3- To the rest of the word (@any.other.domain)
Hi Stephan, about #3 how about the variable extension? I never used it so far, but it should work
This should solve the first two:
require "fileinto"; require "relational";
require "variables";
set "done" "0";
if address :is :domain "To" "dept.example.com" { fileinto "Dept";
set "done" "1";
}
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";
set "done" "1";
}
if string :is "${done}" "0" { fileinto "other"; }
Steffen Kaiser -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux)
iQEVAwUBUoXQOl3r2wJMiz2NAQKk/ggAi8ywhial+WRDJxNhZKLahQnIp8Iyn6tN JN8MBqrALStkGZ6QLeRrgPhNuJ4I3vdbh8MnCtQR1ftH51NxUs/7X0zRIfmmdd3+ NWEBnSX5op4Qda48edUiSAXsZ69ggrzKXfqf98Rask8jXxBZG3HLR87AgVGXoEaL c2BmT0xWf7EXsNqGBjpSCNwwzD0LpEF7mqGIVg8N+OiLrUNc0+s7BQTNdKNXmez/ 1A1pt3zX+oyIBKivFvaZxxHwrNOYSZNk4+fLS2n612eUJ4ge0C0RTqolb8OEharW TGauhXFu4Rw2w9h1rkqO1OzL8dINzQLQbhjIwj4Lhx73fVUVVZwESA== =JwG9 -----END PGP SIGNATURE-----
On 11/15/2013 8:41 AM, Steffen Kaiser wrote:
Hi Stephan, about #3 how about the variable extension? I never used it so far, but it should work
Congratulations! You fell into the same trap I did when I first saw this problem. :)
Consider this header:
To: user@dept.example.com, user@example.com, user@other.domain
require "fileinto"; require "relational";
require "variables";
set "done" "0";
if address :is :domain "To" "dept.example.com" { fileinto "Dept";
set "done" "1";
}
The variable "done" is set to "1", due to the first address.
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";
set "done" "1";
}
The variable "done" is set to "1", due to the second address. And now that I think of it, it would also work on the combination of the first and the third, making this rule still inadequate.
if string :is "${done}" "0" { fileinto "other"; }
Since "done" is set to "1", the message is not filed into "other". But that is wrong, due to the presence of the third address.
See the core of the problem now? :)
Regards,
Stephan.
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)...
Yanko Hernández Álvarez skrev den 2013-11-14 19:17:
I'm loosing my mind trying to classify my outgoing messages with sieve-test (2.0.9, centos 6.4). It came to the point I think it's not even possible with a sieve script.
before you loose your hair aswell, have you consider trying roundcube on localhost ?
and setup it to the problematic domain email server with imap and sieve support ?
when it works you have a sieve rule that works :)
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Thu, 14 Nov 2013, Yanko Hernández Álvarez wrote:
I'm loosing my mind trying to classify my outgoing messages with sieve-test (2.0.9, centos 6.4). It came to the point I think it's not even possible with a sieve script.
I need to classify my outgoing messages in three folders:
As others told already, you can filter incoming messages only, but you can make outgoing into incoming messages with BCC. You will have to have an unique way to identify your BCC'ed messages, however.
E.g.: a) Add a custom header, say "X-X-Yanko", in your MUA. If possible remove that header by your MTA if the message leaves your network b) use detail (subaddressing), if your MTA allows that: user+detail@ c) use a completely different account that spools into the mail storage of your normal account d) ...
3- To the rest of the word (@any.other.domain)
Would the normal "sent" folder be OK? There you would have 1+2+3 merged.
Another idea is in the reply to Stephan's post.
Steffen Kaiser -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux)
iQEVAwUBUoXOb13r2wJMiz2NAQJLYgf/b9IZLunFOdgX2tLH/5WZI5msUlQx41TZ 0bsykwCYSZWeGxmB1fnsFmiFLiJJ7F2xqsX2N8YwOYMmKB3iQ/a8O8c+I+3hwmGD Jk1TGmUZ6mdtBk1nOXqDbWIUXEGvH2YRqTG+yyUaDg/z6gAr/xq7OIBlvm7887CJ ciEueGV7x/SCk25K2HNFpovg65ZYjERDjeXaY51mtL/yb7Vp1FQ71Xkr6MQt3yUT 9phZKZOOTylO312/sQVz0RP/ZLethnKeisKcBWZg4LUS12sdVEzy7PXCZgUNE1OP OsFjkleykQIzXR/lio8MiBVcTWkoL0tpAUQ5ryF217b/0oT2YC6iKQ== =olis -----END PGP SIGNATURE-----
participants (6)
-
Benny Pedersen
-
Muzaffer Tolga Ozses
-
Robert Schetterer
-
Steffen Kaiser
-
Stephan Bosch
-
Yanko Hernández Álvarez