Lines 88-106
Link Here
|
88 |
@MIGRATED_SETTINGS |
88 |
@MIGRATED_SETTINGS |
89 |
|
89 |
|
90 |
$TYPE_HEAD_TESTS $TYPE_HEAD_EVALS |
90 |
$TYPE_HEAD_TESTS $TYPE_HEAD_EVALS |
91 |
$TYPE_BODY_TESTS $TYPE_BODY_EVALS $TYPE_FULL_TESTS $TYPE_FULL_EVALS |
91 |
$TYPE_FULL_TESTS $TYPE_FULL_EVALS |
92 |
$TYPE_RAWBODY_TESTS $TYPE_RAWBODY_EVALS $TYPE_URI_TESTS $TYPE_URI_EVALS |
92 |
$TYPE_RAWBODY_TESTS $TYPE_RAWBODY_EVALS $TYPE_URI_TESTS $TYPE_URI_EVALS |
93 |
$TYPE_META_TESTS $TYPE_RBL_EVALS |
93 |
$TYPE_META_TESTS $TYPE_RBL_EVALS |
|
|
94 |
|
95 |
$AUTOLEARN_NONE $AUTOLEARN_HEAD $AUTOLEARN_BODY $AUTOLEARN_META |
94 |
}; |
96 |
}; |
95 |
|
97 |
|
96 |
@ISA = qw(); |
98 |
@ISA = qw(); |
97 |
|
99 |
|
|
|
100 |
#BUG4778: below to be removed |
98 |
# odd => eval test. Not constants so they can be shared with Parser |
101 |
# odd => eval test. Not constants so they can be shared with Parser |
99 |
# TODO: move to Constants.pm? |
102 |
# TODO: move to Constants.pm? |
100 |
$TYPE_HEAD_TESTS = 0x0008; |
103 |
$TYPE_HEAD_TESTS = 0x0008; |
101 |
$TYPE_HEAD_EVALS = 0x0009; |
104 |
$TYPE_HEAD_EVALS = 0x0009; |
102 |
$TYPE_BODY_TESTS = 0x000a; |
|
|
103 |
$TYPE_BODY_EVALS = 0x000b; |
104 |
$TYPE_FULL_TESTS = 0x000c; |
105 |
$TYPE_FULL_TESTS = 0x000c; |
105 |
$TYPE_FULL_EVALS = 0x000d; |
106 |
$TYPE_FULL_EVALS = 0x000d; |
106 |
$TYPE_RAWBODY_TESTS = 0x000e; |
107 |
$TYPE_RAWBODY_TESTS = 0x000e; |
Lines 110-120
Link Here
|
110 |
$TYPE_META_TESTS = 0x0012; |
111 |
$TYPE_META_TESTS = 0x0012; |
111 |
$TYPE_RBL_EVALS = 0x0013; |
112 |
$TYPE_RBL_EVALS = 0x0013; |
112 |
|
113 |
|
113 |
my @rule_types = ("body_tests", "uri_tests", "uri_evals", |
114 |
my @rule_types = ("body_tests_obsolete", "uri_tests", "uri_evals", |
114 |
"head_tests", "head_evals", "body_evals", "full_tests", |
115 |
"head_tests", "head_evals", "body_evals_obsolete", "full_tests", |
115 |
"full_evals", "rawbody_tests", "rawbody_evals", |
116 |
"full_evals", "rawbody_tests", "rawbody_evals", |
116 |
"rbl_evals", "meta_tests"); |
117 |
"rbl_evals", "meta_tests"); |
|
|
118 |
#BUG4778: above to be removed |
117 |
|
119 |
|
|
|
120 |
$AUTOLEARN_NONE = 0; |
121 |
$AUTOLEARN_HEAD = 1; |
122 |
$AUTOLEARN_BODY = 2; |
123 |
$AUTOLEARN_META = 3; |
124 |
|
118 |
$VERSION = 'bogus'; # avoid CPAN.pm picking up version strings later |
125 |
$VERSION = 'bogus'; # avoid CPAN.pm picking up version strings later |
119 |
|
126 |
|
120 |
# these are variables instead of constants so that other classes can |
127 |
# these are variables instead of constants so that other classes can |
Lines 1943-1986
Link Here
|
1943 |
} |
1950 |
} |
1944 |
}); |
1951 |
}); |
1945 |
|
1952 |
|
1946 |
=item body SYMBOLIC_TEST_NAME /pattern/modifiers |
|
|
1947 |
|
1948 |
Define a body pattern test. C<pattern> is a Perl regular expression. Note: |
1949 |
as per the header tests, C<#> must be escaped (C<\#>) or else it is considered |
1950 |
the beginning of a comment. |
1951 |
|
1952 |
The 'body' in this case is the textual parts of the message body; |
1953 |
any non-text MIME parts are stripped, and the message decoded from |
1954 |
Quoted-Printable or Base-64-encoded format if necessary. The message |
1955 |
Subject header is considered part of the body and becomes the first |
1956 |
paragraph when running the rules. All HTML tags and line breaks will |
1957 |
be removed before matching. |
1958 |
|
1959 |
=item body SYMBOLIC_TEST_NAME eval:name_of_eval_method([args]) |
1960 |
|
1961 |
Define a body eval test. See above. |
1962 |
|
1963 |
=cut |
1964 |
|
1965 |
push (@cmds, { |
1966 |
setting => 'body', |
1967 |
is_frequent => 1, |
1968 |
is_priv => 1, |
1969 |
code => sub { |
1970 |
my ($self, $key, $value, $line) = @_; |
1971 |
if ($value =~ /^(\S+)\s+eval:(.*)$/) { |
1972 |
$self->{parser}->add_test ($1, $2, $TYPE_BODY_EVALS); |
1973 |
} |
1974 |
else { |
1975 |
my @values = split(/\s+/, $value, 2); |
1976 |
if (@values != 2) { |
1977 |
return $MISSING_REQUIRED_VALUE; |
1978 |
} |
1979 |
$self->{parser}->add_test (@values, $TYPE_BODY_TESTS); |
1980 |
} |
1981 |
} |
1982 |
}); |
1983 |
|
1984 |
=item uri SYMBOLIC_TEST_NAME /pattern/modifiers |
1953 |
=item uri SYMBOLIC_TEST_NAME /pattern/modifiers |
1985 |
|
1954 |
|
1986 |
Define a uri pattern test. C<pattern> is a Perl regular expression. Note: as |
1955 |
Define a uri pattern test. C<pattern> is a Perl regular expression. Note: as |
Lines 2822-2833
Link Here
|
2822 |
# after parsing, tests are refiled into these hashes for each test type. |
2791 |
# after parsing, tests are refiled into these hashes for each test type. |
2823 |
# this allows e.g. a full-text test to be rewritten as a body test in |
2792 |
# this allows e.g. a full-text test to be rewritten as a body test in |
2824 |
# the user's user_prefs file. |
2793 |
# the user's user_prefs file. |
2825 |
$self->{body_tests} = { }; |
|
|
2826 |
$self->{uri_tests} = { }; |
2794 |
$self->{uri_tests} = { }; |
2827 |
$self->{uri_evals} = { }; # not used/implemented yet |
2795 |
$self->{uri_evals} = { }; # not used/implemented yet |
2828 |
$self->{head_tests} = { }; |
2796 |
$self->{head_tests} = { }; |
2829 |
$self->{head_evals} = { }; |
2797 |
$self->{head_evals} = { }; |
2830 |
$self->{body_evals} = { }; |
|
|
2831 |
$self->{full_tests} = { }; |
2798 |
$self->{full_tests} = { }; |
2832 |
$self->{full_evals} = { }; |
2799 |
$self->{full_evals} = { }; |
2833 |
$self->{rawbody_tests} = { }; |
2800 |
$self->{rawbody_tests} = { }; |
Lines 2912-2922
Link Here
|
2912 |
return $self->{scoreset_current}; |
2879 |
return $self->{scoreset_current}; |
2913 |
} |
2880 |
} |
2914 |
|
2881 |
|
|
|
2882 |
#BUG4778: function to be removed |
2915 |
sub get_rule_types { |
2883 |
sub get_rule_types { |
2916 |
my ($self) = @_; |
2884 |
my ($self) = @_; |
2917 |
return @rule_types; |
2885 |
return @rule_types; |
2918 |
} |
2886 |
} |
2919 |
|
2887 |
|
|
|
2888 |
#BUG4778: function to be removed |
2920 |
sub get_rule_keys { |
2889 |
sub get_rule_keys { |
2921 |
my ($self, $test_type, $priority) = @_; |
2890 |
my ($self, $test_type, $priority) = @_; |
2922 |
|
2891 |
|
Lines 2937-2942
Link Here
|
2937 |
} |
2906 |
} |
2938 |
} |
2907 |
} |
2939 |
|
2908 |
|
|
|
2909 |
#BUG4778: function to be removed |
2940 |
sub get_rule_value { |
2910 |
sub get_rule_value { |
2941 |
my ($self, $test_type, $rulename, $priority) = @_; |
2911 |
my ($self, $test_type, $rulename, $priority) = @_; |
2942 |
|
2912 |
|
Lines 2984-2989
Link Here
|
2984 |
# Remove all rules that don't match the given regexp (or are sub-rules of |
2954 |
# Remove all rules that don't match the given regexp (or are sub-rules of |
2985 |
# meta-tests that match the regexp). |
2955 |
# meta-tests that match the regexp). |
2986 |
|
2956 |
|
|
|
2957 |
#BUG4778: below to be reimplemented |
2987 |
sub trim_rules { |
2958 |
sub trim_rules { |
2988 |
my ($self, $regexp) = @_; |
2959 |
my ($self, $regexp) = @_; |
2989 |
|
2960 |
|
Lines 3019-3024
Link Here
|
3019 |
} |
2990 |
} |
3020 |
} # trim_rules() |
2991 |
} # trim_rules() |
3021 |
|
2992 |
|
|
|
2993 |
#BUG4778: function to be moved into meta rule type plugin and/or reimplemented |
3022 |
sub add_meta_depends { |
2994 |
sub add_meta_depends { |
3023 |
my ($self, $meta) = @_; |
2995 |
my ($self, $meta) = @_; |
3024 |
|
2996 |
|
Lines 3042-3073
Link Here
|
3042 |
} # add_meta_depends() |
3014 |
} # add_meta_depends() |
3043 |
|
3015 |
|
3044 |
sub is_rule_active { |
3016 |
sub is_rule_active { |
3045 |
my ($self, $test_type, $rulename, $priority) = @_; |
3017 |
my ($self, $rulename) = @_; |
3046 |
|
3018 |
|
3047 |
# special case rbl_evals since they do not have a priority |
3019 |
return 0 unless $self->{source_file}->{$rulename}; |
3048 |
if ($test_type eq 'rbl_evals') { |
|
|
3049 |
return 0 unless ($self->{$test_type}->{$rulename}); |
3050 |
return ($self->{scores}->{$rulename}); |
3051 |
} |
3052 |
|
3020 |
|
3053 |
# first determine if the rule is defined |
|
|
3054 |
if (defined($priority)) { |
3055 |
# we have a specific priority |
3056 |
return 0 unless ($self->{$test_type}->{$priority}->{$rulename}); |
3057 |
} |
3058 |
else { |
3059 |
# no specific priority so we must loop over all currently defined |
3060 |
# priorities to see if the rule is defined |
3061 |
my $found_p = 0; |
3062 |
foreach my $pri (keys %{$self->{priorities}}) { |
3063 |
if ($self->{$test_type}->{$pri}->{$rulename}) { |
3064 |
$found_p = 1; |
3065 |
last; |
3066 |
} |
3067 |
} |
3068 |
return 0 unless ($found_p); |
3069 |
} |
3070 |
|
3071 |
return ($self->{scores}->{$rulename}); |
3021 |
return ($self->{scores}->{$rulename}); |
3072 |
} |
3022 |
} |
3073 |
|
3023 |
|
Lines 3112-3124
Link Here
|
3112 |
|
3062 |
|
3113 |
sub maybe_header_only { |
3063 |
sub maybe_header_only { |
3114 |
my($self,$rulename) = @_; |
3064 |
my($self,$rulename) = @_; |
3115 |
my $type = $self->{test_types}->{$rulename}; |
3065 |
my $autolearn = $self->{autolearn}->{$rulename}; |
3116 |
return 0 if (!defined ($type)); |
3066 |
return 0 if (!defined ($autolearn)); |
3117 |
|
3067 |
|
3118 |
if (($type == $TYPE_HEAD_TESTS) || ($type == $TYPE_HEAD_EVALS)) { |
3068 |
if ($autolearn == $AUTOLEARN_HEAD) { |
3119 |
return 1; |
3069 |
return 1; |
3120 |
|
3070 |
|
3121 |
} elsif ($type == $TYPE_META_TESTS) { |
3071 |
} elsif ($autolearn == $AUTOLEARN_META) { |
3122 |
my $tflags = $self->{tflags}->{$rulename}; $tflags ||= ''; |
3072 |
my $tflags = $self->{tflags}->{$rulename}; $tflags ||= ''; |
3123 |
if ($tflags =~ m/\bnet\b/i) { |
3073 |
if ($tflags =~ m/\bnet\b/i) { |
3124 |
return 0; |
3074 |
return 0; |
Lines 3132-3147
Link Here
|
3132 |
|
3082 |
|
3133 |
sub maybe_body_only { |
3083 |
sub maybe_body_only { |
3134 |
my($self,$rulename) = @_; |
3084 |
my($self,$rulename) = @_; |
3135 |
my $type = $self->{test_types}->{$rulename}; |
3085 |
my $autolearn = $self->{autolearn}->{$rulename}; |
3136 |
return 0 if (!defined ($type)); |
3086 |
return 0 if (!defined ($autolearn)); |
3137 |
|
3087 |
|
3138 |
if (($type == $TYPE_BODY_TESTS) || ($type == $TYPE_BODY_EVALS) |
3088 |
if ($autolearn == $AUTOLEARN_BODY) { |
3139 |
|| ($type == $TYPE_URI_TESTS) || ($type == $TYPE_URI_EVALS)) |
|
|
3140 |
{ |
3141 |
# some rawbody go off of headers... |
3142 |
return 1; |
3089 |
return 1; |
3143 |
|
3090 |
|
3144 |
} elsif ($type == $TYPE_META_TESTS) { |
3091 |
} elsif ($autolearn == $AUTOLEARN_META) { |
3145 |
my $tflags = $self->{tflags}->{$rulename}; $tflags ||= ''; |
3092 |
my $tflags = $self->{tflags}->{$rulename}; $tflags ||= ''; |
3146 |
if ($tflags =~ m/\bnet\b/i) { |
3093 |
if ($tflags =~ m/\bnet\b/i) { |
3147 |
return 0; |
3094 |
return 0; |