Sisimai/SMTP/Command.pm

filter: Statementstmt 100% 53 / 53 Branchbran 91.6% 22 / 24 Conditioncond 61.2% 19 / 31 MC/DCmcdc 21.4% 3 / 14 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 81.0% 107 / 132 CC 25 SCAR 28.8
CC
25
Cov
87%
find
25.0
test
4.0
BEGIN
1.0
CRAP 17.9
« Sisimai/RFC1123.pm ↑ Summary Sisimai/Lhost/DeutscheTelekom.pm »
1 package Sisimai::SMTP::Command;
2 92 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 92 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 92 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 92 ▶use Sisimai::Eb;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 92 ▶use constant ExceptDATA => [$Sisimai::Eb::CeCONN, $Sisimai::Eb::CeEHLO, $Sisimai::Eb::CeHELO,
Subroutine BEGIN: called CC=1 SCAR=0.0
7 92 $Sisimai::Eb::CeMAIL, $Sisimai::Eb::CeRCPT];
8 92 ▶use constant BeforeRCPT => [$Sisimai::Eb::CeCONN, $Sisimai::Eb::CeEHLO, $Sisimai::Eb::CeHELO,
Subroutine BEGIN: called CC=1 SCAR=0.0
9 92 $Sisimai::Eb::CeMAIL, $Sisimai::Eb::CeAUTH, $Sisimai::Eb::CeTTLS];
10 92 state $Availables = [
11 $Sisimai::Eb::CeHELO, $Sisimai::Eb::CeEHLO, $Sisimai::Eb::CeMAIL, $Sisimai::Eb::CeRCPT,
12 $Sisimai::Eb::CeDATA, $Sisimai::Eb::CeQUIT, $Sisimai::Eb::CeRSET, $Sisimai::Eb::CeNOOP,
13 $Sisimai::Eb::CeVRFY, $Sisimai::Eb::CeETRN, $Sisimai::Eb::CeEXPN, $Sisimai::Eb::CeHELP,
14 $Sisimai::Eb::CeAUTH, $Sisimai::Eb::CeTTLS, $Sisimai::Eb::CeXFWD,
15 $Sisimai::Eb::CeCONN, # CONN is a pseudo SMTP command used only in Sisimai
16 ];
17 92 state $Detectable = [
18 $Sisimai::Eb::CeHELO, $Sisimai::Eb::CeEHLO, $Sisimai::Eb::CeTTLS, "AUTH PLAIN", "AUTH LOGIN",
19 "AUTH CRAM-", "AUTH DIGEST-", "MAIL F", $Sisimai::Eb::CeRCPT, "RCPT T", $Sisimai::Eb::CeDATA,
20 $Sisimai::Eb::CeQUIT, $Sisimai::Eb::CeXFWD,
21 ];
22  
23 7162 ▶sub test {
Subroutine test: called CC=4 SCAR=13.9
Pod documented
24 # Check that an SMTP command in the argument is valid or not
25 # @param [String] argv0 An SMTP command
26 # @return [Boolean] 0: Is not a valid SMTP command, 1: Is a valid SMTP command
27 # @since v5.0.0
28 7162 my $class = shift;
29 7162 ▶ my $argv0 = shift // return 0; return 0 unless length $argv0 > 3;
Branch: 1 branch
BranchTrueFalseTotal
unless length $argv0 > 3 1963 5198 7161
Condition100%2/2
shift() // (return 0)
l!l
71611
MC/DC100%1/1
shift() // (return 0)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
30 5198 ▶ return 1 if grep { index($argv0, $_) > -1 } @$Availables;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($argv0, $_) != -1;} @$Availables 3221 1977 5198
31 1977 return 0;
32 }
33  
34 3507 ▶sub find {
Subroutine find: called CC=22 SCAR=32.2
Pod documented
35 # Pick an SMTP command from the given string
36 # @param [String] argv0 A transcript text MTA returned
37 # @return [String] An SMTP command
38 # @since v5.0.0
39 3507 my $class = shift;
40 3507 ▶ my $argv0 = shift // return ""; return "" unless __PACKAGE__->test($argv0);
Branch: 1 branch
BranchTrueFalseTotal
unless __PACKAGE__->test($argv0) 1987 1519 3506
Condition100%2/2
shift() // (return "")
l!l
35061
MC/DC100%1/1
shift() // (return "")
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
41  
42 1519 my $issuedcode = ' '.lc($argv0).' ';
43 1519 my $commandmap = {'STAR' => $Sisimai::Eb::CeTTLS, 'XFOR' => $Sisimai::Eb::CeXFWD};
44 1519 my $commandset = [];
45  
46 1519 for my $e ( @$Detectable ) {
47 # Find an SMTP command from the given string
48 19747 ▶ my $p0 = index($argv0, $e); next if $p0 < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $p0 < 0 17660 2087 19747
49 2087 ▶ if( index($e, " ") < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e, " ") == -1) 1283 804 2087
50 # For example, "RCPT T" does not appear in an email address or a domain name
51 1283 my $cx = 1; while(1) {
52 # Exclude an SMTP command in the part of an email address, a domain name, such as
53 # DATABASE@EXAMPLE.JP, EMAIL.EXAMPLE.COM, and so on.
54 1283 my $ca = ord(substr($issuedcode, $p0, 1));
55 1283 my $cz = ord(substr($issuedcode, $p0 + length($e) + 1, 1));
56  
57 1283 ▶ last if $ca > 47 && $ca < 58 || $cz > 47 && $cz < 58; # 0-9
Branch: 1 branch
BranchTrueFalseTotal
if $ca > 47 and $ca < 58 or $cz > 47 and $cz < 58 0 1283 1283
Condition55%5/9
$ca > 47 and $ca < 58 or $cz > 47 and $cz < 58
l!l&&r!l&&!r
001283
$ca > 47 and $ca < 58
!ll&&!rl&&r
1240430
$cz > 47 and $cz < 58
!ll&&!rl&&r
1189940
MC/DC0%0/4
$ca > 47 and $ca < 58 or $cz > 47 and $cz < 58
$ca > 47 $ca < 58 $cz > 47 $cz < 58
Truth table57%4/7
A and B or C and D
A= $ca > 47B= $ca < 58C= $cz > 47D= $cz < 58
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
58 1283 ▶ last if $ca > 63 && $ca < 91 || $cz > 63 && $cz < 91; # @-Z
Branch: 1 branch
BranchTrueFalseTotal
if $ca > 63 and $ca < 91 or $cz > 63 and $cz < 91 1 1282 1283
Condition77%7/9
$ca > 63 and $ca < 91 or $cz > 63 and $cz < 91
l!l&&r!l&&!r
011282
$ca > 63 and $ca < 91
!ll&&!rl&&r
1252310
$cz > 63 and $cz < 91
!ll&&!rl&&r
1251311
MC/DC25%1/4
$ca > 63 and $ca < 91 or $cz > 63 and $cz < 91
$ca > 63 $ca < 91 $cz > 63 $cz < 91
Truth table42%3/7
A and B or C and D
A= $ca > 63B= $ca < 91C= $cz > 63D= $cz < 91
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
59 1282 ▶ last if $ca > 96 && $ca < 123 || $cz > 96 && $cz < 123; # `-z
Branch: 1 branch
BranchTrueFalseTotal
if $ca > 96 and $ca < 123 or $cz > 96 and $cz < 123 0 1282 1282
Condition33%3/9
$ca > 96 and $ca < 123 or $cz > 96 and $cz < 123
l!l&&r!l&&!r
001282
$ca > 96 and $ca < 123
!ll&&!rl&&r
128200
$cz > 96 and $cz < 123
!ll&&!rl&&r
128200
MC/DC0%0/4
$ca > 96 and $ca < 123 or $cz > 96 and $cz < 123
$ca > 96 $ca < 123 $cz > 96 $cz < 123
Truth table14%1/7
A and B or C and D
A= $ca > 96B= $ca < 123C= $cz > 96D= $cz < 123
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
60 1282 $cx = 0; last;
61 }
62 1283 ▶ next if $cx == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $cx == 1 1 1282 1283
63 }
64  
65 # There is the same command in the "commanset" or nor
66 2086 ▶ my $cv = substr($e, 0, 4); next if grep { index($cv, $_) == 0 } @$commandset;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($cv, $_) == 0;} @$commandset 556 1530 2086
67 1530 ▶ $cv = $commandmap->{ $cv } if exists $commandmap->{ $cv };
Branch: 1 branch
BranchTrueFalseTotal
if exists $commandmap->{$cv} 12 1518 1530
68 1530 push @$commandset, $cv;
69 }
70 1519 ▶ return "" unless scalar @$commandset;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$commandset 5 1514 1519
71 1514 return pop @$commandset;
72 }
73  
74 92 1;
75 __END__
« Sisimai/RFC1123.pm ↑ Summary Sisimai/Lhost/DeutscheTelekom.pm »