| 1 | package Mail::Abuse::Filter::Time; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | require 5.005_62; | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Date::Manip; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use base 'Mail::Abuse::Filter'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # The code below should be in a single line | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | our $VERSION = do { my @r = (q$Revision: 1.9 $ =~ /\d+/g); sprintf " %d."."%03d" x $#r, @r }; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | Mail::Abuse::Filter::Time - Filter incidents according to how old they are | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | use Mail::Abuse::Filter::Time; | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | my $f = new Mail::Abuse::Filter::Time; | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | $report->filter([$f]); | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | Removes those events from a C<Mail::Abuse::Report> that are older than | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | a given threshold, which can be specified in the configuration file | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | for the abuse report. | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | The following configuration keys are recognized: | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | =over | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | =item B<filter before> | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | Incidents older than the specified time will be removed from the | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | report and not considered. The time can be specified as a specific | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | date or as a time delta according to the specifications in | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | L<Date::Manip>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | If this is not specified, the default is to ignore incidents that | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | happened more than 96 hours in the past (ie, "96 hours ago"). | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | =item B<filter after> | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | Incidents newer than the specified time will be removed from the | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | report and not considered. Normally, this time specification should be | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | specified as a relative date (ie, "in 48 hours" which is the | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | default). This is useful to discard events that occur in the future. | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | =item B<filter local timezone> | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | If specified, assume this timezone for the conversion of the | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | dates. Defaults to UTC. | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | =item B<debug time filter> | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | When set to a true value, causes this module to emit debugging | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | messages via C<warn()>. Of course, defaults to a false value. | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | The following methods are implemented in this class. | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | =over | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | =item C<criteria($report, $incident)> | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | This function receives a C<Mail::Abuse::Report> and a | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | C<Mail::Abuse::Incident> object. It returns a true value if the | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | incident should be handled or false otherwise. This function will be | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | generally called by the C<Mail::Abuse::Report> object when requested | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | to filter its events. | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | sub criteria | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 10 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
criteria: called CC=25 SCAR=37.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 10 | my $rep = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 10 | my $inc = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # warn "criteria self: ", ref $self, "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # warn "criteria rep: ", ref $rep, "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # warn "criteria inc: ", ref $inc, "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 10 | ▶ | unless ($self->before) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | my $date_before; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | my $date_after; | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | ▶ | Date_Init("TZ=" . ($rep->config->{'filter local timezone'} || 'UTC')); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rep->config->{'filter local timezone'} || 'UTC'
MC/DC0%0/1
$rep->config->{'filter local timezone'} || 'UTC'
$rep->config->{'filter local timezone'}
Truth table50%1/2
A
A= $rep->config->{'filter local timezone'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | ▶ | if (ref $rep->config->{'filter before'} eq 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | $date_before = | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ParseDate(join(' ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | @{$rep->config->{'filter before'}})); | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | $date_before = | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | ParseDate($rep->config->{'filter before'} | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rep->config->{'filter before'} || '96 hours ago'
MC/DC0%0/1
$rep->config->{'filter before'} || '96 hours ago'
$rep->config->{'filter before'}
Truth table50%1/2
A
A= $rep->config->{'filter before'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | || "96 hours ago"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ▶ | if (ref $rep->config->{'filter after'} eq 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | $date_after = | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ParseDate(join(' ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | @{$rep->config->{'filter after'}})); | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | $date_after = | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | ▶ | ParseDate($rep->config->{'filter after'} | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rep->config->{'filter after'} || 'in 48 hours'
MC/DC0%0/1
$rep->config->{'filter after'} || 'in 48 hours'
$rep->config->{'filter after'}
Truth table50%1/2
A
A= $rep->config->{'filter after'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | || "in 48 hours"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | warn "Parsing said: $@" if $@ and $rep->config->{'debug time filter'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ and $rep->config->{"debug time filter"}
MC/DC0%0/2
$@ and $rep->config->{"debug time filter"}
$@
$rep->config->{"debug time filter"}
Truth table33%1/3
A and B
A= $@B= $rep->config->{"debug time filter"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | ▶ | die "Filter::Time: Cannot parse 'filter before' date\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | unless $date_before; | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | ▶ | die "Filter::Time: Cannot parse 'filter after' date\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | unless $date_after; | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | $self->before(UnixDate($date_before, '%s')); | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | $self->after(UnixDate($date_after, '%s')); | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | ▶ | die "Filter::Time: Times before the epoch are not supported" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | if $self->before < 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | warn "Filter::Time: Removing incidents older than ", $self->before, | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | "\n" if $rep->config->{'debug time filter'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | warn "Filter::Time: Removing incidents newer than ", $self->after, | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | ▶ | "\n" if $rep->config->{'debug time filter'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 10 | ▶ | if ($inc->time and $self->before and $inc->time < $self->before) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$inc->time and $self->before and $inc->time < $self->before
$inc->time and $self->before
MC/DC33%1/3
$inc->time and $self->before and $inc->time < $self->before
$inc->time
$self->before
$inc->time < $self->before
Truth table50%2/4
A and B and C
A= $inc->timeB= $self->beforeC= $inc->time < $self->before
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | warn "Filter::Time - discard before ", $inc->time, "\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | ▶ | if $rep->config->{'debug time filter'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 3 | ▶ | $rep->filtered(0) unless $rep->filtered; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | $rep->filtered($rep->filtered + 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | ▶ | elsif ($inc->time and $self->after and $inc->time > $self->after) | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$inc->time and $self->after and $inc->time > $self->after
$inc->time and $self->after
MC/DC33%1/3
$inc->time and $self->after and $inc->time > $self->after
$inc->time
$self->after
$inc->time > $self->after
Truth table50%2/4
A and B and C
A= $inc->timeB= $self->afterC= $inc->time > $self->after
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | warn "Filter::Time - discard after ", $inc->time, "\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | ▶ | if $rep->config->{'debug time filter'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | ▶ | $rep->filtered(0) unless $rep->filtered; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | $rep->filtered($rep->filtered + 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | warn "Filter::Time - accept ", $inc->time, "\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 3 | ▶ | if $rep->config->{'debug time filter'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | return $inc; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||