File Coverage

lib/Sisimai/Rhost.pm
Criterion Covered Total %
statement 39 39 100.0
branch 6 6 100.0
condition 10 12 83.3
subroutine 5 5 100.0
pod 0 2 0.0
total 60 64 93.7


line stmt bran cond sub pod time code
1             package Sisimai::Rhost;
2 84     84   1384 use v5.26;
  84         289  
3 84     84   492 use strict;
  84         154  
  84         2047  
4 84     84   404 use warnings;
  84         154  
  84         54230  
5              
6             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"],
27             };
28              
29             sub name {
30             # Detect the rhost class name
31             # @param [Sisimai::Fact] argvs Decoded email object
32             # @return [String] rhost class name
33 3320     3320 0 147910 my $class = shift;
34 3320   50     8137 my $argvs = shift || return "";
35              
36 3320         6293 my $rhostclass = "";
37 3320   100     13471 my $clienthost = lc $argvs->{"lhost"} || "";
38 3320   100     12868 my $remotehost = lc $argvs->{"rhost"} || "";
39 3320   50     11134 my $domainpart = lc $argvs->{"destination"} || "";
40              
41 3320         9908 FINDRHOST: while( $rhostclass eq "" ) {
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 3320         26887 for my $e ( keys %$RhostClass ) {
47             # Try to match the domain part with each value of RhostClass
48 61723 100       94548 next unless grep { index($_, $domainpart) > -1 } $RhostClass->{ $e }->@*;
  102045         197102  
49 337         643 $rhostclass = $e; last FINDRHOST;
  337         791  
50             }
51              
52 2983         15746 for my $e ( keys %$RhostClass ) {
53             # Try to match the remote host with each value of RhostClass
54 54132 100       81607 next unless grep { index($remotehost, $_) > -1 } $RhostClass->{ $e }->@*;
  89532         169912  
55 597         1405 $rhostclass = $e; last FINDRHOST;
  597         1654  
56             }
57              
58             # Neither the remote host nor the destination did not matched with any value of RhostClass
59 2386         11785 for my $e ( keys %$RhostClass ) {
60             # Try to match the client host with each value of RhostClass
61 44824 100       62525 next unless grep { index($clienthost, $_) > -1 } $RhostClass->{ $e }->@*;
  73831         139773  
62 249         668 $rhostclass = $e; last FINDRHOST;
  249         737  
63             }
64 2137         6348 last;
65             }
66 3320         19647 return $rhostclass;
67             }
68              
69             sub find {
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 3231     3231 0 293674 my $class = shift;
74 3231   100     8626 my $argvs = shift || return "";
75 3230   100     15194 my $rhost = __PACKAGE__->name($argvs) || return "";
76              
77 1093         3693 $rhost = __PACKAGE__."::".$rhost; (my $modulepath = $rhost) =~ s|::|/|g;
  1093         8156  
78 1093         79891 require $modulepath.'.pm';
79 1093         11329 return $rhost->find($argvs);
80             }
81              
82             1;
83             __END__