| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# <@LICENSE> |
|
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: |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
|
|
|
|
# |
|
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. |
|
16
|
|
|
|
|
|
|
# </@LICENSE> |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Mail::SpamAssassin::PerMsgLearner - per-message status (spam or not-spam) |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $spamtest = new Mail::SpamAssassin ({ |
|
25
|
|
|
|
|
|
|
'rules_filename' => '/etc/spamassassin.rules', |
|
26
|
|
|
|
|
|
|
'userprefs_filename' => $ENV{HOME}.'/.spamassassin/user_prefs' |
|
27
|
|
|
|
|
|
|
}); |
|
28
|
|
|
|
|
|
|
my $mail = $spamtest->parse(); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $status = $spamtest->learn($mail,$id,$isspam,$forget); |
|
31
|
|
|
|
|
|
|
my $didlearn = $status->did_learn(); |
|
32
|
|
|
|
|
|
|
$status->finish(); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The Mail::SpamAssassin C<learn()> method returns an object of this |
|
38
|
|
|
|
|
|
|
class. This object encapsulates all the per-message state for |
|
39
|
|
|
|
|
|
|
the learning process. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 METHODS |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
use strict; |
|
49
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
30
|
|
|
50
|
1
|
|
|
1
|
|
5
|
# use bytes; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
60
|
|
|
51
|
|
|
|
|
|
|
use re 'taint'; |
|
52
|
1
|
|
|
1
|
|
7
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
35
|
|
|
53
|
|
|
|
|
|
|
use Mail::SpamAssassin; |
|
54
|
1
|
|
|
1
|
|
7
|
use Mail::SpamAssassin::PerMsgStatus; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
28
|
|
|
55
|
1
|
|
|
1
|
|
5
|
use Mail::SpamAssassin::Bayes; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
17
|
|
|
56
|
1
|
|
|
1
|
|
5
|
use Mail::SpamAssassin::Logger; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
57
|
1
|
|
|
1
|
|
6
|
|
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
386
|
|
|
58
|
|
|
|
|
|
|
our @ISA = qw(); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
########################################################################### |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $class = shift; |
|
63
|
|
|
|
|
|
|
$class = ref($class) || $class; |
|
64
|
2
|
|
|
2
|
0
|
5
|
my ($main, $msg) = @_; |
|
65
|
2
|
|
33
|
|
|
9
|
|
|
66
|
2
|
|
|
|
|
5
|
my $self = { |
|
67
|
|
|
|
|
|
|
'main' => $main, |
|
68
|
|
|
|
|
|
|
'msg' => $msg, |
|
69
|
|
|
|
|
|
|
'learned' => 0, |
|
70
|
|
|
|
|
|
|
'master_deadline' => $msg->{master_deadline}, # dflt inherited from msg |
|
71
|
|
|
|
|
|
|
}; |
|
72
|
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
11
|
$self->{conf} = $self->{main}->{conf}; |
|
74
|
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
5
|
$self->{bayes_scanner} = $self->{main}->{bayes_scanner}; |
|
76
|
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
5
|
bless ($self, $class); |
|
78
|
|
|
|
|
|
|
$self; |
|
79
|
2
|
|
|
|
|
5
|
} |
|
80
|
2
|
|
|
|
|
5
|
|
|
81
|
|
|
|
|
|
|
########################################################################### |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# $status->learn_spam($id) |
|
84
|
|
|
|
|
|
|
# |
|
85
|
|
|
|
|
|
|
# Learn the message as spam. |
|
86
|
|
|
|
|
|
|
# |
|
87
|
|
|
|
|
|
|
# C<$id> is an optional message-identification string, used internally |
|
88
|
|
|
|
|
|
|
# to tag the message. If it is C<undef>, one will be generated. |
|
89
|
|
|
|
|
|
|
# It should be unique to that message. |
|
90
|
|
|
|
|
|
|
# |
|
91
|
|
|
|
|
|
|
# This is a semi-private API; callers should use |
|
92
|
|
|
|
|
|
|
# C<$spamtest-E<gt>learn($mail,$id,$isspam,$forget)> instead. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my ($self, $id) = @_; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# bug 4096 |
|
97
|
0
|
|
|
0
|
0
|
0
|
# if ($self->{main}->{learn_with_whitelist}) { |
|
98
|
|
|
|
|
|
|
# $self->{main}->add_all_addresses_to_blacklist ($self->{msg}); |
|
99
|
|
|
|
|
|
|
# } |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# use the real message-id here instead of mass-check's idea of an "id", |
|
102
|
|
|
|
|
|
|
# as we may deliver the msg into another mbox format but later need |
|
103
|
|
|
|
|
|
|
# to forget it's training. |
|
104
|
|
|
|
|
|
|
$self->{learned} = $self->{bayes_scanner}->learn (1, $self->{msg}, $id); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
########################################################################### |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# $status->learn_ham($id) |
|
110
|
|
|
|
|
|
|
# |
|
111
|
|
|
|
|
|
|
# Learn the message as ham. |
|
112
|
|
|
|
|
|
|
# |
|
113
|
|
|
|
|
|
|
# C<$id> is an optional message-identification string, used internally |
|
114
|
|
|
|
|
|
|
# to tag the message. If it is C<undef>, one will be generated. |
|
115
|
|
|
|
|
|
|
# It should be unique to that message. |
|
116
|
|
|
|
|
|
|
# |
|
117
|
|
|
|
|
|
|
# This is a semi-private API; callers should use |
|
118
|
|
|
|
|
|
|
# C<$spamtest-E<gt>learn($mail,$id,$isspam,$forget)> instead. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my ($self, $id) = @_; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# bug 4096 |
|
123
|
|
|
|
|
|
|
# if ($self->{main}->{learn_with_whitelist}) { |
|
124
|
2
|
|
|
2
|
0
|
4
|
# $self->{main}->add_all_addresses_to_whitelist ($self->{msg}); |
|
125
|
|
|
|
|
|
|
# } |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
$self->{learned} = $self->{bayes_scanner}->learn (0, $self->{msg}, $id); |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
########################################################################### |
|
131
|
2
|
|
|
|
|
15
|
|
|
132
|
|
|
|
|
|
|
# $status->forget($id) |
|
133
|
|
|
|
|
|
|
# |
|
134
|
|
|
|
|
|
|
# Forget about a previously-learned message. |
|
135
|
|
|
|
|
|
|
# |
|
136
|
|
|
|
|
|
|
# C<$id> is an optional message-identification string, used internally |
|
137
|
|
|
|
|
|
|
# to tag the message. If it is C<undef>, one will be generated. |
|
138
|
|
|
|
|
|
|
# It should be unique to that message. |
|
139
|
|
|
|
|
|
|
# |
|
140
|
|
|
|
|
|
|
# This is a semi-private API; callers should use |
|
141
|
|
|
|
|
|
|
# C<$spamtest-E<gt>learn($mail,$id,$isspam,$forget)> instead. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my ($self, $id) = @_; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# bug 4096 |
|
146
|
|
|
|
|
|
|
# if ($self->{main}->{learn_with_whitelist}) { |
|
147
|
|
|
|
|
|
|
# $self->{main}->remove_all_addresses_from_whitelist ($self->{msg}); |
|
148
|
0
|
|
|
0
|
0
|
0
|
# } |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$self->{learned} = $self->{bayes_scanner}->forget ($self->{msg}, $id); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
########################################################################### |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
0
|
=item $didlearn = $status->did_learn() |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Returns C<1> if the message was learned from or forgotten successfully. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my ($self) = @_; |
|
162
|
|
|
|
|
|
|
return ($self->{learned}); |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
########################################################################### |
|
166
|
|
|
|
|
|
|
|
|
167
|
2
|
|
|
2
|
1
|
5
|
=item $status->finish() |
|
168
|
2
|
|
|
|
|
7
|
|
|
169
|
|
|
|
|
|
|
Finish with the object. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my $self = shift; |
|
174
|
|
|
|
|
|
|
%{$self} = (); |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
########################################################################### |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
1; |
|
180
|
2
|
|
|
2
|
1
|
4
|
|
|
181
|
2
|
|
|
|
|
4
|
=back |
|
|
2
|
|
|
|
|
6
|
|
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Mail::SpamAssassin(3) |
|
186
|
|
|
|
|
|
|
spamassassin(1) |
|
187
|
|
|
|
|
|
|
|