Search code examples
regexperlspamassassin

Spamassassin regex header rule not working


I'm new to Spamassassin, regex and Perl, so I'd appreciate some help. I was trying to add a spam score to all emails whose senders follow a certain pattern, namely: [email protected]. This is what I came up with

header NAME_DOT_SURNAME_DOT_FQDN From=~((?:[a-z]+))(\\.)((?:[a-z]+))(\\.)(@)((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-]+))(?![\\w\\.])
score NAME_DOT_SURNAME_DOT_FQDN 3.0

However, it doesn't seem to be working. When I run spamassassin --lint i get the following output:

Feb 12 12:52:59.521 [32767] warn: Use of ?PATTERN? without explicit operator is deprecated at /etc/spamassassin/local.cf, rule NAME_DOT_SURNAME_DOT_FQDN, line 1.
Feb 12 12:52:59.522 [32767] warn: rules: failed to compile Mail::SpamAssassin::Plugin::Check::_head_tests_0_3, skipping:
Feb 12 12:52:59.522 [32767] warn:  (Unmatched ) in regex; marked by <-- HERE in m/: [...][a-z]+) <-- HERE )(\\.)((/ at /etc/spamassassin/local.cf, rule NAME_DOT_SURNAME_DOT_FQDN, line 1.)
Feb 12 12:52:59.620 [32767] warn: lint: 1 issues detected, please rerun with debug enabled for more information

Running spamassassin --lint -D just produces a wall of text that contains the same error. Can anyone please point me to the right direction? Thanks in advance.


Solution

  • I don't know SpamAssassin, but could it be that it requires / / around the regex?

    Because the error message indicates Perl is treating ? as the regex delimiter, leading to a regex of:

    ?:[a-z]+))(\\.)((?
    #-------^ unmatched ')'
    

    So what I'd try is:

    header NAME_DOT_SURNAME_DOT_FQDN From=~/((?:[a-z]+))(\\.)((?:[a-z]+))(\\.)(@)((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-]+))(?![\\w\\.])/
    

    Also, those doubled backslashes look suspicious. Are you sure you don't mean e.g. \w instead of \\w?