| 1 | package Mail::Milter::Authentication::Tester; | ||||||||||||||||||||||||||||||||||||||
| 2 | 112 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 112 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 112 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 112 | ▶ | use Mail::Milter::Authentication::Pragmas; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Class used for testing | ||||||||||||||||||||||||||||||||||||||
| 7 | 112 | our $VERSION = '4.20261122'; # VERSION | |||||||||||||||||||||||||||||||||||||
| 8 | 112 | ▶ | use Mail::Milter::Authentication; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 112 | ▶ | use Mail::Milter::Authentication::Client; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 112 | ▶ | use Mail::Milter::Authentication::Protocol::Milter; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 112 | ▶ | use Mail::Milter::Authentication::Protocol::SMTP; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 112 | ▶ | use Cwd qw{ cwd }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 112 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 112 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 112 | ▶ | use IO::Socket::UNIX; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 112 | ▶ | use Net::DNS::Resolver::Mock 1.20171219; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | 112 | ▶ | use Test::File::Contents; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 18 | 112 | ▶ | use Test::More; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | 112 | ▶ | use Time::HiRes qw{ sleep time }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | 112 | our @ISA = qw{ Exporter }; ## no critic | |||||||||||||||||||||||||||||||||||||
| 22 | 112 | our @EXPORT = qw{ start_milter stop_milter get_metrics test_metrics smtp_process smtp_process_multi milter_process smtpput send_smtp_packet smtpcat }; ## no critic | |||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | 112 | my $base_dir = cwd(); | |||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 112 | our $MASTER_PROCESS_PID = $$; | |||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||||||||||||
| 30 | 112 | my $milter_pid; | |||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 292 | ▶ | sub start_milter { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
start_milter: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 33 | 292 | my ( $prefix ) = @_; | |||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 292 | ▶ | return if $milter_pid; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | 292 | ▶ | if ( ! -e $prefix . '/authentication_milter.json' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 38 | 0 | die "Could not find config"; | |||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | 292 | system "cp $prefix/mail-dmarc.ini ."; | |||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||
| 43 | # Remove anything left from a previous run, so we can tell when this one is listening | ||||||||||||||||||||||||||||||||||||||
| 44 | 292 | my @sockets = _unix_socket_paths( $prefix ); | |||||||||||||||||||||||||||||||||||||
| 45 | 292 | unlink 'tmp/authentication_milter.pid', @sockets; | |||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||
| 47 | 292 | $milter_pid = fork(); | |||||||||||||||||||||||||||||||||||||
| 48 | 292 | ▶ | die "unable to fork: $!" unless defined($milter_pid); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 49 | 292 | ▶ | if (!$milter_pid) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 50 | 34 | $Mail::Milter::Authentication::Config::PREFIX = $prefix; | |||||||||||||||||||||||||||||||||||||
| 51 | 34 | $Mail::Milter::Authentication::Config::IDENT = 'test_authentication_milter_test'; | |||||||||||||||||||||||||||||||||||||
| 52 | # Keep runtime files, including metrics, with this run rather than in a | ||||||||||||||||||||||||||||||||||||||
| 53 | # directory shared by every run, so test files can run in parallel | ||||||||||||||||||||||||||||||||||||||
| 54 | 34 | my $config = Mail::Milter::Authentication::Config::get_config(); | |||||||||||||||||||||||||||||||||||||
| 55 | 34 | foreach my $type ( qw{ cache lib spool } ) { | |||||||||||||||||||||||||||||||||||||
| 56 | 102 | my $dir = File::Spec->rel2abs( "tmp/$type" ); | |||||||||||||||||||||||||||||||||||||
| 57 | 102 | mkdir $dir; | |||||||||||||||||||||||||||||||||||||
| 58 | 102 | ▶ | $config->{ $type . '_dir' } //= $dir; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$$config{$type . '_dir'} //= $dir
MC/DC0%0/2
$$config{$type . '_dir'} //= $dir
$$config{$type . '_dir'}
$dir
Truth table33%1/3
A //= B
A= $$config{$type . '_dir'}B= $dir
| |||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||
| 60 | 34 | my $Resolver = Net::DNS::Resolver::Mock->new(); | |||||||||||||||||||||||||||||||||||||
| 61 | 34 | $Resolver->zonefile_read( 'zonefile' ); | |||||||||||||||||||||||||||||||||||||
| 62 | 34 | $Mail::Milter::Authentication::Handler::TestResolver = $Resolver; | |||||||||||||||||||||||||||||||||||||
| 63 | 34 | Mail::Milter::Authentication::start({ | |||||||||||||||||||||||||||||||||||||
| 64 | 'pid_file' => 'tmp/authentication_milter.pid', | ||||||||||||||||||||||||||||||||||||||
| 65 | 'daemon' => 0, | ||||||||||||||||||||||||||||||||||||||
| 66 | }); | ||||||||||||||||||||||||||||||||||||||
| 67 | 0 | die; | |||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | 258 | ▶ | _wait_for( 'milter to start', sub { -s 'tmp/authentication_milter.pid' && ! grep { ! -S $_ } @sockets } ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 71 | # The socket file is created when bound, just before it starts listening | ||||||||||||||||||||||||||||||||||||||
| 72 | 258 | sleep 0.1; | |||||||||||||||||||||||||||||||||||||
| 73 | 258 | open my $pid_file, '<', 'tmp/authentication_milter.pid'; | |||||||||||||||||||||||||||||||||||||
| 74 | 258 | $milter_pid = <$pid_file>; | |||||||||||||||||||||||||||||||||||||
| 75 | 258 | close $pid_file; | |||||||||||||||||||||||||||||||||||||
| 76 | 258 | print "Milter started at pid $milter_pid\n"; | |||||||||||||||||||||||||||||||||||||
| 77 | 258 | return; | |||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | 196 | ▶ | sub stop_milter { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
stop_milter: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 81 | 196 | ▶ | return if ! $milter_pid; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 82 | 189 | kill( 'HUP', $milter_pid ); | |||||||||||||||||||||||||||||||||||||
| 83 | 189 | waitpid ($milter_pid,0); | |||||||||||||||||||||||||||||||||||||
| 84 | 189 | print "Milter killed at pid $milter_pid\n"; | |||||||||||||||||||||||||||||||||||||
| 85 | 189 | undef $milter_pid; | |||||||||||||||||||||||||||||||||||||
| 86 | 189 | unlink 'tmp/authentication_milter.pid'; | |||||||||||||||||||||||||||||||||||||
| 87 | 189 | unlink 'mail-dmarc.ini'; | |||||||||||||||||||||||||||||||||||||
| 88 | 189 | return; | |||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||
| 91 | 112 | ▶ | END { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 92 | 112 | ▶ | return if $MASTER_PROCESS_PID != $$; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 93 | 7 | stop_milter(); | |||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | # The unix socket paths the milter with this config will listen on | ||||||||||||||||||||||||||||||||||||||
| 98 | 112 | ▶ | sub _unix_socket_paths { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_unix_socket_paths: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||
| 99 | 292 | my ( $prefix ) = @_; | |||||||||||||||||||||||||||||||||||||
| 100 | 292 | my $config = Mail::Milter::Authentication::Config::load_file( $prefix . '/authentication_milter.json' ); | |||||||||||||||||||||||||||||||||||||
| 101 | 292 | my @connections = ( $config->{'connection'}, $config->{'metric_connection'} ); | |||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | push @connections, map { $_->{'connection'} } values %{ $config->{'connections'} // {} }; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{"connections"} // {}
MC/DC0%0/1
$config->{"connections"} // {}
$config->{"connections"}
Truth table50%1/2
A
A= $config->{"connections"}
| |||||||||||||||||||||||||||||||||||||||
| 103 | 292 | ▶ | return map { /^unix:(.+)$/ ? $1 : () } grep { defined } @connections; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | # Wait for a condition to become true, polling rather than sleeping for a fixed time | ||||||||||||||||||||||||||||||||||||||
| 107 | 258 | ▶ | sub _wait_for { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_wait_for: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||
| 108 | 258 | my ( $what, $check, $timeout ) = @_; | |||||||||||||||||||||||||||||||||||||
| 109 | 258 | ▶ | my $deadline = time + ( $timeout // 30 ); | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$timeout // 30
MC/DC0%0/1
$timeout // 30
$timeout
Truth table50%1/2
A
A= $timeout
| |||||||||||||||||||||||||||||||||||||||
| 110 | 258 | ▶ | while ( ! $check->() ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 111 | 642 | ▶ | die "Timed out waiting for $what\n" if time > $deadline; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 112 | 642 | sleep 0.05; | |||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||
| 114 | 258 | return; | |||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||
| 117 | 13736 | ▶ | sub get_metrics { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_metrics: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 118 | 13736 | my ( $path ) = @_; | |||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||
| 120 | 13736 | my $sock = IO::Socket::UNIX->new( | |||||||||||||||||||||||||||||||||||||
| 121 | 'Peer' => $path, | ||||||||||||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | 13736 | print $sock "GET /metrics HTTP/1.0\n\n"; | |||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | 13736 | my $data = {}; | |||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||
| 128 | 13736 | ▶ | while ( my $line = <$sock> ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 129 | 41208 | chomp $line; | |||||||||||||||||||||||||||||||||||||
| 130 | 41208 | ▶ | last if $line eq q{}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||
| 132 | 13736 | ▶ | while ( my $line = <$sock> ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 133 | 1941862 | chomp $line; | |||||||||||||||||||||||||||||||||||||
| 134 | 1941862 | ▶ | next if $line =~ /^#/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 135 | 1289796 | $line =~ /^(.*)\{(.*)\} (.*)$/; | |||||||||||||||||||||||||||||||||||||
| 136 | 1289796 | my $count_id = $1; | |||||||||||||||||||||||||||||||||||||
| 137 | 1289796 | my $labels = $2; | |||||||||||||||||||||||||||||||||||||
| 138 | 1289796 | my $count = $3; | |||||||||||||||||||||||||||||||||||||
| 139 | 1289796 | $data->{ $count_id . '{' . $labels . '}' } = $count; | |||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||
| 142 | 13736 | return $data; | |||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | # Some metrics vary between runs, so are compared by whether they are set | ||||||||||||||||||||||||||||||||||||||
| 146 | 768652 | ▶ | sub _metric_value { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_metric_value: called CC=9 SCAR=23.6
| |||||||||||||||||||||||||||||||||||||||
| 147 | 768652 | my ( $key, $value ) = @_; | |||||||||||||||||||||||||||||||||||||
| 148 | 768652 | ▶ | return ( $value // 0 ) > 0 if $key =~ /seconds_total/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$value // 0
MC/DC0%0/1
$value // 0
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||
| 149 | 372422 | ▶ | return ( $value // 0 ) > 0 if $key =~ /microseconds_sum/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$value // 0
MC/DC0%0/1
$value // 0
$value
Truth table0%0/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||
| 150 | 372422 | ▶ | return ( $value // 0 ) > 0 if $key =~ /authmilter_forked_children_total/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$value // 0
MC/DC0%0/1
$value // 0
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||
| 151 | 363412 | ▶ | return ( $value // 0 ) > -1 if $key =~ /authmilter_processes_/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$value // 0
MC/DC0%0/1
$value // 0
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||
| 152 | 345198 | return $value; | |||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||
| 155 | 13736 | ▶ | sub _metrics_match { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_metrics_match: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||
| 156 | 13736 | my ( $metrics, $data ) = @_; | |||||||||||||||||||||||||||||||||||||
| 157 | 13736 | foreach my $key ( keys %$data ) { | |||||||||||||||||||||||||||||||||||||
| 158 | 371469 | my $got = _metric_value( $key, $metrics->{ $key } ); | |||||||||||||||||||||||||||||||||||||
| 159 | 371469 | my $want = _metric_value( $key, $data->{ $key } ); | |||||||||||||||||||||||||||||||||||||
| 160 | 371469 | ▶ | return 0 if ( $got // q{} ) ne ( $want // q{} ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
$got // ""
$want // ""
MC/DC100%1/1
$got // ""
$got
MC/DC0%0/1
$want // ""
$want
Truth table100%2/2
A
A= $got
Truth table50%1/2
A
A= $want
| |||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||
| 162 | 48 | return 1; | |||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | 189 | ▶ | sub test_metrics { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
test_metrics: called CC=7 SCAR=25.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 166 | 189 | my ( $expected ) = @_; | |||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||
| 168 | 189 | my $j = JSON::XS->new(); | |||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||
| 170 | 189 | my $data; | |||||||||||||||||||||||||||||||||||||
| 171 | 189 | ▶ | if ( -e $expected ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 172 | 189 | open my $InF, '<', $expected; | |||||||||||||||||||||||||||||||||||||
| 173 | 189 | my @content = <$InF>; | |||||||||||||||||||||||||||||||||||||
| 174 | 189 | close $InF; | |||||||||||||||||||||||||||||||||||||
| 175 | 189 | $data = $j->decode( join( q{}, @content ) ); | |||||||||||||||||||||||||||||||||||||
| 176 | 189 | for my $key ( sort keys %$data ) { | |||||||||||||||||||||||||||||||||||||
| 177 | 14614 | ▶ | next unless $key =~ /^authmilter_version/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 178 | 1757 | delete $data->{$key}; | |||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||
| 182 | # The server updates metrics after replying, so wait for it to catch up, | ||||||||||||||||||||||||||||||||||||||
| 183 | # but not for long if they never match, the test will then report the differences | ||||||||||||||||||||||||||||||||||||||
| 184 | 189 | my $metrics = get_metrics( 'tmp/authentication_milter_test_metrics.sock' ); | |||||||||||||||||||||||||||||||||||||
| 185 | 189 | ▶ | if ( $data ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 186 | 189 | my $deadline = time + 10; | |||||||||||||||||||||||||||||||||||||
| 187 | 189 | ▶ | while ( ! _metrics_match( $metrics, $data ) && time < $deadline ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not _metrics_match($metrics, $data) and &Mail::Milter::Authentication::Tester::time() < $deadline
MC/DC100%2/2
not _metrics_match($metrics, $data) and &Mail::Milter::Authentication::Tester::time() < $deadline
not _metrics_match($metrics, $data)
&Mail::Milter::Authentication::Tester::time() < $deadline
Truth table100%3/3
not(A) and B
A= not _metrics_match($metrics, $data)B= &Mail::Milter::Authentication::Tester::time() < $deadline
| |||||||||||||||||||||||||||||||||||||||
| 188 | 13547 | sleep 0.1; | |||||||||||||||||||||||||||||||||||||
| 189 | 13547 | $metrics = get_metrics( 'tmp/authentication_milter_test_metrics.sock' ); | |||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||
| 193 | 189 | ▶ | subtest $expected => sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=13 SCAR=46.4
| |||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||
| 195 | 189 | ▶ | if ( $data ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||
| 197 | 189 | plan tests => scalar keys %$data; | |||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||
| 199 | 189 | foreach my $key ( sort keys %$data ) { | |||||||||||||||||||||||||||||||||||||
| 200 | 12857 | is( _metric_value( $key, $metrics->{ $key } ), _metric_value( $key, $data->{ $key } ), "Metrics $expected $key" ); | |||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||
| 204 | else { | ||||||||||||||||||||||||||||||||||||||
| 205 | 0 | fail( 'Metrics data does not exist' ); | |||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||
| 208 | 189 | ▶ | if ( $ENV{'WRITE_METRICS'} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 209 | 0 | foreach my $key ( sort keys %$metrics ) { | |||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if ( $key =~ /seconds_total/ ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | $metrics->{ $key } = 123456 if $metrics->{ $key } > 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||
| 213 | elsif ( $key =~ /microseconds_sum/ ) { | ||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | $metrics->{ $key } = 123456 if $metrics->{ $key } > 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||
| 216 | elsif ( $key =~ /authmilter_forked_children_total/ ) { | ||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $metrics->{ $key } = 123456 if $metrics->{ $key } > 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||
| 219 | elsif ( $key =~ /authmilter_processes_/) { | ||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | $metrics->{ $key } = 123456 if $metrics->{ $key } > -1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||
| 223 | 0 | open my $OutF, '>', $expected; | |||||||||||||||||||||||||||||||||||||
| 224 | 0 | $j->pretty(); | |||||||||||||||||||||||||||||||||||||
| 225 | 0 | $j->canonical(); | |||||||||||||||||||||||||||||||||||||
| 226 | 0 | print $OutF $j->encode( $metrics ); | |||||||||||||||||||||||||||||||||||||
| 227 | 0 | close $OutF; | |||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||
| 230 | 189 | }; | |||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||
| 233 | 953 | ▶ | sub smtp_process { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
smtp_process: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 234 | 953 | my ( $args ) = @_; | |||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||
| 236 | 953 | ▶ | if ( ! -e $args->{'prefix'} . '/authentication_milter.json' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 237 | 0 | die "Could not find config " . $args->{'prefix'}; | |||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||
| 239 | 953 | ▶ | if ( ! -e 'data/source/' . $args->{'source'} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 240 | 0 | die "Could not find source"; | |||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||
| 243 | my $catargs = { | ||||||||||||||||||||||||||||||||||||||
| 244 | 'sock_type' => 'unix', | ||||||||||||||||||||||||||||||||||||||
| 245 | 'sock_path' => 'tmp/authentication_milter_smtp_out.sock', | ||||||||||||||||||||||||||||||||||||||
| 246 | 'remove' => [10,11], | ||||||||||||||||||||||||||||||||||||||
| 247 | 953 | 'output' => 'tmp/result/' . $args->{'dest'}, | |||||||||||||||||||||||||||||||||||||
| 248 | }; | ||||||||||||||||||||||||||||||||||||||
| 249 | 953 | unlink 'tmp/authentication_milter_smtp_out.sock'; | |||||||||||||||||||||||||||||||||||||
| 250 | 953 | my $cat_pid; | |||||||||||||||||||||||||||||||||||||
| 251 | 953 | ▶ | if ( ! $args->{'no_cat'} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 252 | 932 | $cat_pid = smtpcat( $catargs ); | |||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||
| 255 | my $return = smtpput({ | ||||||||||||||||||||||||||||||||||||||
| 256 | 'sock_type' => 'unix', | ||||||||||||||||||||||||||||||||||||||
| 257 | 'sock_path' => 'tmp/authentication_milter_test.sock', | ||||||||||||||||||||||||||||||||||||||
| 258 | 'mailer_name' => 'test.module', | ||||||||||||||||||||||||||||||||||||||
| 259 | 'connect_ip' => [ $args->{'ip'} ], | ||||||||||||||||||||||||||||||||||||||
| 260 | 'connect_name' => [ $args->{'name'} ], | ||||||||||||||||||||||||||||||||||||||
| 261 | 'helo_host' => [ $args->{'name'} ], | ||||||||||||||||||||||||||||||||||||||
| 262 | 'mail_from' => [ $args->{'from'} ], | ||||||||||||||||||||||||||||||||||||||
| 263 | 'rcpt_to' => [ $args->{'to'} ], | ||||||||||||||||||||||||||||||||||||||
| 264 | 'mail_file' => [ 'data/source/' . $args->{'source'} ], | ||||||||||||||||||||||||||||||||||||||
| 265 | 919 | 'eom_expect' => $args->{'eom_expect'}, | |||||||||||||||||||||||||||||||||||||
| 266 | }); | ||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||
| 268 | 919 | ▶ | if ( ! $args->{'no_cat'} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 269 | 898 | waitpid( $cat_pid,0 ); | |||||||||||||||||||||||||||||||||||||
| 270 | 898 | files_eq_or_diff( 'data/example/' . $args->{'dest'}, 'tmp/result/' . $args->{'dest'}, 'smtp ' . $args->{'desc'} ); | |||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||
| 272 | else { | ||||||||||||||||||||||||||||||||||||||
| 273 | 21 | is( $return, 1, 'SMTP Put Returned ok' ); | |||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||
| 277 | 97 | ▶ | sub smtp_process_multi { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
smtp_process_multi: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 278 | 97 | my ( $args ) = @_; | |||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||
| 280 | 97 | ▶ | if ( ! -e $args->{'prefix'} . '/authentication_milter.json' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 281 | 0 | die "Could not find config"; | |||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||
| 284 | # Hardcoded lines to remove in subsequent messages | ||||||||||||||||||||||||||||||||||||||
| 285 | # If you change the source email then change the awk | ||||||||||||||||||||||||||||||||||||||
| 286 | # numbers here too. | ||||||||||||||||||||||||||||||||||||||
| 287 | # This could be better! | ||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||
| 289 | my $catargs = { | ||||||||||||||||||||||||||||||||||||||
| 290 | 'sock_type' => 'unix', | ||||||||||||||||||||||||||||||||||||||
| 291 | 'sock_path' => 'tmp/authentication_milter_smtp_out.sock', | ||||||||||||||||||||||||||||||||||||||
| 292 | 'remove' => $args->{'filter'}, | ||||||||||||||||||||||||||||||||||||||
| 293 | 97 | 'output' => 'tmp/result/' . $args->{'dest'}, | |||||||||||||||||||||||||||||||||||||
| 294 | }; | ||||||||||||||||||||||||||||||||||||||
| 295 | 97 | unlink 'tmp/authentication_milter_smtp_out.sock'; | |||||||||||||||||||||||||||||||||||||
| 296 | 97 | my $cat_pid = smtpcat( $catargs ); | |||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||
| 298 | 95 | my $putargs = { | |||||||||||||||||||||||||||||||||||||
| 299 | 'sock_type' => 'unix', | ||||||||||||||||||||||||||||||||||||||
| 300 | 'sock_path' => 'tmp/authentication_milter_test.sock', | ||||||||||||||||||||||||||||||||||||||
| 301 | 'mailer_name' => 'test.module', | ||||||||||||||||||||||||||||||||||||||
| 302 | 'connect_ip' => [], | ||||||||||||||||||||||||||||||||||||||
| 303 | 'connect_name' => [], | ||||||||||||||||||||||||||||||||||||||
| 304 | 'helo_host' => [], | ||||||||||||||||||||||||||||||||||||||
| 305 | 'mail_from' => [], | ||||||||||||||||||||||||||||||||||||||
| 306 | 'rcpt_to' => [], | ||||||||||||||||||||||||||||||||||||||
| 307 | 'mail_file' => [], | ||||||||||||||||||||||||||||||||||||||
| 308 | }; | ||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||
| 310 | 95 | foreach my $item ( @{$args->{'ip'}} ) { | |||||||||||||||||||||||||||||||||||||
| 311 | 426 | push @{$putargs->{'connect_ip'}}, $item; | |||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||
| 313 | 95 | foreach my $item ( @{$args->{'name'}} ) { | |||||||||||||||||||||||||||||||||||||
| 314 | 426 | push @{$putargs->{'connect_name'}}, $item; | |||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||
| 316 | 95 | foreach my $item ( @{$args->{'name'}} ) { | |||||||||||||||||||||||||||||||||||||
| 317 | 426 | push @{$putargs->{'helo_host'}}, $item; | |||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||
| 319 | 95 | foreach my $item ( @{$args->{'from'}} ) { | |||||||||||||||||||||||||||||||||||||
| 320 | 426 | push @{$putargs->{'mail_from'}}, $item; | |||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||
| 322 | 95 | foreach my $item ( @{$args->{'to'}} ) { | |||||||||||||||||||||||||||||||||||||
| 323 | 426 | push @{$putargs->{'rcpt_to'}}, $item; | |||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||
| 325 | 95 | foreach my $item ( @{$args->{'source'}} ) { | |||||||||||||||||||||||||||||||||||||
| 326 | 426 | push @{$putargs->{'mail_file'}}, 'data/source/' . $item; | |||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||
| 328 | #warn 'Testing ' . $args->{'source'} . ' > ' . $args->{'dest'} . "\n"; | ||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||
| 330 | 95 | smtpput( $putargs ); | |||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||
| 332 | 95 | waitpid( $cat_pid,0 ); | |||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||
| 334 | 95 | files_eq_or_diff( 'data/example/' . $args->{'dest'}, 'tmp/result/' . $args->{'dest'}, 'smtp ' . $args->{'desc'} ); | |||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||
| 337 | 885 | ▶ | sub milter_process { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
milter_process: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 338 | 885 | my ( $args ) = @_; | |||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||
| 340 | 885 | ▶ | if ( ! -e $args->{'prefix'} . '/authentication_milter.json' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 341 | 0 | die "Could not find config"; | |||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||
| 343 | 885 | ▶ | if ( ! -e 'data/source/' . $args->{'source'} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 344 | 0 | die "Could not find source"; | |||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||
| 347 | client({ | ||||||||||||||||||||||||||||||||||||||
| 348 | 'prefix' => $args->{'prefix'}, | ||||||||||||||||||||||||||||||||||||||
| 349 | 'mailer_name' => 'test.module', | ||||||||||||||||||||||||||||||||||||||
| 350 | 'mail_file' => 'data/source/' . $args->{'source'}, | ||||||||||||||||||||||||||||||||||||||
| 351 | 'connect_ip' => $args->{'ip'}, | ||||||||||||||||||||||||||||||||||||||
| 352 | 'connect_name' => $args->{'name'}, | ||||||||||||||||||||||||||||||||||||||
| 353 | 'helo_host' => $args->{'name'}, | ||||||||||||||||||||||||||||||||||||||
| 354 | 'mail_from' => $args->{'from'}, | ||||||||||||||||||||||||||||||||||||||
| 355 | 'rcpt_to' => $args->{'to'}, | ||||||||||||||||||||||||||||||||||||||
| 356 | 885 | 'output' => 'tmp/result/' . $args->{'dest'}, | |||||||||||||||||||||||||||||||||||||
| 357 | }); | ||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||
| 359 | 852 | files_eq_or_diff( 'data/example/' . $args->{'dest'}, 'tmp/result/' . $args->{'dest'}, 'milter ' . $args->{'desc'} ); | |||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||
| 362 | 1016 | ▶ | sub smtpput { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
smtpput: called CC=23 SCAR=34.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 363 | 1016 | my ( $args ) = @_; | |||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||
| 365 | 1016 | my $mailer_name = $args->{'mailer_name'}; | |||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||
| 367 | 1016 | my $mail_file_a = $args->{'mail_file'}; | |||||||||||||||||||||||||||||||||||||
| 368 | 1016 | my $mail_from_a = $args->{'mail_from'}; | |||||||||||||||||||||||||||||||||||||
| 369 | 1016 | my $rcpt_to_a = $args->{'rcpt_to'}; | |||||||||||||||||||||||||||||||||||||
| 370 | 1016 | my $x_name_a = $args->{'connect_name'}; | |||||||||||||||||||||||||||||||||||||
| 371 | 1016 | my $x_addr_a = $args->{'connect_ip'}; | |||||||||||||||||||||||||||||||||||||
| 372 | 1016 | my $x_helo_a = $args->{'helo_host'}; | |||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||
| 374 | 1016 | my $sock_type = $args->{'sock_type'}; | |||||||||||||||||||||||||||||||||||||
| 375 | 1016 | my $sock_path = $args->{'sock_path'}; | |||||||||||||||||||||||||||||||||||||
| 376 | 1016 | my $sock_host = $args->{'sock_host'}; | |||||||||||||||||||||||||||||||||||||
| 377 | 1016 | my $sock_port = $args->{'sock_port'}; | |||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||
| 379 | 1016 | ▶ | my $eom_expect = $args->{'eom_expect'} || '250'; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'eom_expect'} || '250'
MC/DC100%1/1
$args->{'eom_expect'} || '250'
$args->{'eom_expect'}
Truth table100%2/2
A
A= $args->{'eom_expect'}
| |||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||
| 381 | 1016 | my $sock; | |||||||||||||||||||||||||||||||||||||
| 382 | 1016 | ▶ | if ( $sock_type eq 'inet' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | $sock = IO::Socket::INET->new( | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
'IO::Socket::INET'->new('Proto', 'tcp', 'PeerAddr', $sock_host, 'PeerPort', $sock_port) || die("could not open outbound SMTP socket: $!")
MC/DC0%0/1
'IO::Socket::INET'->new('Proto', 'tcp', 'PeerAddr', $sock_host, 'PeerPort', $sock_port) || die("could not open outbound SMTP socket: $!")
'IO::Socket::INET'->new('Proto', 'tcp', 'PeerAddr', $sock_host, 'PeerPort', $sock_port)
Truth table0%0/2
A
A= 'IO::Socket::INET'->new('Proto', 'tcp', 'PeerAddr', $sock_host, 'PeerPort', $sock_port)
| |||||||||||||||||||||||||||||||||||||||
| 384 | 'Proto' => 'tcp', | ||||||||||||||||||||||||||||||||||||||
| 385 | 'PeerAddr' => $sock_host, | ||||||||||||||||||||||||||||||||||||||
| 386 | 'PeerPort' => $sock_port, | ||||||||||||||||||||||||||||||||||||||
| 387 | ) || die "could not open outbound SMTP socket: $!"; | ||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||
| 389 | elsif ( $sock_type eq 'unix' ) { | ||||||||||||||||||||||||||||||||||||||
| 390 | 1016 | ▶ | $sock = IO::Socket::UNIX->new( | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'IO::Socket::UNIX'->new('Peer', $sock_path) || die("could not open outbound SMTP socket: $!")
MC/DC0%0/1
'IO::Socket::UNIX'->new('Peer', $sock_path) || die("could not open outbound SMTP socket: $!")
'IO::Socket::UNIX'->new('Peer', $sock_path)
Truth table50%1/2
A
A= 'IO::Socket::UNIX'->new('Peer', $sock_path)
| |||||||||||||||||||||||||||||||||||||||
| 391 | 'Peer' => $sock_path, | ||||||||||||||||||||||||||||||||||||||
| 392 | ) || die "could not open outbound SMTP socket: $!"; | ||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||
| 395 | 1016 | my $line = <$sock>; | |||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||
| 397 | 1016 | ▶ | if ( ($line =~ /^4/) || ($line =~ /^5/) ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line =~ /^4/u or $line =~ /^5/u
MC/DC0%0/2
$line =~ /^4/u or $line =~ /^5/u
$line =~ /^4/u
$line =~ /^5/u
Truth table33%1/3
A or B
A= $line =~ /^4/uB= $line =~ /^5/u
| |||||||||||||||||||||||||||||||||||||||
| 398 | 0 | die "Unexpected SMTP response $line"; | |||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||
| 401 | 1016 | ▶ | send_smtp_packet( $sock, 'EHLO ' . $mailer_name, '250' ) || die; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||
| 403 | 1016 | my $first_time = 1; | |||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||
| 405 | 1016 | ▶ | while ( @$mail_from_a ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||
| 407 | 1302 | ▶ | if ( ! $first_time ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 408 | 286 | ▶ | if ( ! send_smtp_packet( $sock, 'RSET', '250' ) ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 409 | 47 | $sock->close(); | |||||||||||||||||||||||||||||||||||||
| 410 | 47 | return; | |||||||||||||||||||||||||||||||||||||
| 411 | }; | ||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||
| 413 | 1255 | $first_time = 0; | |||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||
| 415 | 1255 | my $mail_file = shift @$mail_file_a; | |||||||||||||||||||||||||||||||||||||
| 416 | 1255 | my $mail_from = shift @$mail_from_a; | |||||||||||||||||||||||||||||||||||||
| 417 | 1255 | my $rcpt_to = shift @$rcpt_to_a; | |||||||||||||||||||||||||||||||||||||
| 418 | 1255 | my $x_name = shift @$x_name_a; | |||||||||||||||||||||||||||||||||||||
| 419 | 1255 | my $x_addr = shift @$x_addr_a; | |||||||||||||||||||||||||||||||||||||
| 420 | 1255 | my $x_helo = shift @$x_helo_a; | |||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||
| 422 | 1255 | my $mail_data = q{}; | |||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||
| 424 | 1255 | ▶ | if ( $mail_file eq '-' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | while ( my $l = <> ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $mail_data .= $l; | |||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||
| 429 | else { | ||||||||||||||||||||||||||||||||||||||
| 430 | 1255 | ▶ | if ( ! -e $mail_file ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 431 | 0 | die "Mail file $mail_file does not exist"; | |||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||
| 433 | 1255 | open my $inf, '<', $mail_file; | |||||||||||||||||||||||||||||||||||||
| 434 | 1255 | my @all = <$inf>; | |||||||||||||||||||||||||||||||||||||
| 435 | 1255 | $mail_data = join( q{}, @all ); | |||||||||||||||||||||||||||||||||||||
| 436 | 1255 | close $inf; | |||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||
| 439 | 1255 | $mail_data =~ s/\015?\012/\015\012/g; | |||||||||||||||||||||||||||||||||||||
| 440 | # Handle transparency | ||||||||||||||||||||||||||||||||||||||
| 441 | 1255 | $mail_data =~ s/\015\012\./\015\012\.\./g; | |||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||
| 443 | 1255 | ▶ | send_smtp_packet( $sock, 'XFORWARD NAME=' . $x_name, '250' ) || die; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 444 | 1255 | ▶ | send_smtp_packet( $sock, 'XFORWARD ADDR=' . $x_addr, '250' ) || die; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 445 | 1255 | ▶ | send_smtp_packet( $sock, 'XFORWARD HELO=' . $x_helo, '250' ) || die; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||
| 447 | 1255 | ▶ | send_smtp_packet( $sock, 'MAIL FROM:' . $mail_from, '250' ) || die; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 448 | 1255 | ▶ | send_smtp_packet( $sock, 'RCPT TO:' . $rcpt_to, '250' ) || die; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 449 | 1255 | ▶ | send_smtp_packet( $sock, 'DATA', '354' ) || die; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||
| 451 | 1255 | print $sock $mail_data; | |||||||||||||||||||||||||||||||||||||
| 452 | 1255 | print $sock "\r\n"; | |||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||
| 454 | 1255 | ▶ | send_smtp_packet( $sock, '.', $eom_expect ) || return 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||
| 458 | 969 | ▶ | send_smtp_packet( $sock, 'QUIT', '221' ) || return 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 459 | 969 | $sock->close(); | |||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||
| 461 | 969 | return 1; | |||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||
| 464 | 11056 | ▶ | sub send_smtp_packet { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
send_smtp_packet: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 465 | 11056 | my ( $socket, $send, $expect ) = @_; | |||||||||||||||||||||||||||||||||||||
| 466 | 11056 | print $socket "$send\r\n"; | |||||||||||||||||||||||||||||||||||||
| 467 | 11056 | my $recv = <$socket>; | |||||||||||||||||||||||||||||||||||||
| 468 | 11056 | ▶ | $recv = '' if !defined $recv; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 469 | 11056 | ▶ | while ( $recv =~ /^\d\d\d\-/ ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 470 | 4056 | $recv = <$socket>; | |||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||
| 472 | 11056 | ▶ | if ( $recv =~ /^$expect/ ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 473 | 11009 | return 1; | |||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||
| 475 | else { | ||||||||||||||||||||||||||||||||||||||
| 476 | 47 | $recv =~ s/\r?\n?$//; | |||||||||||||||||||||||||||||||||||||
| 477 | 47 | $send =~ s/\r?\n?$//; | |||||||||||||||||||||||||||||||||||||
| 478 | 47 | warn "SMTP Send expected \"$expect\" received \"$recv\" when sending \"$send\"\n"; | |||||||||||||||||||||||||||||||||||||
| 479 | 47 | return 0; | |||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||
| 483 | 1033 | ▶ | sub smtpcat { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
smtpcat: called CC=23 SCAR=32.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 484 | 1033 | my ( $args ) = @_; | |||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||
| 486 | 1033 | my $sock_type = $args->{'sock_type'}; | |||||||||||||||||||||||||||||||||||||
| 487 | 1033 | my $sock_path = $args->{'sock_path'}; | |||||||||||||||||||||||||||||||||||||
| 488 | 1033 | my $sock_host = $args->{'sock_host'}; | |||||||||||||||||||||||||||||||||||||
| 489 | 1033 | my $sock_port = $args->{'sock_port'}; | |||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||
| 491 | 1033 | my $remove = $args->{'remove'}; | |||||||||||||||||||||||||||||||||||||
| 492 | 1033 | my $output = $args->{'output'}; | |||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||
| 494 | 1033 | my @out_lines; | |||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||
| 496 | my $sock; | ||||||||||||||||||||||||||||||||||||||
| 497 | 1033 | ▶ | if ( $sock_type eq 'inet' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | $sock = IO::Socket::INET->new( | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
'IO::Socket::INET'->new('Listen', 5, 'LocalHost', $sock_host, 'LocalPort', $sock_port, 'Protocol', 'tcp') || die("could not open socket: $!")
MC/DC0%0/1
'IO::Socket::INET'->new('Listen', 5, 'LocalHost', $sock_host, 'LocalPort', $sock_port, 'Protocol', 'tcp') || die("could not open socket: $!")
'IO::Socket::INET'->new('Listen', 5, 'LocalHost', $sock_host, 'LocalPort', $sock_port, 'Protocol', 'tcp')
Truth table0%0/2
A
A= 'IO::Socket::INET'->new('Listen', 5, 'LocalHost', $sock_host, 'LocalPort', $sock_port, 'Protocol', 'tcp')
| |||||||||||||||||||||||||||||||||||||||
| 499 | 'Listen' => 5, | ||||||||||||||||||||||||||||||||||||||
| 500 | 'LocalHost' => $sock_host, | ||||||||||||||||||||||||||||||||||||||
| 501 | 'LocalPort' => $sock_port, | ||||||||||||||||||||||||||||||||||||||
| 502 | 'Protocol' => 'tcp', | ||||||||||||||||||||||||||||||||||||||
| 503 | ) || die "could not open socket: $!"; | ||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||
| 505 | elsif ( $sock_type eq 'unix' ) { | ||||||||||||||||||||||||||||||||||||||
| 506 | # Some filesystems briefly refuse to bind a path whose previous socket | ||||||||||||||||||||||||||||||||||||||
| 507 | # is still closing, so retry for a short while | ||||||||||||||||||||||||||||||||||||||
| 508 | 1033 | my $deadline = time + 10; | |||||||||||||||||||||||||||||||||||||
| 509 | 1033 | ▶ | until ( $sock ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 510 | 1033 | unlink $sock_path; | |||||||||||||||||||||||||||||||||||||
| 511 | 1033 | $sock = IO::Socket::UNIX->new( | |||||||||||||||||||||||||||||||||||||
| 512 | 'Listen' => 5, | ||||||||||||||||||||||||||||||||||||||
| 513 | 'Local' => $sock_path, | ||||||||||||||||||||||||||||||||||||||
| 514 | ); | ||||||||||||||||||||||||||||||||||||||
| 515 | 1033 | ▶ | last if $sock; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | die "could not open socket $sock_path: $!" if time > $deadline; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 517 | 0 | sleep 0.05; | |||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||
| 521 | # Listen before forking, so the socket is ready when we return | ||||||||||||||||||||||||||||||||||||||
| 522 | 1033 | my $cat_pid = fork(); | |||||||||||||||||||||||||||||||||||||
| 523 | 1033 | ▶ | die "unable to fork: $!" unless defined($cat_pid); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 524 | 1033 | ▶ | if ( $cat_pid ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 525 | 995 | $sock->close(); | |||||||||||||||||||||||||||||||||||||
| 526 | 995 | return $cat_pid; | |||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||
| 529 | 38 | my $accept = $sock->accept(); | |||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||
| 531 | 38 | print $accept "220 smtp.cat ESMTP Test\r\n"; | |||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | local $SIG{'ALRM'} = sub{ die "Timeout\n" }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||
| 534 | 38 | alarm( 60 ); | |||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||
| 536 | 38 | while ( 1 ) { | |||||||||||||||||||||||||||||||||||||
| 537 | 353 | my $command = <$accept>; | |||||||||||||||||||||||||||||||||||||
| 538 | 353 | ▶ | last unless defined $command; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 539 | 353 | alarm( 60 ); | |||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||
| 541 | 353 | ▶ | if ( $command =~ /^HELO/ ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 542 | 0 | push @out_lines, $command; | |||||||||||||||||||||||||||||||||||||
| 543 | 0 | print $accept "250 HELO Ok\r\n"; | |||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||
| 545 | elsif ( $command =~ /^EHLO/ ) { | ||||||||||||||||||||||||||||||||||||||
| 546 | 38 | push @out_lines, $command; | |||||||||||||||||||||||||||||||||||||
| 547 | 38 | print $accept "250 EHLO Ok\r\n"; | |||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||
| 549 | elsif ( $command =~ /^MAIL/ ) { | ||||||||||||||||||||||||||||||||||||||
| 550 | 45 | push @out_lines, $command; | |||||||||||||||||||||||||||||||||||||
| 551 | 45 | print $accept "250 MAIL Ok\r\n"; | |||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||
| 553 | elsif ( $command =~ /^XFORWARD/ ) { | ||||||||||||||||||||||||||||||||||||||
| 554 | 135 | push @out_lines, $command; | |||||||||||||||||||||||||||||||||||||
| 555 | 135 | print $accept "250 XFORWARD Ok\r\n"; | |||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||
| 557 | elsif ( $command =~ /^RCPT/ ) { | ||||||||||||||||||||||||||||||||||||||
| 558 | 45 | push @out_lines, $command; | |||||||||||||||||||||||||||||||||||||
| 559 | 45 | print $accept "250 RCPT Ok\r\n"; | |||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||
| 561 | elsif ( $command =~ /^RSET/ ) { | ||||||||||||||||||||||||||||||||||||||
| 562 | 7 | push @out_lines, $command; | |||||||||||||||||||||||||||||||||||||
| 563 | 7 | print $accept "250 RSET Ok\r\n"; | |||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||
| 565 | elsif ( $command =~ /^DATA/ ) { | ||||||||||||||||||||||||||||||||||||||
| 566 | 45 | push @out_lines, $command; | |||||||||||||||||||||||||||||||||||||
| 567 | 45 | print $accept "354 Send\r\n"; | |||||||||||||||||||||||||||||||||||||
| 568 | DATA: | ||||||||||||||||||||||||||||||||||||||
| 569 | 45 | ▶ | while ( my $line = <$accept> ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 570 | 3059 | alarm( 60 ); | |||||||||||||||||||||||||||||||||||||
| 571 | 3059 | push @out_lines, $line; | |||||||||||||||||||||||||||||||||||||
| 572 | 3059 | ▶ | last DATA if $line eq ".\r\n"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 573 | # Handle transparency | ||||||||||||||||||||||||||||||||||||||
| 574 | 3014 | ▶ | if ( $line =~ /^\./ ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 575 | 28 | $line = substr( $line, 1 ); | |||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||
| 578 | 45 | print $accept "250 DATA Ok\r\n"; | |||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||
| 580 | elsif ( $command =~ /^QUIT/ ) { | ||||||||||||||||||||||||||||||||||||||
| 581 | 38 | push @out_lines, $command; | |||||||||||||||||||||||||||||||||||||
| 582 | 38 | print $accept "221 Bye\r\n"; | |||||||||||||||||||||||||||||||||||||
| 583 | 38 | last; | |||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||
| 585 | else { | ||||||||||||||||||||||||||||||||||||||
| 586 | 0 | push @out_lines, $command; | |||||||||||||||||||||||||||||||||||||
| 587 | 0 | print $accept "250 Unknown Ok\r\n"; | |||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||
| 591 | 38 | open my $file, '>', $output; | |||||||||||||||||||||||||||||||||||||
| 592 | 38 | my $i = 0; | |||||||||||||||||||||||||||||||||||||
| 593 | 38 | foreach my $line ( @out_lines ) { | |||||||||||||||||||||||||||||||||||||
| 594 | 3412 | $i++; | |||||||||||||||||||||||||||||||||||||
| 595 | 3412 | ▶ | $line = "############\n" if grep { $i == $_ } @$remove; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 596 | 3412 | print $file $line; | |||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||
| 598 | 38 | close $file; | |||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||
| 600 | 38 | $accept->close(); | |||||||||||||||||||||||||||||||||||||
| 601 | 38 | $sock->close(); | |||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||
| 603 | 38 | exit 0; | |||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||
| 606 | 885 | ▶ | sub client { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
client: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 607 | 885 | my ( $args ) = @_; | |||||||||||||||||||||||||||||||||||||
| 608 | 885 | my $pid = fork(); | |||||||||||||||||||||||||||||||||||||
| 609 | 885 | ▶ | die "unable to fork: $!" unless defined($pid); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 610 | 885 | ▶ | if ( ! $pid ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||
| 612 | 33 | my $output = $args->{'output'}; | |||||||||||||||||||||||||||||||||||||
| 613 | 33 | delete $args->{'output'}; | |||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||
| 615 | 33 | $Mail::Milter::Authentication::Config::PREFIX = $args->{'prefix'}; | |||||||||||||||||||||||||||||||||||||
| 616 | 33 | delete $args->{'prefix'}; | |||||||||||||||||||||||||||||||||||||
| 617 | 33 | $args->{'testing'} = 1; | |||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||
| 619 | 33 | my $client = Mail::Milter::Authentication::Client->new( $args ); | |||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||
| 621 | 33 | $client->process(); | |||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||
| 623 | 33 | open my $file, '>', $output; | |||||||||||||||||||||||||||||||||||||
| 624 | 33 | print $file $client->result(); | |||||||||||||||||||||||||||||||||||||
| 625 | 33 | close $file; | |||||||||||||||||||||||||||||||||||||
| 626 | 33 | exit 0; | |||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||
| 629 | 852 | waitpid( $pid, 0 ); | |||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||
| 632 | 112 | 1; | |||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||
| 634 | __END__ | ||||||||||||||||||||||||||||||||||||||