| 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.31'; | |||||||||||||||||||||||||||
| 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 'reject_text' => 'Rejected.'; | |||||||||||||||||||||||||||
| 31 | 1 | has 'skip_if'; | |||||||||||||||||||||||||||
| 32 | 1 | has 'skip_for_from' => coerce => \&addresses_to_hash; | |||||||||||||||||||||||||||
| 33 | 1 | has 'skip_for_rcpt' => coerce => \&addresses_to_hash; | |||||||||||||||||||||||||||
| 34 | 1 | has 'skip_for_sender' => coerce => \&addresses_to_hash; | |||||||||||||||||||||||||||
| 35 | 1 | has 'skip_if_relayclient'; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | my @debug; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | sub debug { | ||||||||||||||||||||||||||
|
Subroutine
debug: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 41 | 1 | push @debug, join ': ', @_; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $SIG{__DIE__} //= sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 45 | 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
| |||||||||||||||||||||||||||||
| 46 | 0 | __PACKAGE__->debug( died => "@_" ); | |||||||||||||||||||||||||||
| 47 | 0 | die @_; | |||||||||||||||||||||||||||
| 48 | 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 @_;
}
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub add_filters { | ||||||||||||||||||||||||||
|
Subroutine
add_filters: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | while ( defined( my $filter = shift ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | unless ( blessed($filter) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 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]
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $filter = __PACKAGE__ . $filter if $filter =~ /^::/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | eval "use $filter"; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | confess $@ if length $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | $filter = $filter->new(%$opt); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 0 | push @{ $self->{filters} }, $filter; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 0 | $self; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub defer { | ||||||||||||||||||||||||||
|
Subroutine
defer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 67 | 0 | $self->debug( action => 'defer' ); | |||||||||||||||||||||||||||
| 68 | 0 | $self->_exit( Z => @_ ); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub filter { | ||||||||||||||||||||||||||
|
Subroutine
filter: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | $_->run for @{ $self->filters }; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub message { | ||||||||||||||||||||||||||
|
Subroutine
message: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | state $message = MailX::Qmail::Queue::Message->receive | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | or die "Invalid message\n"; | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub reject { | ||||||||||||||||||||||||||
|
Subroutine
reject: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 84 | 0 | $self->debug( action => 'reject' ); | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | $self->_exit( $self->defer_only ? 'Z' : 'D', @_ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $package = ref $self; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 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)
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 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
| |||||||||||||||||||||||||||||
| 96 | 0 | $self->debug("$package skipped"); | |||||||||||||||||||||||||||
| 97 | 0 | return; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ( my $skip_for_sender = $self->skip_for_sender ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | match_address( | ||||||||||||||||||||||||||||
| 103 | $skip_for_sender, my $sender = $self->message->from | ||||||||||||||||||||||||||||
| 104 | ) | ||||||||||||||||||||||||||||
| 105 | ) | ||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||
| 107 | 0 | $self->debug( "$package skipped because of sender", $sender ); | |||||||||||||||||||||||||||
| 108 | 0 | return; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 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
| |||||||||||||||||||||||||||||
| 113 | && ( my $from = $self->message->header_from ) ) | ||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ( match_address( $skip_for_from, $from = $from->address ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $self->debug( "$package skipped because of RFC5322.From", $from ); | |||||||||||||||||||||||||||
| 117 | 0 | return; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( my $skip_for_rcpt = $self->skip_for_rcpt ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | for ( $self->message->to ) { | |||||||||||||||||||||||||||
| 123 | 0 | ▶ | next unless match_address( $skip_for_rcpt, $_ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | $self->debug( "$package skipped because of rcpt", $_ ); | |||||||||||||||||||||||||||
| 125 | 0 | return; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | $self->debug("$package started"); | |||||||||||||||||||||||||||
| 130 | 0 | $self->filter; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub _exit { | ||||||||||||||||||||||||||
|
Subroutine
_exit: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 134 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 135 | 0 | my $status = shift; | |||||||||||||||||||||||||||
| 136 | 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
| |||||||||||||||||||||||||||||
| 137 | 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
| |||||||||||||||||||||||||||||
| 138 | if ref $reject_text && 'CODE' eq ref $reject_text; | ||||||||||||||||||||||||||||
| 139 | 0 | $self->feedback_fh->print( $status, $reject_text =~ y/\n/ /r ); | |||||||||||||||||||||||||||
| 140 | 0 | exit 88; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1 | ▶ | END { | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 144 | 1 | __PACKAGE__->debug( 'exit code' => $? ); | |||||||||||||||||||||||||||
| 145 | 1 | say STDERR "$FindBin::Script\[$$]: " . join '; ', @debug; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | __END__ | ||||||||||||||||||||||||||||