our
@ISA
=
qw(Mail::SpamAssassin::Plugin)
;
sub
new {
my
$class
=
shift
;
my
$mailsaobject
=
shift
;
$class
=
ref
(
$class
) ||
$class
;
my
$self
=
$class
->SUPER::new(
$mailsaobject
);
bless
(
$self
,
$class
);
$self
->register_eval_rule (
"check_https_http_mismatch"
,
$Mail::SpamAssassin::Conf::TYPE_BODY_EVALS
);
return
$self
;
}
sub
check_https_http_mismatch {
my
(
$self
,
$permsgstatus
,
undef
,
$minanchors
,
$maxanchors
) =
@_
;
$minanchors
||= 1;
if
(!
exists
$permsgstatus
->{chhm_hit}) {
$permsgstatus
->{chhm_hit} = 0;
$permsgstatus
->{chhm_anchors} = 0;
foreach
my
$k
(
keys
%{
$permsgstatus
->{html}->{uri_detail}} ) {
my
%uri_detail
= %{
$permsgstatus
->{html}->{uri_detail}};
my
$v
= ${uri_detail}{
$k
};
next
unless
(
exists
$v
->{anchor_text} && @{
$v
->{anchor_text}});
my
$uri
;
if
(
$k
=~ m@^https?://([^/:?
$uri
= $1;
if
(
$uri
=~ IS_IP_ADDRESS) {
undef
$uri
;
next
;
}
$uri
=
$self
->{main}->{registryboundaries}->trim_domain(
$uri
);
my
$domain
=
$self
->{main}->{registryboundaries}->uri_to_domain(
$uri
);
undef
$uri
unless
(
$self
->{main}->{registryboundaries}->is_domain_valid(
$domain
));
}
next
unless
$uri
;
$permsgstatus
->{chhm_anchors}++
if
exists
$v
->{anchor_text};
foreach
(@{
$v
->{anchor_text}}) {
if
(m
@https
://([^\s/:?
my
$https
= $1;
if
(
$https
!~ IS_IP_ADDRESS) {
$https
=
$self
->{main}->{registryboundaries}->trim_domain(
$https
);
undef
$https
unless
(
$self
->{main}->{registryboundaries}->is_domain_valid(
$https
));
}
next
unless
$https
;
dbg(
"https_http_mismatch: domains $uri -> $https"
);
next
if
$uri
eq
$https
;
$permsgstatus
->{chhm_hit} = 1;
last
;
}
}
}
dbg(
"https_http_mismatch: anchors "
.
$permsgstatus
->{chhm_anchors});
}
return
(
$permsgstatus
->{chhm_hit} &&
$permsgstatus
->{chhm_anchors} >=
$minanchors
&& (
defined
$maxanchors
&&
$permsgstatus
->{chhm_anchors} <
$maxanchors
) );
}
1;