| 1 | 1 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Mail::Qmail::Filter; | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.71'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use FindBin (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use IO::Handle (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Mail::Qmail::Filter::Util qw(addresses_to_hash match_address); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use MailX::Qmail::Queue::Message; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # Must be under namespace::clean for coercion to work: | ||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Mo qw(coerce default); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | my $feedback_fh; # Open ASAP before the handle gets reused: | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | $feedback_fh = IO::Handle->new_from_fd( 4, 'w' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | or warn "Cannot open feedback handle: $!"; | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | has 'defer_only'; | |||||||||||||||||||||||||||
| 28 | 1 | has 'feedback_fh' => $feedback_fh; | |||||||||||||||||||||||||||
| 29 | 1 | has 'filters' => []; | |||||||||||||||||||||||||||
| 30 | 1 | has 'log_fh'; | |||||||||||||||||||||||||||
| 31 | 1 | has 'reject_text' => 'Rejected.'; | |||||||||||||||||||||||||||
| 32 | 1 | has 'skip_if'; | |||||||||||||||||||||||||||
| 33 | 1 | has 'skip_for_from' => coerce => \&addresses_to_hash; | |||||||||||||||||||||||||||
| 34 | 1 | has 'skip_for_rcpt' => coerce => \&addresses_to_hash; | |||||||||||||||||||||||||||
| 35 | 1 | has 'skip_for_sender' => coerce => \&addresses_to_hash; | |||||||||||||||||||||||||||
| 36 | 1 | has 'skip_if_remote_ip_matches'; | |||||||||||||||||||||||||||
| 37 | 1 | has 'skip_if_relayclient'; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | my @debug; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | sub debug { | ||||||||||||||||||||||||||
|
Subroutine
debug: called CC=3 SCAR=16.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | 1 | push @debug, my $message = join ': ', @_; | |||||||||||||||||||||||||||
| 44 | 1 | ▶ | if ( $self->log_fh ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | my $package = ref($self) . ' '; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | $self->log_fh->say( $message !~ /^\Q$package/ && $package, $message ); | ||||||||||||||||||||||||||
|
Condition0%0/3
!($message =~ /^\Q$package\E/u) && $package
MC/DC0%0/2
!($message =~ /^\Q$package\E/u) && $package
!($message =~ /^\Q$package\E/u)
$package
Truth table0%0/3
not(A) && B
A= !($message =~ /^\Q$package\E/u)B= $package
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $SIG{__DIE__} //= sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return if $^S || !defined $^S; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$^S or not defined $^S
MC/DC0%0/2
$^S or not defined $^S
$^S
not defined $^S
Truth table0%0/3
A or not(B)
A= $^SB= not defined $^S
| |||||||||||||||||||||||||||||
| 52 | 0 | __PACKAGE__->debug( died => "@_" ); | |||||||||||||||||||||||||||
| 53 | 0 | die @_; | |||||||||||||||||||||||||||
| 54 | 1 | ▶ | }; | ||||||||||||||||||||||||||
|
Condition33%1/3
$SIG{"__DIE__"} //= sub {
return if $^S or not defined $^S;
__PACKAGE__->debug("died", join($", @_));
die @_;
}
MC/DC0%0/2
$SIG{"__DIE__"} //= sub {
return if $^S or not defined $^S;
__PACKAGE__->debug("died", join($", @_));
die @_;
}
$SIG{"__DIE__"}
sub {
return if $^S or not defined $^S;
__PACKAGE__->debug("died", join($", @_));
die @_;
}
Truth table33%1/3
A //= B
A= $SIG{"__DIE__"}B= sub {
return if $^S or not defined $^S;
__PACKAGE__->debug("died", join($", @_));
die @_;
}
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub add_filters { | ||||||||||||||||||||||||||
|
Subroutine
add_filters: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | while ( defined( my $filter = shift ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | unless ( blessed($filter) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $opt = shift if @_ && 'HASH' eq ref $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ and "HASH" eq ref $_[0]
MC/DC0%0/2
@_ and "HASH" eq ref $_[0]
@_
"HASH" eq ref $_[0]
Truth table0%0/3
A and B
A= @_B= "HASH" eq ref $_[0]
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | $filter = __PACKAGE__ . $filter if $filter =~ /^::/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | eval "use $filter"; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | confess $@ if length $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | $filter = $filter->new(%$opt); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 0 | push @{ $self->{filters} }, $filter; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 0 | $self; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub defer { | ||||||||||||||||||||||||||
|
Subroutine
defer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 73 | 0 | $self->debug( action => 'defer' ); | |||||||||||||||||||||||||||
| 74 | 0 | $self->_exit( Z => @_ ); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub filter { | ||||||||||||||||||||||||||
|
Subroutine
filter: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | $_->run for @{ $self->filters }; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub message { | ||||||||||||||||||||||||||
|
Subroutine
message: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | state $message = MailX::Qmail::Queue::Message->receive | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | or die "Invalid message\n"; | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub reject { | ||||||||||||||||||||||||||
|
Subroutine
reject: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | 0 | $self->debug( action => 'reject' ); | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | $self->_exit( $self->defer_only ? 'Z' : 'D', @_ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | my $package = ref $self; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | return if $self->skip_if && $self->skip_if->($self); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->skip_if and $self->skip_if->($self)
MC/DC0%0/2
$self->skip_if and $self->skip_if->($self)
$self->skip_if
$self->skip_if->($self)
Truth table0%0/3
A and B
A= $self->skip_ifB= $self->skip_if->($self)
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ( exists $ENV{RELAYCLIENT} && $self->skip_if_relayclient ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $ENV{"RELAYCLIENT"} and $self->skip_if_relayclient
MC/DC0%0/2
exists $ENV{"RELAYCLIENT"} and $self->skip_if_relayclient
exists $ENV{"RELAYCLIENT"}
$self->skip_if_relayclient
Truth table0%0/3
A and B
A= exists $ENV{"RELAYCLIENT"}B= $self->skip_if_relayclient
| |||||||||||||||||||||||||||||
| 102 | 0 | $self->debug("$package skipped"); | |||||||||||||||||||||||||||
| 103 | 0 | return; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->skip_if_remote_ip_matches and my $match = $self->skip_if_remote_ip_matches->match_ip($self->message->remote_ip)
MC/DC0%0/2
$self->skip_if_remote_ip_matches and my $match = $self->skip_if_remote_ip_matches->match_ip($self->message->remote_ip)
$self->skip_if_remote_ip_matches
my $match = $self->skip_if_remote_ip_matches->match_ip($self->message->remote_ip)
Truth table0%0/3
A and B
A= $self->skip_if_remote_ip_matchesB= my $match = $self->skip_if_remote_ip_matches->match_ip($self->message->remote_ip)
| |||||||||||||||||||||||||||||
| 107 | $self->skip_if_remote_ip_matches | ||||||||||||||||||||||||||||
| 108 | && ( | ||||||||||||||||||||||||||||
| 109 | my $match = $self->skip_if_remote_ip_matches->match_ip( | ||||||||||||||||||||||||||||
| 110 | $self->message->remote_ip | ||||||||||||||||||||||||||||
| 111 | ) | ||||||||||||||||||||||||||||
| 112 | ) | ||||||||||||||||||||||||||||
| 113 | ) | ||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | 0 | $self->debug("$package skipped because remote IP belongs to $match"); | |||||||||||||||||||||||||||
| 116 | 0 | return; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ( my $skip_for_sender = $self->skip_for_sender ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | match_address( | ||||||||||||||||||||||||||||
| 122 | $skip_for_sender, my $sender = $self->message->from | ||||||||||||||||||||||||||||
| 123 | ) | ||||||||||||||||||||||||||||
| 124 | ) | ||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||
| 126 | 0 | $self->debug( "$package skipped because of sender", $sender ); | |||||||||||||||||||||||||||
| 127 | 0 | return; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if ( ( my $skip_for_from = $self->skip_for_from ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
my $skip_for_from = $self->skip_for_from and my $from = $self->message->header_from
MC/DC0%0/2
my $skip_for_from = $self->skip_for_from and my $from = $self->message->header_from
my $skip_for_from = $self->skip_for_from
my $from = $self->message->header_from
Truth table0%0/3
A and B
A= my $skip_for_from = $self->skip_for_fromB= my $from = $self->message->header_from
| |||||||||||||||||||||||||||||
| 132 | && ( my $from = $self->message->header_from ) ) | ||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ( match_address( $skip_for_from, $from = $from->address ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | $self->debug( "$package skipped because of RFC5322.From", $from ); | |||||||||||||||||||||||||||
| 136 | 0 | return; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ( my $skip_for_rcpt = $self->skip_for_rcpt ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | for ( $self->message->to ) { | |||||||||||||||||||||||||||
| 142 | 0 | ▶ | next unless match_address( $skip_for_rcpt, $_ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | $self->debug( "$package skipped because of rcpt", $_ ); | |||||||||||||||||||||||||||
| 144 | 0 | return; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | $self->debug("$package started"); | |||||||||||||||||||||||||||
| 149 | 0 | $self->filter; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub _exit { | ||||||||||||||||||||||||||
|
Subroutine
_exit: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 153 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 154 | 0 | my $status = shift; | |||||||||||||||||||||||||||
| 155 | 0 | ▶ | my $reject_text = shift // $self->reject_text; | ||||||||||||||||||||||||||
|
Condition0%0/3
shift() // $self->reject_text
MC/DC0%0/2
shift() // $self->reject_text
shift()
$self->reject_text
Truth table0%0/3
A // B
A= shift()B= $self->reject_text
| |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | $reject_text = $reject_text->(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $reject_text and "CODE" eq ref $reject_text
MC/DC0%0/2
ref $reject_text and "CODE" eq ref $reject_text
ref $reject_text
"CODE" eq ref $reject_text
Truth table0%0/3
A and B
A= ref $reject_textB= "CODE" eq ref $reject_text
| |||||||||||||||||||||||||||||
| 157 | if ref $reject_text && 'CODE' eq ref $reject_text; | ||||||||||||||||||||||||||||
| 158 | 0 | $reject_text =~ y/\n/ /; | |||||||||||||||||||||||||||
| 159 | 0 | $self->feedback_fh->print( $status, $reject_text ); | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | exit 88; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 1 | ▶ | END { | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 165 | 1 | __PACKAGE__->debug( 'exit code' => $? ); | |||||||||||||||||||||||||||
| 166 | 1 | say STDERR "$FindBin::Script\[$$]: " . join '; ', @debug; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | __END__ | ||||||||||||||||||||||||||||