Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need top classify my incomming emails using this three rules:

  1. if the email was send to any @somedomain.tld, then copy that email to "somedomain_tld"
  2. if the email was send to any other @*.tld , then copy that email to "others_tlds". (any other = "not somedomain.tld")
  3. The rest of emails, copy to a third folder "rest".

I'm using dovecot sieve rules to do this.

There is an additional condition: the three rules above must be applied to every "To:" address in the email... So in the most complex case, the email should be copied in the three folders

for example: the following email should be copied to the three folders:

From: user@someunrelateddomain.anytld
To: myaddress@mydomain.mytld, user@otherdomain.tld, user@somedomain.tld
Subject: Test Email

This is a test email
  1. Because of "user@somedomain.tld" this email should be copied to "somedomain_tld"
  2. Because of "user@otherdomain.tld" this email should be copied to "others_tlds"
  3. Because of "myaddress@mydomain.mytld" this email should be copied to "rest"

The require and the first rule is easy:

require ["fileinto","copy"];
if address :is :domain "to" "somedomain.tld" { fileinto :copy "somedomain_tld"; }

but the second don't know how to do it:

if address :matches :domain "to" "*.tld" { fileinto :copy "others_tlds"; }

will match somedomain.tld also, which is not what is intended... (if I have an email with "To: user@somedomain.tld" it will be copied to somedomain_tld (OK) and others_tlds (BUG))

For #3 I don't have a clue.

I was also thinking of regexes, but I don know how to express "every domain except this" in a sieve regex (or any other regex style)

Does anyone knows how to bends dovecot's sieve to do 1,2,3?

share|improve this question
add comment

1 Answer 1

require ["fileinto"];
if header :contains "To" "domain.tld"
{
        fileinto "INBOX/domain_tld";
        stop;
}
if header :contains "To" ".tld"
{
        fileinto "INBOX/other_tld";
        stop;
}
if true
{
        fileinto "INBOX/rest";
        stop;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.