File Coverage

lib/Sisimai/Reason/HostUnknown.pm
Criterion Covered Total %
statement 35 35 100.0
branch 12 12 100.0
condition 8 10 80.0
subroutine 8 8 100.0
pod 2 4 50.0
total 65 69 94.2


line stmt bran cond sub pod time code
1             package Sisimai::Reason::HostUnknown;
2 42     42   2917 use v5.26;
  42         167  
3 42     42   308 use strict;
  42         89  
  42         1163  
4 42     42   233 use warnings;
  42         75  
  42         2402  
5 42     42   290 use Sisimai::String;
  42         2045  
  42         19081  
6              
7 111     111 1 298 sub text { 'hostunknown' }
8 4     4 0 14 sub description { "Delivery failed due to a domain part of a recipient's email address does not exist" }
9             sub match {
10             # Try to match that the given text and regular expressions
11             # @param [String] argv1 String to be matched with regular expressions
12             # @return [Integer] 0: Did not match
13             # 1: Matched
14             # @since v4.0.0
15 765     765 1 2959 my $class = shift;
16 765   100     2666 my $argv1 = shift // return 0;
17              
18 764         1398 state $index = [
19             "domain is not reachable",
20             "domain mentioned in email address is unknown",
21             "domain must exist",
22             "host or domain name not found",
23             "host unknown",
24             "host unreachable",
25             "name or service not known",
26             "no such domain",
27             "recipient address rejected: unknown domain name",
28             "unknown host",
29             ];
30 764         1543 state $pairs = [
31             ["domain ", "not exist"],
32             ["unrout", "able ", "address"],
33             ];
34              
35 764 100       1891 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  7640         14737  
36 722 100       1525 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  1444         4424  
37 717         3189 return 0;
38             }
39              
40             sub true {
41             # Whether the host is unknown or not
42             # @param [Sisimai::Fact] 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 817     817 0 1822 my $class = shift;
48 817   100     2430 my $argvs = shift // return 0;
49              
50 816         3481 require Sisimai::SMTP::Command;
51 816 100       3482 return 1 if $argvs->{'reason'} eq 'hostunknown';
52 785 100       3351 return 0 if grep { $argvs->{'command'} eq $_ } Sisimai::SMTP::Command->BeforeRCPT->@*;
  4710         9129  
53              
54 704   50     2409 my $statuscode = $argvs->{'deliverystatus'} // '';
55 704   50     2908 my $issuedcode = lc $argvs->{'diagnosticcode'} // '';
56              
57 704 100 100     2817 if( (Sisimai::SMTP::Status->name($statuscode) || '') eq 'hostunknown' ) {
58             # To prevent classifying DNS errors as "HostUnknown"
59 40         2342 require Sisimai::Reason::NetworkError;
60 40 100       392 return 1 unless Sisimai::Reason::NetworkError->match($issuedcode);
61              
62             } else {
63             # Status: 5.1.2
64             # Diagnostic-Code: SMTP; 550 Host unknown
65 664         2510 return __PACKAGE__->match($issuedcode);
66             }
67 5         31 return 0;
68             }
69              
70             1;
71             __END__