2

I have a problem on a dovecot2 mail server with a sieve script I write. The script should automatically move mail coming from a mailing list to a folder (by list name, not list id)

require ["fileinto", "mailbox", "variables", "regex"];
if exists "list-id" {
    if header :regex "list-id" "([a-zA-Z0-9][a-zA-Z0-9-_. ]+[a-zA-Z0-9.])" {
        fileinto :create "${1}";
        stop;
    }
}

For a mail with the header

List-Id: RZ Monitoring <rz-monitoring.lists.example.com>

This script should move all mail to a folder "RZ Monitoring". But for some reason all mail is piling up in the inbox instead.

The script is getting executed and I have no errors in my logs so I must have made a mistake in the script itself.

M1k3y
  • 19
  • 4

2 Answers2

0

The Dovecot sieve docs aren't clear about this - I think you'd have to dig into the RFCs - but I think that the exists operator is case sensitive, although :regex isn't. So you should use List-Id instead of list-id:

if exists "List-Id" {
    if header :regex "List-Id" "([a-zA-Z0-9][a-zA-Z0-9-_. ]+[a-zA-Z0-9.])" {
        fileinto :create "${1}";
        stop;
    }
}
Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
0

So the following worked:

require ["fileinto", "mailbox", "variables", "regex"];
if exists "List-Id" {
    if header :regex "List-Id" "([a-zA-Z0-9][a-zA-Z0-9\\-_. ]+[a-zA-Z0-9.])" {
        fileinto :create "${1}";
        stop;
    }
}

Like Andrew Schulman pointed out, it seems that "exists" is case sensitive. After fixing this, I ran into an error in the logs. In the regex

([a-zA-Z0-9][a-zA-Z0-9-_. ]+[a-zA-Z0-9.])
                      ^

this "-" is interpreted as a range from "9" to "_", ehich is not valid (Though as far as my understanding of regex is, it shouldn't. Possibly a quirk of dovecots regex implementation). So the "-" here has to be escaped

([a-zA-Z0-9][a-zA-Z0-9\\-_. ]+[a-zA-Z0-9.])
M1k3y
  • 19
  • 4