[Mimedefang] local rule with wildcard checking subject
Bill Cole
mdlist-20140424 at billmail.scconsult.com
Tue Oct 16 17:36:26 EDT 2018
On 16 Oct 2018, at 4:21, MAYER Hans wrote:
> Dear All,
>
> I am using mimedefang version 2.79 in combination with SpamAssassin.
> I have several rules defined in /etc/mail/sa-mimedefang.cf which all
> works fine.
> Now I tried to define a rule testing a subject with a wildcard.
> But all my tests failed. Is there a way to define a wildcard checking
> the subject line ?
> I also had an issue to escape the '#' character. Any idea how to do ?
>
> Any help is welcome.
This is really better suited to the SpamAssassin Users List (see
https://wiki.apache.org/spamassassin/MailingLists) but it seems simple
enough that I expect Dianne won't mind an answer here...
The file /etc/mail/sa-mimedefang.cf is a SpamAssassin config file, so
all its directives are SA directives and all rules are SA rules. As
such, they use Perl regular expressions (a.k.a. "regex") for pattern
matching. If you are unfamiliar with regular expressions, 'man 7 regex'
on Linux or 'man 7 re_format' on MacOS or any of the *BSDs will give you
the standard for regex and 'man perlre' for the Perl variations.
To illustrate an answer to your wildcard question, here's the definition
of a rule named "SCC_STOCK_ROCK" that I once found useful:
describe SCC_STOCK_ROCK Skater dood wording for stock tips
header SCC_STOCK_ROCK Subject =~ /St0ck .* R0ck/
score SCC_STOCK_ROCK 2.0
Technically the 'describe' and 'score' lines are optional, with the
default score of a rule being 1.0.
The 'header' line is the meat. There are 3 parts after the rule name:
1. "Subject" is the name of the header to be matched.
2. "=~" is the Perl regular expression match operator.
3. "/St0ck .* R0ck/" is a regular expression delimited by '/'.
The '.*' in that regex means any character (.) repeated any number of
times (*) and because the regex. is not "anchored" at either end there's
an implied '.*' before and after it, so the whole regex would match any
of these:
Subject: H0t St0ck that's sure to R0ck!!!
Subject: St0ck will R0ck
Subject: St0ck R0ck!!!
Note the 2 spaces in the last one...
It would NOT match:
Subject: St0ck R0ck
Subject: St0cks that R0ck
The '#' character is a Perl metacharacter (marking the start of a
comment) so it needs to be escaped with a preceding backslash (\) as
does any other Perl metacharacter (notably % and @) and any character
that can have special meaning in regex syntax: ./(){}[]&^$?+*\|
More information about the MIMEDefang
mailing list