| 1 | package Email::Filter::Rules; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use constant RULE_SPLIT_LIMIT => 3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = 1.2; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | return unless $args{rules}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | my @rules = (); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # added the \n check because I got a warning if a did a -e test on | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # a scalar containing newlines | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | if ( $args{rules} !~ /\n/s && -e $args{rules} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
not $args{"rules"} =~ /\n/s and -e $args{"rules"}
MC/DC100%2/2
not $args{"rules"} =~ /\n/s and -e $args{"rules"}
not $args{"rules"} =~ /\n/s
-e $args{"rules"}
Truth table100%3/3
not(A) and B
A= not $args{"rules"} =~ /\n/sB= -e $args{"rules"}
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | open my $fh, '<', $args{rules} or die "Can't open file $args{rules}: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | @rules = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | elsif ( ref $args{rules} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | @rules = @{ $args{rules} }; | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | @rules = split /\n/, $args{rules}; | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | ▶ | return unless scalar @rules; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | my @rule_data = (); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | for my $line (@rules) { | |||||||||||||||||||||||||||||||||||||||||
| 31 | 51 | chomp($line); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 51 | ▶ | next if $line =~ /^#/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 48 | my ( $folder, $methods, $substring ) = split( /\s+/, $line, RULE_SPLIT_LIMIT ); | |||||||||||||||||||||||||||||||||||||||||
| 34 | 48 | ▶ | next unless $methods && $folder && $substring; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$methods and $folder and $substring
$methods and $folder
MC/DC100%3/3
$methods and $folder and $substring
$methods
$folder
$substring
Truth table100%4/4
A and B and C
A= $methodsB= $folderC= $substring
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 28 | my $escaped_substring = quotemeta($substring); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 28 | my @methods = split( /\:/, $methods ); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 28 | push @rule_data, { | |||||||||||||||||||||||||||||||||||||||||
| 38 | methods => \@methods, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | substring => $escaped_substring, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | folder => $folder, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | my $obj = { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | rule_data => \@rule_data, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | debug => $args{debug}, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 5 | return bless $obj, $class; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | ▶ | sub apply_rules { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_rules: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 5 | my ( $self, $email ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | for my $rule ( @{ $self->{rule_data} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | for my $method ( @{ $rule->{methods} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | my $substring = $rule->{substring}; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | ▶ | next unless $email->can($method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | my $testing = $email->$method; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 7 | ▶ | next unless $testing; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | warn "testing $method \"$testing\" with $substring\n" | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # going to keep the 'i' now, may pass this in somehow | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | ▶ | return $rule->{folder} if $testing =~ /$substring/is; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||||||||||||||||