Problem with mail filter rules

Discussion in 'General' started by Dehumanizer, Oct 21, 2012.

  1. Dehumanizer

    Dehumanizer New Member

    I have found that dovecot probably has some problems with regexp in sieve scripts...
    Everything is fine until I enter a mail rule which includes some characters that need escaping, like "[". The ISPConfig correctly escapes it and for rule which includes "[Test" in the Subject header it generates a script like this:
    ### BEGIN FILTER_ID:2
    if header :regex ["subject"] [".*\[Test"] {
    fileinto "Test";
    stop;
    }
    ### END FILTER_ID:2

    but then when I try to send an email to this mailbox, I'm getting this error :
    main_script: line 34: error: invalid regular expression for regex match: unmatched [ or [^.
    main_script: error: validation failed.

    even though the regular expression is perfectly fine.
    Any ideas on how to fix this? Can anyone test if it works for them hence if it's just a problem with the dovecot version I'm running?
    The server is Debian 6 with Dovecot 1.2.15
     
    Last edited: Oct 21, 2012
  2. Dehumanizer

    Dehumanizer New Member

    Well after a bit of testing I found that special characters (or at least the square bracket, I haven't tried anything else yet) have to be double escaped, so my filter from the previous message should go like this:

    ### BEGIN FILTER_ID:2
    if header :regex ["subject"] [".*\\[Test"] {
    fileinto "Test";
    stop;
    }
    ### END FILTER_ID:2

    However you need to manually edit the filter in the "custom rules" tab, because if you enter \[ in the mail filtering tab as a rule, it will get triple escaped (it will become \\\[ in the filter).
    I'm not sure if it's a bug in the dovecot's sieve plugin implementation of regular expressions or if this is how it should work. If it's a correct behaviour, it needs to be fixed in ISPConfig so that special characters will get double escaped.
     
  3. falko

    falko Super Moderator ISPConfig Developer

    I've added this to our bugtracker, so we will check that.
     

Share This Page