Reference Manuals

SpamRules

SpamRules — A rule-based spamfilter that can work with SpamAssassin's .cf rules

SpamRules is part of the SpamFilter package.

Synopsis

class SpamRules {
        private        array               $configs
        private        array               $errors
        private        array               $evals
        public         bool                $local_tests_only
        private        mixed               $re_dquote
        private        mixed               $re_eval
        private        mixed               $re_function
        private        mixed               $re_number
        private        mixed               $re_param
        private        mixed               $re_parens
        private        mixed               $re_quote
        private        mixed               $re_squote
        private        array               $rules
        public         string              $rules_filename
        private        The                 $score_type
        private        array               $state
        private        array               $tests
        public         bool                $use_bayes

        private        void                body                      ( string $test );
        public         float               check                     ( string $message,
                                                                       array &$matched_tests,
                                                                       bool $all_tests );
        private        void                describe                  ( string $rule );
        public         mixed               get_errors                ( void );
        public         array               get_state                 ( void );
        public         void                init                      ( void );
        private        void                loadplugin                ( string $plugin );
        private        void                meta                      ( string $test );
        private        void                parse_line                ( string $line );
        public         void                register_config           ( string $config_name,
                                                                       mixed &$config_variable );
        public         void                register_eval             ( string $eval_name,
                                                                       callback &$callback );
        public         void                register_rule             ( string $rule_name,
                                                                       callback &$callback );
        private        void                score                     ( string $rule );
        private        array               split_line                ( string $line,
                                                                       int $num_words );
        private        bool                test                      ( string &$message,
                                                                       string $test );
}

Object Hierarchy

SpamRules

Description

A rule-based spamfilter that can work with SpamAssassin's .cf rules

Attribute Details

$configs

private        array          $configs

An array containing all registered config variables

Default value: empty string


$errors

private        array          $errors

An array containing the tests that causes preg_match errors in the last run.

Default value: empty string


$evals

private        array          $evals

An array containing all registered eval functions

Default value: empty string


$local_tests_only

public         bool           $local_tests_only

If enabled, tests flagged with 'net' will be skipped

Default value: empty string


$re_dquote

private        mixed          $re_dquote

Internal regular expression

Default value: empty string


$re_eval

private        mixed          $re_eval

Internal regular expression

Default value: empty string


$re_function

private        mixed          $re_function

Internal regular expression

Default value: empty string


$re_number

private        mixed          $re_number

Internal regular expression

Default value: empty string


$re_param

private        mixed          $re_param

Internal regular expression

Default value: empty string


$re_parens

private        mixed          $re_parens

Internal regular expression

Default value: empty string


$re_quote

private        mixed          $re_quote

Internal regular expression

Default value: empty string


$re_squote

private        mixed          $re_squote

Internal regular expression

Default value: empty string


$rules

private        array          $rules

An array containing all the registered extra rules

Default value: empty string


$rules_filename

public         string         $rules_filename

Path to the filename or directory containing the .cf rule files. Note that you should *not* simply set this to the path in your SpamAssassin installation. Comment spam is a different beast than e-mail spam. There are many rules in SpamAssassin that should not be used. Instead, simply copy the .cf files you want to a different directory or symlink them.

Default value: empty string


$score_type

private        The            $score_type

scoring type to use. This depends on the values of $use_bayes and $local_tests_only

Default value: empty string


$state

private        array          $state

An array containing the state of all the tests.

Default value: empty string


$tests

private        array          $tests

A list containing all the tests.

Default value: empty string


$use_bayes

public         bool           $use_bayes

Enable/disbale baysian filters

Default value: empty string

Method Details

body()

private        void           body                      ( string $test );

Parse a 'body' test.

$test
The test to parse

check()

public         float          check                     ( string $message,
                                                          array &$matched_tests,
                                                          bool $all_tests );

Run all tests on a message

If you want to know exactly which tests were triggered and how much each test contributed to the final score the set the $matched_tests parameter. By default, tests that start with __ are skipped because these are internal tests used in various meta tests. Set $all_tests to TRUE to match against these tests as well so that they are returned in the $matched_tests array. This is useful for debugging meta tests.

$message
The message to scan
&$matched_tests
An array containing the tests that matched successfully
$all_tests
Check internal tests

describe()

private        void           describe                  ( string $rule );

Parse a 'describe' rule.

$rule
The rule to parse

get_errors()

public         mixed          get_errors                ( void );

Returns an array of the tests that causes PCRE errors in the last run


get_state()

public         array          get_state                 ( void );

Returns an array containing the internal state for the last check.

This is purely for debugging purposes.


init()

public         void           init                      ( void );

Load all the SpamAssasin rules from file


loadplugin()

private        void           loadplugin                ( string $plugin );

Load a plugin

$plugin
The name of the plugin to load

meta()

private        void           meta                      ( string $test );

Parse a 'meta' test.

$test
The test to parse

parse_line()

private        void           parse_line                ( string $line );

Parse a single cf line

$line
The line to parse

register_config()

public         void           register_config           ( string $config_name,
                                                          mixed &$config_variable );

Register a new config variable.

$config_name
The name of the config variable
&$config_variable
A reference to the config variable that will be set

register_eval()

public         void           register_eval             ( string $eval_name,
                                                          callback &$callback );

Register a new eval function.

$eval_name
The name of the eval function
&$callback
A callback to the actual function that will be called

register_rule()

public         void           register_rule             ( string $rule_name,
                                                          callback &$callback );

Register a new rule.

$rule_name
The name of the rule
&$callback
A callback to the actual function that will be called

score()

private        void           score                     ( string $rule );

Parse a 'score' rule.

$rule
The rule to parse

split_line()

private        array          split_line                ( string $line,
                                                          int $num_words );

Break a line down in words

This function will always return an array of size $num_words, so it's safe to use in combination with the list() function. The array elements will contain the words in the line, except for the last element. That will contain the remainder of the line. Example:list($word_1, $word_2, $remainder) = $this->split_line("This is a sentence", 3);$word_1 is "This" $word_2 is "is" $remainder is "a sentence"A "word" here is either a perl word, a string in single or double quotes, or a literal number.

$line
A line of text
$num_words
The number of words to split the line in

test()

private        bool           test                      ( string &$message,
                                                          string $test );

Run a test on a message

&$message
The message to scan
$test
The name of the test