File Coverage

blib/lib/Mail/SpamAssassin/Plugin/URIEval.pm
Criterion Covered Total %
statement 24 48 50.0
branch 0 8 0.0
condition 1 6 16.6
subroutine 6 9 66.6
pod 1 4 25.0
total 32 75 42.6


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             package Mail::SpamAssassin::Plugin::URIEval;
19              
20 21     21   165 use Mail::SpamAssassin::Plugin;
  21         68  
  21         668  
21 21     21   135 use Mail::SpamAssassin::Logger;
  21         69  
  21         1098  
22              
23 21     21   146 use strict;
  21         49  
  21         397  
24 21     21   115 use warnings;
  21         49  
  21         596  
25             # use bytes;
26 21     21   112 use re 'taint';
  21         71  
  21         10409  
27              
28             our @ISA = qw(Mail::SpamAssassin::Plugin);
29              
30             # constructor: register the eval rule
31             sub new {
32 62     62 1 244 my $class = shift;
33 62         168 my $mailsaobject = shift;
34              
35             # some boilerplate...
36 62   33     464 $class = ref($class) || $class;
37 62         400 my $self = $class->SUPER::new($mailsaobject);
38 62         193 bless ($self, $class);
39              
40             # the important bit!
41 62         318 $self->register_eval_rule("check_for_http_redirector");
42 62         258 $self->register_eval_rule("check_https_ip_mismatch");
43 62         243 $self->register_eval_rule("check_uri_truncated");
44              
45 62         529 return $self;
46             }
47              
48             ###########################################################################
49              
50             sub check_for_http_redirector {
51 0     0 0   my ($self, $pms) = @_;
52              
53 0           foreach ($pms->get_uri_list()) {
54 0           while (s{^https?://([^/:\?]+).+?(https?:/{0,2}?([^/:\?]+).*)$}{$2}i) {
55 0           my ($redir, $dest) = ($1, $3);
56 0           foreach ($redir, $dest) {
57 0   0       $_ = $self->{main}->{registryboundaries}->uri_to_domain($_) || $_;
58             }
59 0 0         next if ($redir eq $dest);
60 0           dbg("eval: redirect: found $redir to $dest, flagging");
61 0           return 1;
62             }
63             }
64 0           return 0;
65             }
66              
67             ###########################################################################
68              
69             sub check_https_ip_mismatch {
70 0     0 0   my ($self, $pms) = @_;
71              
72 0           while (my($k,$v) = each %{$pms->{html}->{uri_detail}}) {
  0            
73 0 0         next if ($k !~ m%^https?:/*(?:[^\@/]+\@)?\d+\.\d+\.\d+\.\d+%i);
74 0           foreach (@{$v->{anchor_text}}) {
  0            
75 0 0         next if (m%^https:/*(?:[^\@/]+\@)?\d+\.\d+\.\d+\.\d+%i);
76 0 0         if (m%https:%i) {
77 0           keys %{$self->{html}->{uri_detail}}; # resets iterator, bug 4829
  0            
78 0           return 1;
79             }
80             }
81             }
82              
83 0           return 0;
84             }
85              
86             ###########################################################################
87              
88             # is there a better way to do this?
89             sub check_uri_truncated {
90 0     0 0   my ($self, $pms) = @_;
91 0           return $pms->{'uri_truncated'};
92             }
93              
94             1;