File Coverage

blib/lib/Mail/SpamAssassin/PersistentAddrList.pm
Criterion Covered Total %
statement 14 25 56.0
branch n/a
condition 1 3 33.3
subroutine 4 9 44.4
pod 6 6 100.0
total 25 43 58.1


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::PersistentAddrList - persistent address list base class
21              
22             =head1 SYNOPSIS
23              
24             my $factory = PersistentAddrListSubclass->new();
25             $spamtest->set_persistent_addr_list_factory ($factory);
26             ... call into SpamAssassin classes...
27              
28             SpamAssassin will call:
29              
30             my $addrlist = $factory->new_checker($spamtest);
31             $entry = $addrlist->get_addr_entry ($addr);
32             ...
33              
34             =head1 DESCRIPTION
35              
36             All persistent address list implementations, used by the auto-whitelist
37             code to track known-good email addresses, use this as a base class.
38              
39             See C<Mail::SpamAssassin::DBBasedAddrList> for an example.
40              
41             =head1 METHODS
42              
43             =over 4
44              
45             =cut
46              
47             package Mail::SpamAssassin::PersistentAddrList;
48              
49 5     5   38 use strict;
  5         12  
  5         217  
50 5     5   35 use warnings;
  5         14  
  5         144  
51             # use bytes;
52 5     5   33 use re 'taint';
  5         11  
  5         1412  
53              
54             our @ISA = qw();
55              
56             ###########################################################################
57              
58             =item $factory = PersistentAddrListSubclass->new();
59              
60             This creates a factory object, which SpamAssassin will call to create
61             a new checker object for the persistent address list.
62              
63             =cut
64              
65             sub new {
66 6     6 1 16 my $class = shift;
67 6   33     27 $class = ref($class) || $class;
68 6         14 my $self = { };
69 6         16 bless ($self, $class);
70 6         19 $self;
71             }
72              
73             ###########################################################################
74              
75             =item my $addrlist = $factory->new_checker();
76              
77             Create a new address-list checker object from the factory. Called by the
78             SpamAssassin classes.
79              
80             =cut
81              
82             sub new_checker {
83 0     0 1   my ($factory, $main) = @_;
84 0           die "auto-whitelist: unimplemented base method"; # override this
85             }
86              
87             ###########################################################################
88              
89             =item $entry = $addrlist->get_addr_entry ($addr);
90              
91             Given an email address C<$addr>, return an entry object with the details of
92             that address.
93              
94             The entry object is a reference to a hash, which must contain at least
95             two keys: C<count>, which is the count of times that address has been
96             encountered before; and C<totscore>, which is the total of all scores for
97             messages associated with that address. From these two fields, an average
98             score will be calculated, and the score for the current message will be
99             regressed towards that mean message score.
100              
101             The hash can contain whatever other data your back-end needs to store,
102             under other keys.
103              
104             The method should never return C<undef>, or a hash that does not contain
105             a C<count> key and a C<totscore> key.
106              
107             =cut
108              
109             sub get_addr_entry {
110 0     0 1   my ($self, $addr, $signedby) = @_;
111 0           my $entry = { };
112 0           die "auto-whitelist: unimplemented base method"; # override this
113 0           return $entry;
114             }
115              
116             ###########################################################################
117              
118             =item $entry = $addrlist->add_score($entry, $score);
119              
120             This method should add the given score to the whitelist database for the
121             given entry, and then return the new entry.
122              
123             =cut
124              
125             sub add_score {
126 0     0 1   my ($self, $entry, $score) = @_;
127 0           die "auto-whitelist: unimplemented base method"; # override this
128             }
129              
130             ###########################################################################
131              
132             =item $entry = $addrlist->remove_entry ($entry);
133              
134             This method should remove the given entry from the whitelist database.
135              
136             =cut
137              
138             sub remove_entry {
139 0     0 1   my ($self, $entry) = @_;
140 0           die "auto-whitelist: unimplemented base method"; # override this
141             }
142              
143             ###########################################################################
144              
145             =item $entry = $addrlist->finish ();
146              
147             Clean up, if necessary. Called by SpamAssassin when it has finished
148             checking, or adding to, the auto-whitelist database.
149              
150             =cut
151              
152             sub finish {
153 0     0 1   my ($self) = @_;
154             }
155              
156             ###########################################################################
157              
158             1;
159              
160             =back
161              
162             =cut