[Dovecot] Writing "sieve" script
This is probably not the best place to ask this question; however, I figured I had to start somewhere.
I want to write a sieve script that can sort incoming mail into specific locations.
EXAMPLE:
require ["fileinto"]; if header :contains "X-Virus-Status" "Infected" {fileinto "SPAM"; stop;} elsif header :contains "X-SpamCop-Disposition" "Blocked" {fileinto "SPAM"; stop;} elsif address :contains "To" "user1@domain.com" {fileinto "INBOX.user1";} elsif address :contains "To" "user2@domain.com" {fileinto "INBOX.user2";} elsif address :contains "To" "user3@domain.com" {fileinto "INBOX.user3";} # The rest goes into INBOX # The default is "implicit keep", we do it here explicitly else {keep;}
This works fine unless user1, user2 and or user3 are all included in the same e-mail address. It is rare; however, it does happen. In that case, a separate message for each recipient would be delivered to the first matching mailbox. The other recipients would not receive any traffic at all.
I am new at writing sieve scripts, and have not come up with any way of preventing this from happening. If anyone has a suggestion, I would love to hear it. Even the examples I found by Googling were not really informative.
-- Jerry Dovecot.user@seibercom.net
Disclaimer: off-list followups get on-list replies or get ignored. Please do not ignore the Reply-To header.
"Glory is fleeting, but obscurity is forever." - Napoleon Bonaparte
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Tue, 23 Mar 2010, Jerry wrote:
require ["fileinto"]; if header :contains "X-Virus-Status" "Infected" {fileinto "SPAM"; stop;} elsif header :contains "X-SpamCop-Disposition" "Blocked" {fileinto "SPAM"; stop;} elsif address :contains "To" "user1@domain.com" {fileinto "INBOX.user1";} elsif address :contains "To" "user2@domain.com" {fileinto "INBOX.user2";} elsif address :contains "To" "user3@domain.com" {fileinto "INBOX.user3";} # The rest goes into INBOX # The default is "implicit keep", we do it here explicitly else {keep;}
This works fine unless user1, user2 and or user3 are all included in the same e-mail address. It is rare; however, it does happen. In that case, a separate message for each recipient would be delivered to the first matching mailbox. The other recipients would not receive any traffic at all.
Is this a catch-all mail account so that a single account receives messages for user1, ...,& user3?
If so, you have a logical error in the program flow:
if user1 then fileinto else if user2 then fileinto else if .... end if
when the first condition matches, the second will never tried.
hence:
if header :contains "X-Virus-Status" "Infected" {fileinto "SPAM"; stop;} elsif header :contains "X-SpamCop-Disposition" "Blocked" {fileinto "SPAM"; stop;} else { if address :contains "To" "user1@domain.com" {fileinto "INBOX.user1";} if address :contains "To" "user2@domain.com" {fileinto "INBOX.user2";} if address :contains "To" "user3@domain.com" {fileinto "INBOX.user3";} # The rest goes into INBOX }
if the implicit keep does not work, you need to add another "if", e.g.
if not address :contains "To" [ "user3@domain.com", "user2@domain.com","user1@domain.com"] {
keep;
}
Regards,
Steffen Kaiser -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux)
iQEVAwUBS6oLwL+Vh58GPL/cAQKTWwf/cPeaPmPh3yttL2kDlZf9H/aaAnmWYJ4j FY4mc34XvhPyu3QaOlrlqFaSG9BPOlmo93nziCgTbt/g6V7PBGkUF0MLPGQXluKX TbfjAilu5h4s0OKDLqO82YhhHuspQmvzLtPZ0HPfA8d66Bf6qfc57XO2ELremBBh 0kPvTyR9mPMvvXs/CuO7SEyh7Ng1bdzUzxntOMlcrwvEYF9miwX8HuFjtIYGXSMK w3jtnxRZ6j4PpzE8716fLaQHMjivscWHq/CSX3JDwV547NDhVxzj2eWkRb99CT7N MPYcEQHw/qj3VC9ro3tnsn1zvfyKpQ6R3ozSCkWeB7UKptWawMbKMQ== =Uzfh -----END PGP SIGNATURE-----
participants (2)
-
Jerry
-
Steffen Kaiser