2
# Licensed to the Apache Software Foundation (ASF) under one or more
3
# contributor license agreements. See the NOTICE file distributed with
4
# this work for additional information regarding copyright ownership.
5
# The ASF licenses this file to you under the Apache License, Version 2.0
6
# (the "License"); you may not use this file except in compliance with
7
# the License. You may obtain a copy of the License at:
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
20
Mail::SpamAssassin::Bayes - support for learning classifiers
24
This is the general class used to train a learning classifier with new samples
25
of spam and ham mail, and classify based on prior training.
27
Prior to version 3.3.0, the default Bayes implementation was here; if you're
28
looking for information on that, it has moved to
29
C<Mail::SpamAssassin::Plugin::Bayes>.
33
package Mail::SpamAssassin::Bayes;
40
use Mail::SpamAssassin;
41
use Mail::SpamAssassin::PerMsgStatus;
42
use Mail::SpamAssassin::Logger;
43
use Mail::SpamAssassin::Util qw(untaint_var);
47
###########################################################################
51
$class = ref($class) || $class;
56
'conf' => $main->{conf},
59
bless ($self, $class);
61
$self->{main}->call_plugins("learner_new");
65
###########################################################################
69
# we don't need to do the plugin; Mail::SpamAssassin::finish() does
74
###########################################################################
76
# force the Bayes dbs to be closed, if they haven't already been; called
77
# at the end of scan operation, or when switching between user IDs,
78
# or when C<Mail::SpamAssassin::finish_learner()> is called.
83
$self->{main}->call_plugins("learner_close", { quiet => $quiet });
86
###########################################################################
91
return 0 unless $self->{use_ignores};
93
my $ig_from = $self->{main}->call_plugins ("check_wb_list",
94
{ permsgstatus => $PMS, type => 'from', list => 'bayes_ignore_from' });
95
my $ig_to = $self->{main}->call_plugins ("check_wb_list",
96
{ permsgstatus => $PMS, type => 'to', list => 'bayes_ignore_to' });
98
my $ignore = $ig_from || $ig_to;
99
dbg("bayes: not using bayes, bayes_ignore_from or _to rule") if $ignore;
103
###########################################################################
106
my ($self, $isspam, $msg, $id) = @_;
107
return unless $self->{conf}->{use_learner};
108
return unless defined $msg;
110
if( $self->{use_ignores} ) # Remove test when PerMsgStatus available.
112
# DMK, koppel@ece.lsu.edu: Hoping that the ultimate fix to bug 2263 will
113
# make it unnecessary to construct a PerMsgStatus here.
114
my $PMS = new Mail::SpamAssassin::PerMsgStatus $self->{main}, $msg;
115
my $ignore = $self->ignore_message($PMS);
120
return $self->{main}->call_plugins("learn_message", { isspam => $isspam, msg => $msg, id => $id });
123
###########################################################################
126
my ($self, $msg, $id) = @_;
127
return unless $self->{conf}->{use_learner};
128
return unless defined $msg;
129
return $self->{main}->call_plugins("forget_message", { msg => $msg, id => $id });
132
###########################################################################
135
my ($self, $sync, $expire, $opts) = @_;
136
return 0 unless $self->{conf}->{use_learner};
139
$self->{main}->call_plugins("learner_sync", $opts );
142
$self->{main}->call_plugins("learner_expire_old_training", $opts );
148
###########################################################################
150
sub is_scan_available {
152
return 0 unless $self->{conf}->{use_learner};
153
return $self->{main}->call_plugins("learner_is_scan_available");
156
###########################################################################
159
my($self, $magic, $toks, $regex) = @_;
160
return 0 unless $self->{conf}->{use_learner};
161
return $self->{main}->call_plugins("learner_dump_database", {
162
magic => $magic, toks => $toks, regex => $regex });