SpamRules — A rule-based spamfilter that can work with SpamAssassin's .cf rules
SpamRules is part of the SpamFilter package.
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 ); }
SpamRules
A rule-based spamfilter that can work with SpamAssassin's .cf rules
private array $configs
An array containing all registered config variables
Default value: empty string
private array $errors
An array containing the tests that causes preg_match errors in the last run.
Default value: empty string
private array $evals
An array containing all registered eval functions
Default value: empty string
public bool $local_tests_only
If enabled, tests flagged with 'net' will be skipped
Default value: empty string
private mixed $re_dquote
Internal regular expression
Default value: empty string
private mixed $re_eval
Internal regular expression
Default value: empty string
private mixed $re_function
Internal regular expression
Default value: empty string
private mixed $re_number
Internal regular expression
Default value: empty string
private mixed $re_param
Internal regular expression
Default value: empty string
private mixed $re_parens
Internal regular expression
Default value: empty string
private mixed $re_quote
Internal regular expression
Default value: empty string
private mixed $re_squote
Internal regular expression
Default value: empty string
private array $rules
An array containing all the registered extra rules
Default value: empty string
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
private The $score_type
scoring type to use. This depends on the values of $use_bayes and $local_tests_only
Default value: empty string
private array $state
An array containing the state of all the tests.
Default value: empty string
private array $tests
A list containing all the tests.
Default value: empty string
public bool $use_bayes
Enable/disbale baysian filters
Default value: empty string
private void body ( string $test );
Parse a 'body' test.
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.
private void describe ( string $rule );
Parse a 'describe' rule.
public mixed get_errors ( void );
Returns an array of the tests that causes PCRE errors in the last run
public array get_state ( void );
Returns an array containing the internal state for the last check.
This is purely for debugging purposes.
public void init ( void );
Load all the SpamAssasin rules from file
private void loadplugin ( string $plugin );
Load a plugin
private void meta ( string $test );
Parse a 'meta' test.
private void parse_line ( string $line );
Parse a single cf line
public void register_config ( string $config_name, mixed &$config_variable );
Register a new config variable.
public void register_eval ( string $eval_name, callback &$callback );
Register a new eval function.
public void register_rule ( string $rule_name, callback &$callback );
Register a new rule.
private void score ( string $rule );
Parse a 'score' rule.
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.
private bool test ( string &$message, string $test );
Run a test on a message