Invalid regex in Mailbox "Mail Filter"

Discussion in 'ISPConfig 3 Priority Support' started by cajdavidson, Jul 8, 2025.

  1. cajdavidson

    cajdavidson New Member HowtoForge Supporter

    I have a client trying to add some regex rules into "Mail Filter" under the individual users mailbox, I created a test which just had the following settings:

    Name: Test Regex
    Source: Subject / Matches Regex
    (?i)spamjunk
    Action: Delete
    Active: Check
    When running ispconfig.sh to update it gives this error....

    .ispconfig-before: line 18: error: invalid regular expression '(?i)spamjunk' for regex match: invalid preceding regular expression.
    .ispconfig-before: error: validation failed.
    sievec(root): Fatal: failed to compile sieve script '/var/vmail/$DOMAIN/$USERNAME/.ispconfig-before.sieve'
    Then when I try to send a mail, none of the filters are applied due to the invalid syntax...

    2025-07-08T10:40:30.067099+02:00 server1 dovecot: lmtp($USERNAME@$DOMAIN)<2386636><0PzUA37ZbGjMaiQAw4QwzQ>: Error: sieve: Failed to compile script `/var/vmail/$USERNAME/$DOMAIN/.ispconfig-before.sieve'​

    As far as I can tell "(?i)spamjunk" should be valid regex syntax to match a word in a subject but case insensitive, if this isn't the regex that should be used here - please confirm what should be - when running this through chatgpt independently it says that the rule that it generates...

    if header :regex "subject" ["(?i)spamjunk"] {
    discard;
    stop;
    }
    Should look like this instead...

    if header :regex :comparator "i;ascii-casemap" "subject" ["spamjunk"] {
    discard;
    stop;
    }
    If that is the case that would need updating from the ispconfig side I believe?

    Any help or guidance appreciated, sure I can't be the first person to encounter this.
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    There are different implementations of Regex engines and the one from Dovecot does not support inline flags, so you can not use (?i) in Dovecot.

    You could try using "contains" instead or "regex" with word "spamjunk" as the contains comparator is case insensitive in most dovecot implementations. If you want to use Regex, you could use kind of brute force match like:

    Code:
    [sS][pP][aA][mM][jJ][uU][nN][kK]
     
  3. cajdavidson

    cajdavidson New Member HowtoForge Supporter

    Ok, perfect, thanks Till. That has solved my problem for now - as a future feature request it would be good to have this syntax checked and not applied (especially when a non-admin user can generate these rules) as if a non-valid rule can be added then it breaks all filtering in the sieve files.
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    I'll add this to our issue tracker.
     

Share This Page