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   2107 use feature ':5.10';
  35         70  
  35         2684  
3 35     35   213 use strict;
  35         70  
  35         683  
4 35     35   176 use warnings;
  35         62  
  35         13794  
5              
6 105     105 1 274 sub text { 'hostunknown' }
7 4     4 0 16 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 858     858 1 1254 my $class = shift;
15 858   50     1896 my $argv1 = shift // return undef;
16              
17 858         1202 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 858         1368 state $regex = qr/553[ ][^ ]+[ ]does[ ]not[ ]exist/;
35 858 100       1522 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  12870         21752  
36 807 100       4095 return 1 if $argv1 =~ $regex;
37 802         1772 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 822     822 0 1343 my $class = shift;
48 822   100     1856 my $argvs = shift // return undef;
49 821 100       1713 return 1 if $argvs->reason eq 'hostunknown';
50              
51 801   50     4152 my $statuscode = $argvs->deliverystatus // '';
52 801   50     3931 my $diagnostic = lc $argvs->diagnosticcode // '';
53              
54 801 100 100     4543 if( (Sisimai::SMTP::Status->name($statuscode) || '') eq 'hostunknown' ) {
55             # Status: 5.1.2
56             # Diagnostic-Code: SMTP; 550 Host unknown
57 34         604 require Sisimai::Reason::NetworkError;
58 34 100       236 return 1 unless Sisimai::Reason::NetworkError->match($diagnostic);
59             } else {
60             # Check the value of Diagnosic-Code: header with patterns
61 767 100       1932 return 1 if __PACKAGE__->match($diagnostic);
62             }
63 727         2021 return 0;
64             }
65              
66             1;
67             __END__