blib/lib/Mail/Exim/MainLogParser.pm

filter: Statementstmt 38.9% 23 / 59 Branchbran 0.0% 0 / 22 Conditioncond 3.4% 1 / 29 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 70.0% 7 / 10 Podpod 100% 3 / 3 totaltotal 24.4% 34 / 139 CC 22 SCAR 57.5
CC
22
Cov
22%
_exim_log_main__parse
462.0
new
2.1
EximMainLoglineParse
2.0
CRAP 313.4
↑ Summary
1 package Mail::Exim::MainLogParser;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 BEGIN {
5 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ $VERSION = '0.01';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 @ISA = qw(Exporter);
9 1 @EXPORT = qw();
10 1 @EXPORT_OK = qw(&EximMainLoglineParse);
11 1 %EXPORT_TAGS = ();
12 }
13  
14 BEGIN {
15 1 ▶ use vars qw(%EXIM_FLAGS %EXIM_FIELD_IDENFIERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # As of 2017-06-08
18 # Source: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-log_files.html
19 1 ▶ %EXIM_FLAGS = (
Subroutine BEGIN: called CC=1 SCAR=0.0
20 '<=' => 'message arrival',
21 '(=' => 'message fakereject',
22 '=>' => 'normal message delivery',
23 '->' => 'additional address in same delivery',
24 '>>' => 'cutthrough message delivery',
25 '*>' => 'delivery suppressed by -N',
26 '**' => 'delivery failed; address bounced',
27 '==' => 'delivery deferred; temporary problem',
28 );
29 1 %EXIM_FIELD_IDENFIERS = (
30 A => 'authenticator name (and optional id and sender)',
31 C => ('SMTP confirmation on delivery'. '; '.
32 'command list for "no mail in SMTP session”'),
33 CV => 'certificate verification status',
34 D => 'duration of "no mail in SMTP session”',
35 DN => 'distinguished name from peer certificate',
36 DS => 'DNSSEC secured lookups',
37 DT => 'on => lines: time taken for a delivery',
38 F => 'sender address (on delivery lines)',
39 H => 'host name and IP address',
40 I => 'local interface used',
41 K => 'CHUNKING extension used',
42 id => 'message id for incoming message',
43 P => ('on <= lines: protocol used'. '; '.
44 'on => and ** lines: return path'),
45 PRDR => 'PRDR extension used',
46 PRX => 'on <= and => lines: proxy address',
47 Q => 'alternate queue name',
48 QT => ('on => lines: time spent on queue so far'. '; '.
49 'on "Completed” lines: time spent on queue'),
50 R => ('on <= lines: reference for local bounce'. '; '.
51 'on => >> ** and == lines: router name'),
52 S => 'size of message in bytes',
53 SNI => 'server name indication from TLS client hello',
54 ST => 'shadow transport name',
55 T => ('on <= lines: message subject (topic)'. '; '.
56 'on => ** and == lines: transport name'),
57 U => 'local user or RFC 1413 identity',
58 X => 'TLS cipher suite'
59 );
60 }
61  
62  
63 sub new
64 {
65 1 ▶ my ($class, %parameters) = @_;
Subroutine new: called CC=2 SCAR=7.6
Pod documented
66  
67 1 ▶ my $self = bless ({}, ref ($class) || $class);
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
68  
69 1 return $self;
70 }
71  
72 sub _exim_log_main__parse($) {
73 0 ▶ my $line = shift || return undef;
Subroutine _exim_log_main__parse: not called CC=21 SCAR=61.4
Condition0%0/2
shift() || (return undef)
l!l
00
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
74 0 my @line = split(/\s/,$line);
75 0 ▶ return undef unless scalar @line >= 3;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @line >= 3 0 0 0
76 0 my $l = {
77 date => shift @line,
78 time => shift @line
79 };
80  
81 # Exim ID: 1dIyz2-0002mc-5x
82 0 ▶ if ($line[0] =~ /......\-......\-../) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line[0] =~ /......\-......\-../) { } 0 0 0
83 0 $l->{eximid} = shift @line;
84 } else {
85 0 $l->{eximid} = undef;
86 }
87  
88 # Exim log line flag
89 0 ▶ if ($line[0] =~ /\<\=|\(\=|\=\>|\-\>|\>\>|\*\>|\*\*|\=\=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line[0] =~ /\<\=|\(\=|\=\>|\-\>|\>\>|\*\>|\*\*|\=\=/) { } 0 0 0
90 0 $l->{flag} = shift @line;
91 } else {
92 # mail rejected or completed!
93 0 $l->{flag} = undef;
94 }
95  
96 # Exim Mail Address
97 0 ▶ if (($line[0] !~ /^[A-Zid]{1,4}\=.+/) && ($line[0] =~ /.+\@.+/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $line[0] =~ /^[A-Zid]{1,4}\=.+/ and $line[0] =~ /.+\@.+/) 0 0 0
Condition0%0/3
not $line[0] =~ /^[A-Zid]{1,4}\=.+/ and $line[0] =~ /.+\@.+/
!ll&&!rl&&r
000
MC/DC0%0/2
not $line[0] =~ /^[A-Zid]{1,4}\=.+/ and $line[0] =~ /.+\@.+/
not $line[0] =~ /^[A-Zid]{1,4}\=.+/ $line[0] =~ /.+\@.+/
Truth table0%0/3
not(A) and B
A= not $line[0] =~ /^[A-Zid]{1,4}\=.+/B= $line[0] =~ /.+\@.+/
ABresult
0X0
100
111
98 0 $l->{address} = shift @line;
99 0 ▶ while ((defined $line[0]) && ($line[0] !~ /^[A-Zid]{1,4}\=.+/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line[0] and not $line[0] =~ /^[A-Zid]{1,4}\=.+/) 0 0 0
Condition0%0/3
defined $line[0] and not $line[0] =~ /^[A-Zid]{1,4}\=.+/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $line[0] and not $line[0] =~ /^[A-Zid]{1,4}\=.+/
defined $line[0] not $line[0] =~ /^[A-Zid]{1,4}\=.+/
Truth table0%0/3
A and not(B)
A= defined $line[0]B= not $line[0] =~ /^[A-Zid]{1,4}\=.+/
ABresult
0X0
100
111
100 0 ▶ if ( ((!defined $l->{flag}) || ((defined $l->{flag}) && ($l->{flag} eq '**'))) && ($l->{address} =~ /\:$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($l->{"flag"}) || defined $l->{"flag"} && $l->{"flag"} eq "**" and $l->{"address"} =~ /\:$/) 0 0 0
Condition0%0/9
!defined($l->{"flag"}) || defined $l->{"flag"} && $l->{"flag"} eq "**" and $l->{"address"} =~ /\:$/
!ll&&!rl&&r
000
not defined $l->{"flag"} or defined $l->{"flag"} and $l->{"flag"} eq "**"
l!l&&r!l&&!r
000
defined $l->{"flag"} and $l->{"flag"} eq "**"
!ll&&!rl&&r
000
MC/DC0%0/4
!defined($l->{"flag"}) || defined $l->{"flag"} && $l->{"flag"} eq "**" and $l->{"address"} =~ /\:$/
not defined $l->{"flag"} defined $l->{"flag"} $l->{"flag"} eq "**" $l->{"address"} =~ /\:$/
Truth table0%0/6
not(A) or B and C and D
A= not defined $l->{"flag"}B= defined $l->{"flag"}C= $l->{"flag"} eq "**"D= $l->{"address"} =~ /\:$/
ABCDresult
00XX0
010X0
1XX00
01100
1XX11
01111
101 0 chop $l->{address};
102 0 last;
103 }
104 0 $l->{address} .= (" " . shift @line);
105 }
106 }
107  
108 # Exim field identifiers and messages
109 0 $l->{args} = [];
110 0 ▶ while (scalar @line >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @line >= 1) 0 0 0
111 0 ▶ if ($line[0] =~ /^([A-Zid]{1,4})\=(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line[0] =~ /^([A-Zid]{1,4})\=(.+)/) { } 0 0 0
112 0 my $this_arg = $1;
113 0 my $this_val = $2;
114 0 shift @line;
115 0 ▶ while ( (scalar @line >= 1) && (($line[0] =~ /^\[.+\]/) || ($line[0] =~ /^\(.+\)/)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @line >= 1 and $line[0] =~ /^\[.+\]/ || $line[0] =~ /^\(.+\)/) 0 0 0
Condition0%0/6
scalar @line >= 1 and $line[0] =~ /^\[.+\]/ || $line[0] =~ /^\(.+\)/
!ll&&!rl&&r
000
$line[0] =~ /^\[.+\]/ or $line[0] =~ /^\(.+\)/
l!l&&r!l&&!r
000
MC/DC0%0/3
scalar @line >= 1 and $line[0] =~ /^\[.+\]/ || $line[0] =~ /^\(.+\)/
scalar @line >= 1 $line[0] =~ /^\[.+\]/ $line[0] =~ /^\(.+\)/
Truth table0%0/4
A and B or C
A= scalar @line >= 1B= $line[0] =~ /^\[.+\]/C= $line[0] =~ /^\(.+\)/
ABCresult
0XX0
1000
11X1
1011
116 0 $this_val .= (" " . shift @line);
117 }
118 0 push(@{$l->{args}},{$this_arg => $this_val});
119 } else {
120 0 $l->{message} = shift @line;
121 0 ▶ while ((defined $line[0]) && ($line[0] !~ /^[A-Zid]{1,4}\=.+/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line[0] and not $line[0] =~ /^[A-Zid]{1,4}\=.+/) 0 0 0
Condition0%0/3
defined $line[0] and not $line[0] =~ /^[A-Zid]{1,4}\=.+/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $line[0] and not $line[0] =~ /^[A-Zid]{1,4}\=.+/
defined $line[0] not $line[0] =~ /^[A-Zid]{1,4}\=.+/
Truth table0%0/3
A and not(B)
A= defined $line[0]B= not $line[0] =~ /^[A-Zid]{1,4}\=.+/
ABresult
0X0
100
111
122 0 $l->{message} .= (" " . shift @line);
123 }
124 }
125 }
126  
127 0 ▶ if (scalar @line >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @line >= 1) 0 0 0
128 0 die ("Error Parsing Line: $line\n"."Unparsed log line data: ".join("; ",@line)."\n");
129 }
130  
131 0 return $l;
132 }
133  
134 sub EximMainLoglineParse($) {
135 0 ▶ return _exim_log_main__parse($_[0]);
Subroutine EximMainLoglineParse: not called CC=1 SCAR=6.9
Pod documented
136 }
137  
138 sub parse($) {
139 0 ▶ my $self = shift;
Subroutine parse: not called CC=1 SCAR=6.9
Pod documented
140 0 return _exim_log_main__parse($_[0]);
141 }
142  
143 1 1;
144 __END__
↑ Summary