blib/lib/Langertha/Holmgang/Sim/Linux/Postfix.pm

filter: Statementstmt 81.4% 215 / 264 Branchbran 53.5% 91 / 170 Conditioncond 41.4% 53 / 128 MC/DCmcdc 10.6% 7 / 66 Subroutinesub 95.2% 20 / 21 Podpod 100% 9 / 9 totaltotal 60.0% 395 / 658 CC 154 SCAR 37.1
CC
154
Cov
64%
postconf
88.4
postfix
80.0
postsuper
62.2
CRAP 41.0
« blib/lib/Langertha/Holmgang/World.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Helm.pm »
1 package Langertha::Holmgang::Sim::Linux::Postfix;
2 # ABSTRACT: Postfix on a simulated Linux server — postconf, postmap, newaliases, queue
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.001';
9  
10  
11 23 ▶sub _lx { 'Langertha::Holmgang::Sim::Linux' }
Subroutine _lx: called CC=1 SCAR=0.0
12 11 ▶sub _text { _lx()->can('_file_text')->(@_) }
Subroutine _text: called CC=1 SCAR=0.0
13  
14 2 my $MAIN = '/etc/postfix/main.cf';
15  
16 2 our %DEFAULT = (
17 myhostname => 'mail.example.com', mydomain => 'example.com', myorigin => '$myhostname', mydestination => '$myhostname, localhost.$mydomain, localhost',
18 relayhost => '', mynetworks => '127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128', mynetworks_style => 'host', inet_interfaces => 'all',
19 inet_protocols => 'all', message_size_limit => '10240000', mailbox_size_limit => '51200000', smtpd_relay_restrictions =>
20 'permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination', smtpd_recipient_restrictions => '',
21 smtp_sasl_auth_enable => 'no', smtp_sasl_password_maps => '', smtp_sasl_security_options => 'noplaintext, noanonymous',
22 smtp_tls_security_level => '', smtpd_tls_security_level => '', transport_maps => '', relay_domains => '', virtual_alias_maps => '',
23 virtual_alias_domains => '$virtual_alias_maps', alias_maps => 'hash:/etc/aliases', alias_database => 'hash:/etc/aliases',
24 sender_canonical_maps => '', recipient_delimiter => '', compatibility_level => '0', maximal_queue_lifetime => '5d',
25 bounce_queue_lifetime => '5d', smtpd_banner => '$myhostname ESMTP $mail_name', smtp_tls_CAfile => '', smtpd_sasl_auth_enable => 'no',
26 header_size_limit => '102400', default_destination_concurrency_limit => '20', smtp_tls_wrappermode => 'no',
27 );
28 2 my %NUMERIC = map { $_ => 1 } qw( message_size_limit mailbox_size_limit header_size_limit default_destination_concurrency_limit );
29  
30  
31 6 ▶sub parse_main {
Subroutine parse_main: called CC=8 SCAR=24.0
Pod documented
32 6 my ($text) = @_;
33 6 my ( %p, $cur );
34 6 ▶ for my $l ( split /\n/, $text // '' ) {
Condition50%1/2
$text // ""
l!l
60
MC/DC0%0/1
$text // ""
$text
Truth table50%1/2
A
A= $text
Aresult
11
00
35 27 ▶ next if $l =~ /\A\s*(?:#|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\A\s*(?:#|\z)/ 0 27 27
36 0 ▶ if ( $l =~ /\A\s/ && defined $cur ) { $p{$cur} .= ' ' . ( $l =~ s/\A\s+|\s+\z//gr ); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A\s/ and defined $cur) 0 27 27
Condition33%1/3
$l =~ /\A\s/ and defined $cur
!ll&&!rl&&r
2700
MC/DC0%0/2
$l =~ /\A\s/ and defined $cur
$l =~ /\A\s/ defined $cur
Truth table33%1/3
A and B
A= $l =~ /\A\s/B= defined $cur
ABresult
0X0
100
111
37 27 ▶ if ( $l =~ /\A([A-Za-z0-9_]+)\s*=\s*(.*?)\s*\z/ ) { ( $cur, $p{$1} ) = ( $1, $2 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /\A([A-Za-z0-9_]+)\s*=\s*(.*?)\s*\z/) 27 0 27
38 }
39 6 s/\s+/ /g for values %p;
40 6 return \%p;
41 }
42  
43 4 ▶sub _check {
Subroutine _check: called CC=3 SCAR=11.0
44 4 my ($p) = @_;
45 4 for my $k ( sort grep { $NUMERIC{$_} } keys %$p ) {
46 3 ▶ return "/usr/sbin/postconf: fatal: bad numerical configuration: $k = $p->{$k}" unless $p->{$k} =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $$p{$k} =~ /\A\d+\z/ 2 1 3
47 }
48 2 return undef;
49 }
50  
51  
52 1 ▶sub prepare {
Subroutine prepare: called CC=3 SCAR=12.0
Pod documented
53 1 my ( $dev, $ctx ) = @_;
54 1 ▶ my $pf = $dev->{postfix} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $pf = $$dev{"postfix"} or return 1 0 1
55 1 ▶ $pf->{running} //= parse_main( _text( $dev, $MAIN ) );
Condition33%1/3
$$pf{"running"} //= parse_main(_text($dev, $MAIN))
l!l&&r!l&&!r
010
MC/DC0%0/2
$$pf{"running"} //= parse_main(_text($dev, $MAIN))
$$pf{"running"} parse_main(_text($dev, $MAIN))
Truth table33%1/3
A //= B
A= $$pf{"running"}B= parse_main(_text($dev, $MAIN))
ABresult
1X1
011
000
56 1 return;
57 }
58  
59 4 ▶sub _reload {
Subroutine _reload: called CC=2 SCAR=6.9
60 4 my ($dev) = @_;
61 4 my $p = parse_main( _text( $dev, $MAIN ) );
62 4 ▶ if ( my $e = _check($p) ) { return ( $e, 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = _check($p)) 2 2 4
63 2 $dev->{postfix}{running} = $p;
64 2 return ( '', 1 );
65 }
66  
67  
68 2 ▶sub service_event {
Subroutine service_event: called CC=3 SCAR=11.0
Pod documented
69 2 my ( $dev, $verb ) = @_;
70 2 ▶ return if $verb eq 'stop';
Branch: 1 branch
BranchTrueFalseTotal
if $verb eq "stop" 0 2 2
71 2 my ( $e, $ok ) = _reload($dev);
72 2 ▶ die "Job for postfix.service failed because the control process exited with error code.\n$e\n" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 1 2
73 1 return;
74 }
75  
76 7 ▶sub _running { my $s = ( $_[0]{services} || {} )->{postfix}; return $s && $s->{active} ? 1 : 0 }
Subroutine _running: called CC=4 SCAR=16.9
Branch: 1 branch
BranchTrueFalseTotal
$s && $$s{'active'} ? : 7 0 7
Condition40%2/5
$_[0]{'services'} || {}
l!l
70
$s and $$s{"active"}
!ll&&!rl&&r
007
MC/DC0%0/1
$_[0]{'services'} || {}
$_[0]{'services'}
MC/DC0%0/2
$s and $$s{"active"}
$s $$s{"active"}
Truth table50%1/2
A
A= $_[0]{'services'}
Aresult
11
00
Truth table33%1/3
A and B
A= $sB= $$s{"active"}
ABresult
0X0
100
111
77  
78  
79 4 ▶sub postconf {
Subroutine postconf: called CC=31 SCAR=44.8
Pod documented
80 4 my ( $dev, $av ) = @_;
81 4 my @a = @$av;
82 4 my %f;
83 my @n;
84 4 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 8 4 12
85 8 my $x = shift @a;
86 8 ▶ if ( $x =~ /\A-([ndhexX]+)\z/ ) { $f{$_} = 1 for split //, $1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($x =~ /\A-([ndhexX]+)\z/) { } 4 4 8
elsif ($x =~ /\A-[cM F P]/) { } 0 4 4
87 0 elsif ( $x =~ /\A-[cM F P]/ ) { return ( '', 0 ) }
88 4 else { push @n, $x }
89 }
90 4 ▶ my $text = _text( $dev, $MAIN ) // '';
Condition50%1/2
_text($dev, $MAIN) // ""
l!l
40
MC/DC0%0/1
_text($dev, $MAIN) // ""
_text($dev, $MAIN)
Truth table50%1/2
A
A= _text($dev, $MAIN)
Aresult
11
00
91 4 ▶ if ( $f{e} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f{"e"}) 3 1 4
92 3 my @lines = split /\n/, $text, -1;
93 3 ▶ pop @lines if @lines && $lines[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if @lines and $lines[-1] eq "" 3 0 3
Condition33%1/3
@lines and $lines[-1] eq ""
!ll&&!rl&&r
003
MC/DC0%0/2
@lines and $lines[-1] eq ""
@lines $lines[-1] eq ""
Truth table33%1/3
A and B
A= @linesB= $lines[-1] eq ""
ABresult
0X0
100
111
94 3 for my $kv (@n) {
95 3 ▶ my ( $k, $v ) = $kv =~ /\A\s*([A-Za-z0-9_]+)\s*=\s*(.*?)\s*\z/ or return ( "postconf: fatal: invalid parameter assignment: $kv", 0 );
Branch: 1 branch
BranchTrueFalseTotal
() = $kv =~ /\A\s*([A-Za-z0-9_]+)\s*=\s*(.*?)\s*\z/ or return "postconf: fatal: invalid parameter assignment: $kv", 0 3 0 3
96 3 my $done;
97 3 ▶ for ( my $i = 0; $i < @lines; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @lines) 11 1 12
98 11 ▶ next unless $lines[$i] =~ /\A\Q$k\E\s*=/;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines[$i] =~ /\A\Q$k\E\s*=/ 9 2 11
99 2 my $j = $i + 1;
100 2 ▶ $j++ while $j < @lines && $lines[$j] =~ /\A\s+\S/;
Branch: 1 branch
BranchTrueFalseTotal
$j < @lines and $lines[$j] =~ /\A\s+\S/ and do { ++$j } 0 2 2
Condition66%2/3
$j < @lines and $lines[$j] =~ /\A\s+\S/
!ll&&!rl&&r
110
MC/DC0%0/2
$j < @lines and $lines[$j] =~ /\A\s+\S/
$j < @lines $lines[$j] =~ /\A\s+\S/
Truth table66%2/3
A and B
A= $j < @linesB= $lines[$j] =~ /\A\s+\S/
ABresult
0X0
100
111
101 2 splice @lines, $i, $j - $i, "$k = $v";
102 2 $done = 1;
103 2 last;
104 }
105 3 ▶ push @lines, "$k = $v" unless $done;
Branch: 1 branch
BranchTrueFalseTotal
unless $done 1 2 3
106 }
107 3 _lx()->can('_file_set')->( $dev, $MAIN, join( "\n", @lines ) . "\n" );
108 3 return ( '', 1 );
109 }
110 1 ▶ if ( $f{X} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f{"X"}) 0 1 1
111 0 my @lines = split /\n/, $text;
112 0 my @out;
113 0 ▶ for ( my $i = 0; $i < @lines; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @lines) 0 0 0
114 0 ▶ if ( grep { $lines[$i] =~ /\A\Q$_\E\s*=/ } @n ) { $i++ while $i + 1 < @lines && $lines[ $i + 1 ] =~ /\A\s+\S/; next }
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$lines[$i] =~ /\A\Q$_\E\s*=/;} @n) 0 0 0
$i + 1 < @lines and $lines[$i + 1] =~ /\A\s+\S/ and do { ++$i } 0 0 0
Condition0%0/3
$i + 1 < @lines and $lines[$i + 1] =~ /\A\s+\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$i + 1 < @lines and $lines[$i + 1] =~ /\A\s+\S/
$i + 1 < @lines $lines[$i + 1] =~ /\A\s+\S/
Truth table0%0/3
A and B
A= $i + 1 < @linesB= $lines[$i + 1] =~ /\A\s+\S/
ABresult
0X0
100
111
115 0 push @out, $lines[$i];
116 }
117 0 _lx()->can('_file_set')->( $dev, $MAIN, join( "\n", @out ) . "\n" );
118 0 return ( '', 1 );
119 }
120 1 my $p = parse_main($text);
121 1 ▶ my %all = $f{d} ? %DEFAULT : $f{n} ? %$p : ( %DEFAULT, %$p );
Branch: 2 branches
BranchTrueFalseTotal
$f{'d'} ? : 0 1 1
$f{'n'} ? : 0 1 1
122 1 ▶ my @show = @n ? @n : sort keys %all;
Branch: 1 branch
BranchTrueFalseTotal
@n ? : 1 0 1
123 1 my ( @l, $ok );
124 1 $ok = 1;
125 1 for my $k (@show) {
126 0 ▶ if ( !exists $all{$k} && !exists $DEFAULT{$k} ) { push @l, "postconf: warning: $k: unknown parameter"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $all{$k} or exists $Langertha::Holmgang::Sim::Linux::Postfix::DEFAULT{$k}) 0 1 1
Condition33%1/3
exists $all{$k} or exists $Langertha::Holmgang::Sim::Linux::Postfix::DEFAULT{$k}
l!l&&r!l&&!r
100
MC/DC0%0/2
exists $all{$k} or exists $Langertha::Holmgang::Sim::Linux::Postfix::DEFAULT{$k}
exists $all{$k} exists $Langertha::Holmgang::Sim::Linux::Postfix::DEFAULT{$k}
Truth table33%1/3
A or B
A= exists $all{$k}B= exists $Langertha::Holmgang::Sim::Linux::Postfix::DEFAULT{$k}
ABresult
1X1
011
000
127 1 ▶ my $v = exists $all{$k} ? $all{$k} : $DEFAULT{$k};
Branch: 1 branch
BranchTrueFalseTotal
exists $all{$k} ? : 1 0 1
128 1 ▶ next if $f{n} && !exists $p->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if $f{"n"} and not exists $$p{$k} 0 1 1
Condition33%1/3
$f{"n"} and not exists $$p{$k}
!ll&&!rl&&r
100
MC/DC0%0/2
$f{"n"} and not exists $$p{$k}
$f{"n"} not exists $$p{$k}
Truth table33%1/3
A and not(B)
A= $f{"n"}B= not exists $$p{$k}
ABresult
0X0
100
111
129 1 ▶ push @l, $f{h} ? $v : "$k = $v";
Branch: 1 branch
BranchTrueFalseTotal
$f{'h'} ? : 1 0 1
130 }
131 1 return ( join( "\n", @l ), $ok );
132 }
133  
134 3 ▶sub _flush {
Subroutine _flush: called CC=12 SCAR=25.9
135 3 my ( $dev, $only ) = @_;
136 3 my $pf = $dev->{postfix};
137 3 my @keep;
138 3 ▶ for my $m ( @{ $pf->{queue} || [] } ) {
Condition50%1/2
$$pf{'queue'} || []
l!l
30
MC/DC0%0/1
$$pf{'queue'} || []
$$pf{'queue'}
Truth table50%1/2
A
A= $$pf{'queue'}
Aresult
11
00
139 6 ▶ my $go = ( $m->{queue} // q{deferred} ) ne q{hold} && ( !defined $only || $m->{id} eq $only ) && $m->{deliver_when};
Condition45%5/11
($$m{'queue'} // 'deferred') ne 'hold' && (!defined($only) || $$m{'id'} eq $only) && $$m{'deliver_when'}
!ll&&!rl&&r
033
($$m{"queue"} // "deferred") ne "hold" and !defined($only) || $$m{"id"} eq $only
!ll&&!rl&&r
006
$$m{"queue"} // "deferred"
l!l
06
not defined $only or $$m{"id"} eq $only
l!l&&r!l&&!r
600
MC/DC0%0/4
($$m{'queue'} // 'deferred') ne 'hold' && (!defined($only) || $$m{'id'} eq $only) && $$m{'deliver_when'}
$$m{"queue"} not defined $only $$m{"id"} eq $only $$m{'deliver_when'}
Truth table0%0/6
A and not(B) or C && D
A= $$m{"queue"}B= not defined $onlyC= $$m{"id"} eq $onlyD= $$m{'deliver_when'}
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
140 6 ▶ if ($go) {
Branch: 1 branch
BranchTrueFalseTotal
if ($go) 3 3 6
141 3 ▶ for my $c ( @{ $m->{deliver_when} || [] } ) {
Condition50%1/2
$$m{'deliver_when'} || []
l!l
30
MC/DC0%0/1
$$m{'deliver_when'} || []
$$m{'deliver_when'}
Truth table50%1/2
A
A= $$m{'deliver_when'}
Aresult
11
00
142 5 my ($ok) = _lx()->can('_condition')->( $dev, $c );
143 5 ▶ $go = 0, last unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 2 3 5
144 }
145 }
146 6 ▶ if ($go) { push @{ $pf->{delivered} }, $m->{id} }
Branch: 1 branch
BranchTrueFalseTotal
if ($go) { } 1 5 6
147 5 else { push @keep, $m }
148 }
149 3 $pf->{queue} = \@keep;
150 3 return;
151 }
152  
153  
154 2 ▶sub postfix {
Subroutine postfix: called CC=14 SCAR=43.8
Pod documented
155 2 my ( $dev, $av ) = @_;
156 2 ▶ my $verb = $av->[0] // '';
Condition50%1/2
$$av[0] // ""
l!l
20
MC/DC0%0/1
$$av[0] // ""
$$av[0]
Truth table50%1/2
A
A= $$av[0]
Aresult
11
00
157 2 ▶ if ( $verb eq 'check' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "check") 0 2 2
158 0 my $e = _check( parse_main( _text( $dev, $MAIN ) ) );
159 0 ▶ return defined $e ? ( $e, 0 ) : ( '', 1 );
Branch: 1 branch
BranchTrueFalseTotal
defined $e ? : 0 0 0
160 }
161 2 ▶ if ( $verb eq 'reload' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "reload") 2 0 2
162 2 ▶ return ( 'postfix/postfix-script: fatal: the Postfix mail system is not running', 0 ) unless _running($dev);
Branch: 1 branch
BranchTrueFalseTotal
unless _running($dev) 0 2 2
163 2 my ( $e, $ok ) = _reload($dev);
164 2 ▶ return ( $e, 0 ) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 1 2
165 1 return ( 'postfix/postfix-script: refreshing the Postfix mail system', 1 );
166 }
167 0 ▶ if ( $verb eq 'status' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "status") 0 0 0
168 0 ▶ return _running($dev) ? ( 'postfix/postfix-script: the Postfix mail system is running: PID: 1342', 1 )
Branch: 1 branch
BranchTrueFalseTotal
_running($dev) ? : 0 0 0
169 : ( 'postfix/postfix-script: the Postfix mail system is not running', 1 );
170 }
171 0 ▶ if ( $verb eq 'flush' ) { _flush($dev) if _running($dev); return ( '', 1 ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($verb eq "flush") 0 0 0
if _running($dev) 0 0 0
172 0 ▶ if ( $verb eq 'start' || $verb eq 'stop' || $verb eq 'restart' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "start" or $verb eq "stop" or $verb eq "restart") 0 0 0
Condition0%0/6
$verb eq "start" or $verb eq "stop" or $verb eq "restart"
l!l&&r!l&&!r
000
$verb eq "start" or $verb eq "stop"
l!l&&r!l&&!r
000
MC/DC0%0/3
$verb eq "start" or $verb eq "stop" or $verb eq "restart"
$verb eq "start" $verb eq "stop" $verb eq "restart"
Truth table0%0/4
A or B or C
A= $verb eq "start"B= $verb eq "stop"C= $verb eq "restart"
ABCresult
1XX1
01X1
0011
0000
173 0 return _lx()->can('_systemctl')->( $dev, [ $verb, 'postfix' ], {} );
174 }
175 0 return ( "postfix: fatal: unknown command: '$verb'. Usage: postfix start (or stop, reload, abort, flush, check, status, set-permissions, upgrade-configuration)", 0 );
176 }
177  
178 2 ▶sub _build_db {
Subroutine _build_db: called CC=12 SCAR=25.8
179 2 my ( $dev, $src, $prog ) = @_;
180 2 my $e = _lx()->can('_file_entry')->( $dev, $src );
181 2 ▶ return ( "$prog: fatal: open $src: No such file or directory", 0 ) unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 0 2 2
182 2 ▶ my $text = _text( $dev, $src ) // '';
Condition50%1/2
_text($dev, $src) // ""
l!l
20
MC/DC0%0/1
_text($dev, $src) // ""
_text($dev, $src)
Truth table50%1/2
A
A= _text($dev, $src)
Aresult
11
00
183 2 my @w;
184 2 my $n = 0;
185 2 for my $l ( split /\n/, $text ) {
186 3 $n++;
187 3 ▶ next if $l =~ /\A\s*(?:#|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\A\s*(?:#|\z)/ 0 3 3
188 3 ▶ next if $l =~ /\A\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\A\s/ 0 3 3
189 3 ▶ my $ok = $prog eq 'postalias' ? $l =~ /\A\S+?:\s*\S/ : $l =~ /\A\S+\s+\S/;
Branch: 1 branch
BranchTrueFalseTotal
$prog eq 'postalias' ? : 2 1 3
190 3 ▶ push @w, $prog eq 'postalias'
Branch: 2 branches
BranchTrueFalseTotal
unless $ok 0 3 3
$prog eq 'postalias' ? : 0 0 0
191 ? "postalias: warning: $src, line $n: need name:value pair"
192 : "postmap: warning: $src, line $n: expected format: key whitespace value" unless $ok;
193 }
194 2 ▶ my %db = ( content => $text, owner => $e->{owner} // 'root', group => $e->{group} // 'root', mode => $e->{mode} // '0644' );
Condition100%6/6
$$e{"owner"} // "root"
l!l
11
$$e{"group"} // "root"
l!l
11
$$e{"mode"} // "0644"
l!l
11
MC/DC100%1/1
$$e{"owner"} // "root"
$$e{"owner"}
MC/DC100%1/1
$$e{"group"} // "root"
$$e{"group"}
MC/DC100%1/1
$$e{"mode"} // "0644"
$$e{"mode"}
Truth table100%2/2
A
A= $$e{"owner"}
Aresult
11
00
Truth table100%2/2
A
A= $$e{"group"}
Aresult
11
00
Truth table100%2/2
A
A= $$e{"mode"}
Aresult
11
00
195 2 $dev->{files}{"$src.db"} = \%db;
196 2 return ( join( "\n", @w ), 1 );
197 }
198  
199 4 ▶sub _map_arg {
Subroutine _map_arg: called CC=2 SCAR=6.9
200 4 my ($a) = @_;
201 4 my ( $type, $f ) = $a =~ /\A(?:(\w+):)?(.+)\z/;
202 4 ▶ return ( $type // 'hash', $f );
Condition100%2/2
$type // "hash"
l!l
22
MC/DC100%1/1
$type // "hash"
$type
Truth table100%2/2
A
A= $type
Aresult
11
00
203 }
204  
205  
206 4 ▶sub postmap {
Subroutine postmap: called CC=19 SCAR=30.9
Pod documented
207 4 my ( $dev, $av, $ctx, $prog ) = @_;
208 4 ▶ $prog //= 'postmap';
Condition100%2/2
$prog //= "postmap"
l!l
13
MC/DC100%1/1
$prog //= "postmap"
$prog
Truth table100%2/2
A
A= $prog
Aresult
11
00
209 4 my @a = @$av;
210 4 my ( $q, @files );
211 4 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 5 4 9
212 5 my $x = shift @a;
213 5 ▶ if ( $x eq '-q' ) { $q = shift @a }
Branch: 2 branches
BranchTrueFalseTotal
if ($x eq '-q') { } 2 3 5
elsif ($x =~ /\A-/) { } 0 3 3
214 elsif ( $x =~ /\A-/ ) { }
215 3 else { push @files, $x }
216 }
217 4 ▶ if ( $prog eq 'newaliases' ) { @files = ('/etc/aliases'); $prog = 'postalias' }
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "newaliases") 1 3 4
218 4 ▶ return ( "$prog: fatal: usage: $prog [-Nfinoprsuvw] [-c config_dir] [-d key] [-q key] [map_type:]file...", 0 ) unless @files;
Branch: 1 branch
BranchTrueFalseTotal
unless @files 0 4 4
219 4 ▶ if ( defined $q ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $q) 2 2 4
220 2 my ( $type, $f ) = _map_arg( $files[0] );
221 2 my $db = _lx()->can('_file_entry')->( $dev, "$f.db" );
222 2 ▶ return ( "$prog: fatal: open database $f.db: No such file or directory", 0 ) unless $db;
Branch: 1 branch
BranchTrueFalseTotal
unless $db 1 1 2
223 # eine mit postalias gebaute Tabelle (Aliase) hat Schlüssel ohne Doppelpunkt — gleich, wer nachschlägt
224 1 ▶ my $alias = $prog eq 'postalias' || $f =~ m{(?:\A|/)aliases\z};
Condition33%1/3
$prog eq 'postalias' || $f =~ m[(?:\A|/)aliases\z]
l!l&&r!l&&!r
001
MC/DC0%0/2
$prog eq 'postalias' || $f =~ m[(?:\A|/)aliases\z]
$prog eq 'postalias' $f =~ m[(?:\A|/)aliases\z]
Truth table33%1/3
A || B
A= $prog eq 'postalias'B= $f =~ m[(?:\A|/)aliases\z]
ABresult
1X1
011
000
225 1 ▶ for my $l ( split /\n/, $db->{content} // '' ) {
Condition50%1/2
$$db{"content"} // ""
l!l
10
MC/DC0%0/1
$$db{"content"} // ""
$$db{"content"}
Truth table50%1/2
A
A= $$db{"content"}
Aresult
11
00
226 1 ▶ next if $l =~ /\A\s*(?:#|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\A\s*(?:#|\z)/ 0 1 1
227 1 ▶ my ( $k, $v ) = $alias ? $l =~ /\A(\S+?):\s*(.*?)\s*\z/ : $l =~ /\A(\S+)\s+(.*?)\s*\z/;
Branch: 1 branch
BranchTrueFalseTotal
$alias ? : 0 1 1
228 1 ▶ return ( $v, 1 ) if defined $k && lc $k eq lc $q;
Branch: 1 branch
BranchTrueFalseTotal
if defined $k and lc $k eq lc $q 1 0 1
Condition33%1/3
defined $k and lc $k eq lc $q
!ll&&!rl&&r
001
MC/DC0%0/2
defined $k and lc $k eq lc $q
defined $k lc $k eq lc $q
Truth table33%1/3
A and B
A= defined $kB= lc $k eq lc $q
ABresult
0X0
100
111
229 }
230 0 return ( '', 0 );
231 }
232 2 my @out;
233 2 for my $fa (@files) {
234 2 my ( $type, $f ) = _map_arg($fa);
235 2 my ( $o, $ok ) = _build_db( $dev, $f, $prog );
236 2 ▶ push @out, $o if length $o;
Branch: 1 branch
BranchTrueFalseTotal
if length $o 0 2 2
237 2 ▶ return ( join( "\n", @out ), 0 ) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 2 2
238 }
239 2 return ( join( "\n", @out ), 1 );
240 }
241  
242 2 ▶sub _queue_text {
Subroutine _queue_text: called CC=18 SCAR=33.5
243 2 my ($dev) = @_;
244 2 ▶ my @q = @{ $dev->{postfix}{queue} || [] };
Condition50%1/2
$$dev{'postfix'}{'queue'} || []
l!l
20
MC/DC0%0/1
$$dev{'postfix'}{'queue'} || []
$$dev{'postfix'}{'queue'}
Truth table50%1/2
A
A= $$dev{'postfix'}{'queue'}
Aresult
11
00
245 2 ▶ return 'Mail queue is empty' unless @q;
Branch: 1 branch
BranchTrueFalseTotal
unless @q 1 1 2
246 1 my @l = ('-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------');
247 1 my $sum = 0;
248 1 for my $m (@q) {
249 1 ▶ my $mark = ( $m->{queue} // '' ) eq 'hold' ? '!' : ( $m->{queue} // '' ) eq 'active' ? '*' : '';
Branch: 2 branches
BranchTrueFalseTotal
($$m{'queue'} // '') eq 'hold' ? : 0 1 1
($$m{'queue'} // '') eq 'active' ? : 0 1 1
Condition50%2/4
$$m{"queue"} // ""
l!l
01
$$m{"queue"} // ""
l!l
01
MC/DC0%0/1
$$m{"queue"} // ""
$$m{"queue"}
MC/DC0%0/1
$$m{"queue"} // ""
$$m{"queue"}
Truth table50%1/2
A
A= $$m{"queue"}
Aresult
11
00
Truth table50%1/2
A
A= $$m{"queue"}
Aresult
11
00
250 1 ▶ push @l, sprintf( '%-11s %8d %s %s', $m->{id} . $mark, $m->{size} // 1024, $m->{time} // 'Tue Oct 20 08:00:00', length( $m->{from} // '' ) ? $m->{from} : 'MAILER-DAEMON' );
Branch: 1 branch
BranchTrueFalseTotal
length($$m{'from'} // '') ? : 1 0 1
Condition50%3/6
$$m{"size"} // 1024
l!l
10
$$m{"time"} // "Tue Oct 20 08:00:00"
l!l
01
$$m{"from"} // ""
l!l
10
MC/DC0%0/1
$$m{"size"} // 1024
$$m{"size"}
MC/DC0%0/1
$$m{"time"} // "Tue Oct 20 08:00:00"
$$m{"time"}
MC/DC0%0/1
$$m{"from"} // ""
$$m{"from"}
Truth table50%1/2
A
A= $$m{"size"}
Aresult
11
00
Truth table50%1/2
A
A= $$m{"time"}
Aresult
11
00
Truth table50%1/2
A
A= $$m{"from"}
Aresult
11
00
251 1 ▶ push @l, " ($m->{reason})" if defined $m->{reason} && ( $m->{queue} // 'deferred' ) eq 'deferred';
Branch: 1 branch
BranchTrueFalseTotal
if defined $$m{"reason"} and ($$m{"queue"} // "deferred") eq "deferred" 1 0 1
Condition40%2/5
defined $$m{"reason"} and ($$m{"queue"} // "deferred") eq "deferred"
!ll&&!rl&&r
001
$$m{"queue"} // "deferred"
l!l
01
MC/DC0%0/2
defined $$m{"reason"} and ($$m{"queue"} // "deferred") eq "deferred"
defined $$m{"reason"} $$m{"queue"}
Truth table33%1/3
A and B
A= defined $$m{"reason"}B= $$m{"queue"}
ABresult
0X0
100
111
252 1 ▶ push @l, map {" $_"} @{ $m->{to} || [] };
Condition50%1/2
$$m{'to'} || []
l!l
10
MC/DC0%0/1
$$m{'to'} || []
$$m{'to'}
Truth table50%1/2
A
A= $$m{'to'}
Aresult
11
00
253 1 push @l, '';
254 1 ▶ $sum += $m->{size} // 1024;
Condition50%1/2
$$m{"size"} // 1024
l!l
10
MC/DC0%0/1
$$m{"size"} // 1024
$$m{"size"}
Truth table50%1/2
A
A= $$m{"size"}
Aresult
11
00
255 }
256 1 ▶ push @l, sprintf( '-- %d Kbytes in %d Request%s.', int( $sum / 1024 + 0.999 ), scalar @q, @q == 1 ? '' : 's' );
Branch: 1 branch
BranchTrueFalseTotal
@q == 1 ? : 1 0 1
257 1 return join "\n", @l;
258 }
259  
260  
261 5 ▶sub postqueue {
Subroutine postqueue: called CC=8 SCAR=27.2
Pod documented
262 5 my ( $dev, $av ) = @_;
263 5 my @a = @$av;
264 5 ▶ return ( "postqueue: fatal: Queue report unavailable - mail system is down", 0 ) unless _running($dev);
Branch: 1 branch
BranchTrueFalseTotal
unless _running($dev) 0 5 5
265 5 ▶ my $o = shift(@a) // '';
Condition50%1/2
shift @a // ""
l!l
50
MC/DC0%0/1
shift @a // ""
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
266 5 ▶ return ( _queue_text($dev), 1 ) if $o eq '-p' || $o eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "-p" or $o eq "" 2 3 5
Condition66%2/3
$o eq "-p" or $o eq ""
l!l&&r!l&&!r
203
MC/DC50%1/2
$o eq "-p" or $o eq ""
$o eq "-p" $o eq ""
Truth table66%2/3
A or B
A= $o eq "-p"B= $o eq ""
ABresult
1X1
011
000
267 3 ▶ if ( $o eq '-f' ) { _flush($dev); return ( '', 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "-f") 3 0 3
268 0 ▶ if ( $o eq '-i' ) { _flush( $dev, shift @a ); return ( '', 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "-i") 0 0 0
269 0 ▶ if ( $o eq '-j' ) { return ( '', 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "-j") 0 0 0
270 0 return ( 'postqueue: fatal: usage: postqueue -f | postqueue -i queueid | postqueue -j | postqueue -p | postqueue -s site', 0 );
271 }
272  
273  
274 1 ▶sub postsuper {
Subroutine postsuper: called CC=24 SCAR=41.3
Pod documented
275 1 my ( $dev, $av, $ctx, $stdin ) = @_;
276 1 my @a = @$av;
277 1 my $pf = $dev->{postfix};
278 1 my ( %act, $n );
279 1 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 1 1 2
280 1 my $x = shift @a;
281 1 ▶ if ( $x =~ /\A-([dhHr])\z/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($x =~ /\A-([dhHr])\z/) { } 1 0 1
elsif ($x =~ /\A(?:deferred|hold|active|incoming|maildrop)\z/) { } 0 0 0
282 1 ▶ my $id = shift @a // return ( "postsuper: fatal: usage: postsuper [-c config_dir] [-d queue_id (delete)] [-h queue_id (hold)] [-H queue_id (un-hold)] [-p (purge temporary files)] [-r queue_id (requeue)] [-s (structure fix)] [-S (structure fix)] [-v (verbose)] [queue...]", 0 );
Condition50%1/2
shift @a // (return "postsuper: fatal: usage: postsuper [-c config_dir] [-d queue_id (delete)] [-h queue_id (hold)] [-H queue_id (un-hold)] [-p (purge temporary files)] [-r queue_id (requeue)] [-s (structure fix)] [-S (structure fix)] [-v (verbose)] [queue...]", 0)
l!l
10
MC/DC0%0/1
shift @a // (return "postsuper: fatal: usage: postsuper [-c config_dir] [-d queue_id (delete)] [-h queue_id (hold)] [-H queue_id (un-hold)] [-p (purge temporary files)] [-r queue_id (requeue)] [-s (structure fix)] [-S (structure fix)] [-v (verbose)] [queue...]", 0)
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
283 1 ▶ push @{ $act{$1} }, $id eq '-' ? ( split ' ', $stdin // '' ) : $id;
Branch: 1 branch
BranchTrueFalseTotal
$id eq '-' ? : 0 1 1
Condition0%0/2
$stdin // ""
l!l
00
MC/DC0%0/1
$stdin // ""
$stdin
Truth table0%0/2
A
A= $stdin
Aresult
11
00
284 }
285 0 elsif ( $x =~ /\A(?:deferred|hold|active|incoming|maildrop)\z/ ) { $act{queue} = $x }
286 }
287 1 my @l;
288 1 for my $op (qw( d h H r )) {
289 4 ▶ my @ids = @{ $act{$op} || [] } or next;
Branch: 1 branch
BranchTrueFalseTotal
my(@ids) = @{$act{$op} or [];} or next 1 3 4
Condition100%2/2
$act{$op} || []
l!l
13
MC/DC100%1/1
$act{$op} || []
$act{$op}
Truth table100%2/2
A
A= $act{$op}
Aresult
11
00
290 1 my $all = grep { $_ eq 'ALL' } @ids;
291 1 my %want = map { $_ => 1 } @ids;
292 1 my $c = 0;
293 1 my @keep;
294 1 ▶ for my $m ( @{ $pf->{queue} || [] } ) {
Condition50%1/2
$$pf{'queue'} || []
l!l
10
MC/DC0%0/1
$$pf{'queue'} || []
$$pf{'queue'}
Truth table50%1/2
A
A= $$pf{'queue'}
Aresult
11
00
295 1 ▶ my $hit = ( $all || $want{ $m->{id} } ) && ( !$act{queue} || ( $m->{queue} // 'deferred' ) eq $act{queue} );
Condition27%3/11
($all || $want{$$m{'id'}}) && (!$act{'queue'} || ($$m{'queue'} // 'deferred') eq $act{'queue'})
!ll&&!rl&&r
001
$all or $want{$$m{"id"}}
l!l&&r!l&&!r
010
not $act{"queue"} or ($$m{"queue"} // "deferred") eq $act{"queue"}
l!l&&r!l&&!r
100
$$m{"queue"} // "deferred"
l!l
00
MC/DC0%0/4
($all || $want{$$m{'id'}}) && (!$act{'queue'} || ($$m{'queue'} // 'deferred') eq $act{'queue'})
$all $want{$$m{"id"}} not $act{"queue"} $$m{"queue"}
Truth table14%1/7
A or B && not(C) or D
A= $allB= $want{$$m{"id"}}C= not $act{"queue"}D= $$m{"queue"}
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
296 0 ▶ if ( !$hit ) { push @keep, $m; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($hit) 0 1 1
297 1 $c++;
298 1 ▶ if ( $op eq 'd' ) { push @{ $pf->{deleted} }, $m->{id}; next }
Branch: 3 branches
BranchTrueFalseTotal
if ($op eq 'd') { } 1 0 1
elsif ($op eq 'h') { } 0 0 0
elsif ($op eq 'H') { } 0 0 0
299 0 elsif ( $op eq 'h' ) { $m->{queue} = 'hold' }
300 0 ▶ elsif ( $op eq 'H' ) { $m->{queue} = 'deferred' if ( $m->{queue} // '' ) eq 'hold' }
Branch: 1 branch
BranchTrueFalseTotal
if ($$m{"queue"} // "") eq "hold" 0 0 0
Condition0%0/2
$$m{"queue"} // ""
l!l
00
MC/DC0%0/1
$$m{"queue"} // ""
$$m{"queue"}
Truth table0%0/2
A
A= $$m{"queue"}
Aresult
11
00
301 0 push @keep, $m;
302 }
303 1 $pf->{queue} = \@keep;
304 1 my %verb = ( d => 'Deleted', h => 'Placed on hold', H => 'Released from hold', r => 'Requeued' );
305 1 ▶ push @l, "postsuper: $verb{$op}: $c message" . ( $c == 1 ? '' : 's' ) if $c;
Branch: 2 branches
BranchTrueFalseTotal
if $c 1 0 1
$c == 1 ? : 1 0 1
306 }
307 1 return ( join( "\n", @l ), 1 );
308 }
309  
310  
311 0 ▶sub postcat {
Subroutine postcat: not called CC=6 SCAR=37.4
Pod documented
312 0 my ( $dev, $av ) = @_;
313 0 my ($id) = grep { !/\A-/ } @$av;
314 0 ▶ my ($m) = grep { $_->{id} eq ( $id // '' ) } @{ $dev->{postfix}{queue} || [] };
Condition0%0/4
$id // ""
l!l
00
$$dev{'postfix'}{'queue'} || []
l!l
00
MC/DC0%0/1
$id // ""
$id
MC/DC0%0/1
$$dev{'postfix'}{'queue'} || []
$$dev{'postfix'}{'queue'}
Truth table0%0/2
A
A= $id
Aresult
11
00
Truth table0%0/2
A
A= $$dev{'postfix'}{'queue'}
Aresult
11
00
315 0 ▶ return ( "postcat: fatal: open queue file $id: No such file or directory", 0 ) unless $m;
Branch: 1 branch
BranchTrueFalseTotal
unless $m 0 0 0
316 return ( join( "\n", '*** ENVELOPE RECORDS deferred/' . $m->{id} . ' ***', "message_size: $m->{size}", "sender: $m->{from}",
317 0 ▶ ( map {"recipient: $_"} @{ $m->{to} || [] } ), '*** MESSAGE CONTENTS deferred/' . $m->{id} . ' ***', ( $m->{headers} // '' ) =~ s/\n\z//r,
Condition0%0/4
$$m{'to'} || []
l!l
00
$$m{"headers"} // ""
l!l
00
MC/DC0%0/1
$$m{'to'} || []
$$m{'to'}
MC/DC0%0/1
$$m{"headers"} // ""
$$m{"headers"}
Truth table0%0/2
A
A= $$m{'to'}
Aresult
11
00
Truth table0%0/2
A
A= $$m{"headers"}
Aresult
11
00
318 0 '*** HEADER EXTRACTED deferred/' . $m->{id} . ' ***', '*** MESSAGE FILE END deferred/' . $m->{id} . ' ***' ), 1 );
319 }
320  
321 2 1;
322  
323 __END__
« blib/lib/Langertha/Holmgang/World.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Helm.pm »