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 45     45   1945 use v5.26;
  45         147  
3 45     45   170 use strict;
  45         61  
  45         904  
4 45     45   140 use warnings;
  45         56  
  45         1998  
5 45     45   194 use Sisimai::String;
  45         69  
  45         15414  
6              
7 116     116 1 239 sub text { 'hostunknown' }
8 4     4 0 20 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 852     852 1 2651 my $class = shift;
16 852   100     2057 my $argv1 = shift // return 0;
17              
18 851         2322 state $index = [
19             "all host address lookups failed", # Exim/transports/smtp.c:3524
20             "couldn't find any host ", # qmail-remote.c:78
21             "dns server returned answer with no data",
22             "domain is not reachable",
23             "domain mentioned in email address is unknown",
24             "domain must exist",
25             "domain name not found",
26             "host or domain name not found",
27             "host unknown",
28             "host unreachable",
29             "illegal host/domain name found",
30             "invalid domain name", # OpenSMTPD/smtpd/mta.c:976
31             "mx records point to non-existent hosts", # Exim/routers/dnslookup.c:331
32             "name or service not known",
33             "no such domain",
34             "recipient address rejected: unknown domain name",
35             "responded with code nxdomain",
36             "unknown host",
37             ];
38 851         937 state $pairs = [
39             ["domain ", "not exist"],
40             ["host ", " not found"],
41             ["unrout", "able ", "address"],
42             ];
43              
44 851 100       1398 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  15318         20332  
45 804 100       1206 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  2412         3743  
46 779         1986 return 0;
47             }
48              
49             sub true {
50             # Whether the host is unknown or not
51             # @param [Sisimai::Fact] argvs Object to be detected the reason
52             # @return [Integer] 1: is unknown host
53             # [Integer] 0: is not unknown host.
54             # @since v4.0.0
55             # @see http://www.ietf.org/rfc/rfc2822.txt
56 889     889 0 1326 my $class = shift;
57 889   100     2014 my $argvs = shift // return 0;
58              
59 888         2383 require Sisimai::SMTP::Command;
60 888 100       2105 return 1 if $argvs->{'reason'} eq 'hostunknown';
61 887 100       2447 return 0 if grep { $argvs->{'command'} eq $_ } Sisimai::SMTP::Command->BeforeRCPT->@*;
  5322         8300  
62              
63 801   50     2076 my $statuscode = $argvs->{'deliverystatus'} // '';
64 801   50     2549 my $issuedcode = lc $argvs->{'diagnosticcode'} // '';
65              
66 801 100 100     1875 if( (Sisimai::SMTP::Status->name($statuscode) || '') eq 'hostunknown' ) {
67             # To prevent classifying DNS errors as "HostUnknown"
68 50         1799 require Sisimai::Reason::NetworkError;
69 50 100       302 return 1 unless Sisimai::Reason::NetworkError->match($issuedcode);
70              
71             } else {
72             # Status: 5.1.2
73             # Diagnostic-Code: SMTP; 550 Host unknown
74 751         1716 return __PACKAGE__->match($issuedcode);
75             }
76 5         18 return 0;
77             }
78              
79             1;
80             __END__