Sisimai/Rhost.pm

filter: Statementstmt 100% 41 / 41 Branchbran 87.5% 7 / 8 Conditioncond 83.3% 10 / 12 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 90.5% 67 / 74 CC 14 SCAR 21.6
CC
14
Cov
95%
name
12.1
find
3.0
BEGIN
1.0
CRAP 8.7
« Sisimai/Mail/Maildir.pm ↑ Summary Sisimai.pm »
1 package Sisimai::Rhost;
2 86 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 86 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 86 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 86 state $RhostClass = {
7 "Aol" => [".mail.aol.com", ".mx.aol.com"],
8 "Apple" => [".mail.icloud.com", ".apple.com", ".me.com", "privaterelay.appleid.com"],
9 "Cloudflare" => [".mx.cloudflare.net"],
10 "Cox" => ["cox.net"],
11 "Facebook" => [".facebook.com"],
12 "FrancePTT" => [".laposte.net", ".orange.fr", ".wanadoo.fr"],
13 "GoDaddy" => ["smtp.secureserver.net", "mailstore1.secureserver.net"],
14 "Google" => ["aspmx.l.google.com", "gmail-smtp-in.l.google.com"],
15 "GSuite" => ["googlemail.com"],
16 "IUA" => [".email.ua"],
17 "KDDI" => [".ezweb.ne.jp", "msmx.au.com"],
18 "MessageLabs" => [".messagelabs.com"],
19 "Microsoft" => [".prod.outlook.com", ".protection.outlook.com", ".onmicrosoft.com", ".exchangelabs.com",],
20 "Mimecast" => [".mimecast.com"],
21 "NTTDOCOMO" => ["mfsmax.docomo.ne.jp"],
22 "Outlook" => [".hotmail.com"],
23 "Spectrum" => ["charter.net"],
24 "Tencent" => [".qq.com"],
25 "YahooInc" => [".yahoodns.net"],
26 "Zoho" => [".zoho.com", ".zoho.eu", ".zoho.jp", ".zoho.com.au", ".zoho.com.cn", ".zoho.in"],
27 };
28  
29 3425 ▶sub name {
Subroutine name: called CC=12 SCAR=24.9
Pod undocumented
30 # Detect the rhost class name
31 # @param [Sisimai::Fact] argvs Decoded email object
32 # @return [String] rhost class name
33 3425 my $class = shift;
34 3425 ▶ my $argvs = shift || return "";
Condition50%1/2
shift() || (return '')
l!l
34250
MC/DC0%0/1
shift() || (return '')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
35  
36 3425 my $rhostclass = "";
37 3425 ▶ my $clienthost = lc $argvs->{"lhost"} || "";
Condition100%2/2
lc $argvs->{'lhost'} || ''
l!l
3068357
MC/DC100%1/1
lc $argvs->{'lhost'} || ''
lc $argvs->{'lhost'}
Truth table100%2/2
A
A= lc $argvs->{'lhost'}
Aresult
11
00
38 3425 ▶ my $remotehost = lc $argvs->{"rhost"} || "";
Condition100%2/2
lc $argvs->{'rhost'} || ''
l!l
3313112
MC/DC100%1/1
lc $argvs->{'rhost'} || ''
lc $argvs->{'rhost'}
Truth table100%2/2
A
A= lc $argvs->{'rhost'}
Aresult
11
00
39 3425 ▶ my $domainpart = lc $argvs->{"destination"} || "";
Condition50%1/2
lc $argvs->{'destination'} || ''
l!l
34250
MC/DC0%0/1
lc $argvs->{'destination'} || ''
lc $argvs->{'destination'}
Truth table50%1/2
A
A= lc $argvs->{'destination'}
Aresult
11
00
40  
41 3425 ▶ FINDRHOST: while( $rhostclass eq "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhostclass eq "") 3425 0 3425
42 # Try to match the hostname patterns with the following order:
43 # 1. destination: The domain part of the recipient address
44 # 2. rhost: remote hostname
45 # 3. lhost: local MTA hostname
46 3425 for my $e ( keys %$RhostClass ) {
47 # Try to match the domain part with each value of RhostClass
48 65772 ▶ next unless grep { index($_, $domainpart) > -1 } $RhostClass->{ $e }->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($_, $domainpart) != -1;} @{$$RhostClass{$e}} 65434 338 65772
49 338 $rhostclass = $e; last FINDRHOST;
50 }
51  
52 3087 for my $e ( keys %$RhostClass ) {
53 # Try to match the remote host with each value of RhostClass
54 56440 ▶ next unless grep { index($remotehost, $_) > -1 } $RhostClass->{ $e }->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($remotehost, $_) != -1;} @{$$RhostClass{$e}} 55843 597 56440
55 597 $rhostclass = $e; last FINDRHOST;
56 }
57  
58 # Neither the remote host nor the destination did not matched with any value of RhostClass
59 2490 for my $e ( keys %$RhostClass ) {
60 # Try to match the client host with each value of RhostClass
61 46378 ▶ next unless grep { index($clienthost, $_) > -1 } $RhostClass->{ $e }->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($clienthost, $_) != -1;} @{$$RhostClass{$e}} 46129 249 46378
62 249 $rhostclass = $e; last FINDRHOST;
63 }
64 2241 last;
65 }
66 3425 return $rhostclass;
67 }
68  
69 3336 ▶sub find {
Subroutine find: called CC=3 SCAR=11.0
Pod undocumented
70 # Detect the bounce reason from certain remote hosts
71 # @param [Sisimai::Fact] argvs Decoded email object
72 # @return [String] The value of bounce reason
73 3336 my $class = shift;
74 3336 ▶ my $argvs = shift || return "";
Condition100%2/2
shift() || (return '')
l!l
33351
MC/DC100%1/1
shift() || (return '')
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
75 3335 ▶ my $rhost = __PACKAGE__->name($argvs) || return "";
Condition100%2/2
__PACKAGE__->name($argvs) || (return '')
l!l
10942241
MC/DC100%1/1
__PACKAGE__->name($argvs) || (return '')
__PACKAGE__->name($argvs)
Truth table100%2/2
A
A= __PACKAGE__->name($argvs)
Aresult
11
00
76  
77 1094 $rhost = __PACKAGE__."::".$rhost; (my $modulepath = $rhost) =~ s|::|/|g;
78 1094 require $modulepath.'.pm';
79 1094 return $rhost->find($argvs);
80 }
81  
82 86 1;
83 __END__
« Sisimai/Mail/Maildir.pm ↑ Summary Sisimai.pm »