AntiSpam.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« AntiSpam/NoSpam.pm ↑ Summary
1 package Apache::AntiSpam;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 $VERSION = 0.05;
6  
7 0 ▶use Apache::Constants qw(:common);
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use Apache::File;
9 use Carp ();
10 use Email::Find 0.04;
11  
12 sub handler ($$) {
13 my($class, $r) = @_;
14  
15 my $filtered = uc($r->dir_config('Filter')) eq 'ON';
16  
17 # makes Apache::Filter aware
18 # snippets stolen from Geoffrey Young's Apache::Clean
19 $r = $r->filter_register if $filtered;
20  
21 # AntiSpam filtering is done on text/* files
22 return DECLINED unless ($r->content_type =~ m,^text/, && $r->is_main);
23  
24 my($fh, $status);
25 if ($filtered) {
26 ($fh, $status) = $r->filter_input;
27 undef $fh unless $status == OK;
28 } else {
29 $fh = Apache::File->new($r->filename);
30 }
31  
32 return DECLINED unless $fh;
33  
34 # finds and replaces e-mail addresses
35 # if-statement should be outside the sub for efficiency
36 my $replacer;
37 if (uc($r->dir_config('AntiSpamFormat')) eq 'SPACES') {
38 $replacer = sub {
39 my($email, $orig) = @_;
40 $orig =~ s/\@/ at /g;
41 $orig =~ s/\./ dot /g;
42 $orig =~ s/\-/ bar /g;
43 $orig =~ s/ */ /g;
44 return $orig;
45 };
46 } else {
47 $replacer = sub {
48 my($email, $orig) = @_;
49 $orig =~ s/\@/-nospam\@/;
50 return $orig;
51 };
52 }
53  
54 $r->send_http_header;
55  
56 local $/; # slurp
57 my $input = <$fh>;
58 find_emails($input, sub { $class->antispamize(@_) });
59 $r->print($input);
60  
61 return OK;
62 }
63  
64 sub antispamize {
65 my($class, $email, $orig) = @_;
66 Carp::carp "Apache::AntiSpam should be subclassed. I'll do nothing";
67 return $orig;
68 }
69  
70 1;
71 __END__
« AntiSpam/NoSpam.pm ↑ Summary