File Coverage

lib/Sisimai/Rhost.pm
Criterion Covered Total %
statement 36 36 100.0
branch 5 6 83.3
condition 10 11 90.9
subroutine 6 6 100.0
pod 1 2 50.0
total 58 61 95.0


line stmt bran cond sub pod time code
1             package Sisimai::Rhost;
2 76     76   520613 use feature ':5.10';
  76         189  
  76         5609  
3 76     76   407 use strict;
  76         145  
  76         1600  
4 76     76   406 use warnings;
  76         214  
  76         22007  
5              
6 76         25979 use constant RhostClass => {
7             qr/[.](?:prod|protection)[.]outlook[.]com\z/ => 'ExchangeOnline',
8             qr/\b(?>laposte[.]net|(?:orange|wanadoo)[.]fr)\z/ => 'FrancePTT',
9             qr/\A(?:smtp|mailstore1)[.]secureserver[.]net\z/ => 'GoDaddy',
10             qr/(?:aspmx|gmail-smtp-in)[.]l[.]google[.]com\z/ => 'GoogleApps',
11             qr/[.]email[.]ua\z/ => 'IUA',
12             qr/[.](?:ezweb[.]ne[.]jp|au[.]com)\z/ => 'KDDI',
13             qr/charter[.]net/ => 'Spectrum',
14             qr/cox[.]net/ => 'Cox',
15             qr/mx[0-9]+[.]qq[.]com\z/ => 'TencentQQ',
16 76     76   511 };
  76         143  
17              
18             sub match {
19             # The value of "rhost" is listed in RhostClass or not
20             # @param [String] argv1 Remote host name
21             # @return [Integer] 0: did not match
22             # 1: match
23 4860     4860 1 29529 my $class = shift;
24 4860   100     7688 my $rhost = shift // return undef;
25 4859   100     10512 my $host0 = lc($rhost) || return 0;
26 4215         6324 my $match = 0;
27              
28 4215         4638 for my $e ( keys %{ RhostClass() } ) {
  4215         12970  
29             # Try to match with each key of RhostClass
30 36498 100       730904 next unless $host0 =~ $e;
31 430         1084 $match = 1;
32 430         685 last;
33             }
34 4215         17046 return $match;
35             }
36              
37             sub get {
38             # Detect the bounce reason from certain remote hosts
39             # @param [Sisimai::Data] argvs Parsed email object
40             # @param [String] proxy The alternative of the "rhost"
41             # @return [String] The value of bounce reason
42 347     347 0 678 my $class = shift;
43 347   100     1020 my $argvs = shift || return undef;
44 346   100     1261 my $proxy = shift || undef;
45              
46 346   66     1348 my $remotehost = $proxy || lc $argvs->rhost;
47 346         1996 my $rhostclass = '';
48              
49 346         435 for my $e ( keys %{ RhostClass() } ) {
  346         1110  
50             # Try to match with each key of RhostClass
51 2008 100       35962 next unless $remotehost =~ $e;
52 346         1287 $rhostclass = __PACKAGE__.'::'.RhostClass->{ $e };
53 346         1212 last;
54             }
55 346 50       1885 return undef unless $rhostclass;
56              
57 346         1459 (my $modulepath = $rhostclass) =~ s|::|/|g;
58 346         19731 require $modulepath.'.pm';
59 346         2437 return $rhostclass->get($argvs);
60             }
61              
62             1;
63             __END__