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   2076 use feature ':5.10';
  35         63  
  35         2504  
3 35     35   208 use strict;
  35         67  
  35         679  
4 35     35   147 use warnings;
  35         63  
  35         12704  
5              
6 105     105 1 259 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 1397 my $class = shift;
15 858   50     1931 my $argv1 = shift // return undef;
16              
17 858         1197 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         1113 state $regex = qr/553[ ][^ ]+[ ]does[ ]not[ ]exist/;
35 858 100       1631 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  12870         21342  
36 807 100       4156 return 1 if $argv1 =~ $regex;
37 802         2000 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 1521 my $class = shift;
48 822   100     2146 my $argvs = shift // return undef;
49 821 100       1921 return 1 if $argvs->reason eq 'hostunknown';
50              
51 801   50     4543 my $statuscode = $argvs->deliverystatus // '';
52 801   50     4379 my $diagnostic = lc $argvs->diagnosticcode // '';
53              
54 801 100 100     5052 if( (Sisimai::SMTP::Status->name($statuscode) || '') eq 'hostunknown' ) {
55             # Status: 5.1.2
56             # Diagnostic-Code: SMTP; 550 Host unknown
57 34         575 require Sisimai::Reason::NetworkError;
58 34 100       246 return 1 unless Sisimai::Reason::NetworkError->match($diagnostic);
59             } else {
60             # Check the value of Diagnosic-Code: header with patterns
61 767 100       2137 return 1 if __PACKAGE__->match($diagnostic);
62             }
63 727         2102 return 0;
64             }
65              
66             1;
67             __END__