File Coverage

lib/Sisimai/Reason/HostUnknown.pm
Criterion Covered Total %
statement 29 29 100.0
branch 12 12 100.0
condition 7 10 70.0
subroutine 7 7 100.0
pod 2 4 50.0
total 57 62 91.9


line stmt bran cond sub pod time code
1             package Sisimai::Reason::HostUnknown;
2 35     35   1736 use feature ':5.10';
  35         57  
  35         2322  
3 35     35   236 use strict;
  35         57  
  35         650  
4 35     35   143 use warnings;
  35         61  
  35         11649  
5              
6 105     105 1 190 sub text { 'hostunknown' }
7 4     4 0 14 sub description { "Delivery failed due to a domain part of a recipient's email address does not exist" }
8             sub match {
9             # Try to match that the given text and regular expressions
10             # @param [String] argv1 String to be matched with regular expressions
11             # @return [Integer] 0: Did not match
12             # 1: Matched
13             # @since v4.0.0
14 878     878 1 1325 my $class = shift;
15 878   50     1717 my $argv1 = shift // return undef;
16              
17 878         1107 state $index = [
18             'domain does not exist',
19             'domain is not reachable',
20             'domain must exist',
21             'host or domain name not found',
22             'host unknown',
23             'host unreachable',
24             'mail domain mentioned in email address is unknown',
25             'name or service not known',
26             'no such domain',
27             'recipient address rejected: unknown domain name',
28             'recipient domain must exist',
29             'the account or domain may not exist',
30             'unknown host',
31             'unroutable address',
32             'unrouteable address',
33             ];
34 878         1011 state $regex = qr/553[ ][^ ]+[ ]does[ ]not[ ]exist/;
35 878 100       1462 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  13170         19007  
36 827 100       3619 return 1 if $argv1 =~ $regex;
37 822         1823 return 0;
38             }
39              
40             sub true {
41             # Whether the host is unknown or not
42             # @param [Sisimai::Data] argvs Object to be detected the reason
43             # @return [Integer] 1: is unknown host
44             # [Integer] 0: is not unknown host.
45             # @since v4.0.0
46             # @see http://www.ietf.org/rfc/rfc2822.txt
47 842     842 0 1263 my $class = shift;
48 842   100     1784 my $argvs = shift // return undef;
49 841 100       1657 return 1 if $argvs->reason eq 'hostunknown';
50              
51 821   50     4092 my $statuscode = $argvs->deliverystatus // '';
52 821   50     3831 my $diagnostic = lc $argvs->diagnosticcode // '';
53              
54 821 100 100     4137 if( (Sisimai::SMTP::Status->name($statuscode) || '') eq 'hostunknown' ) {
55             # Status: 5.1.2
56             # Diagnostic-Code: SMTP; 550 Host unknown
57 34         482 require Sisimai::Reason::NetworkError;
58 34 100       210 return 1 unless Sisimai::Reason::NetworkError->match($diagnostic);
59             } else {
60             # Check the value of Diagnosic-Code: header with patterns
61 787 100       1732 return 1 if __PACKAGE__->match($diagnostic);
62             }
63 747         2003 return 0;
64             }
65              
66             1;
67             __END__