File Coverage

lib/Sisimai/Reason/RequirePTR.pm
Criterion Covered Total %
statement 27 27 100.0
branch 8 8 100.0
condition 6 6 100.0
subroutine 8 8 100.0
pod 1 4 25.0
total 50 53 94.3


line stmt bran cond sub pod time code
1             package Sisimai::Reason::RequirePTR;
2 51     51   2735 use v5.26;
  51         149  
3 51     51   211 use strict;
  51         536  
  51         1113  
4 51     51   171 use warnings;
  51         86  
  51         2274  
5 51     51   201 use Sisimai::String;
  51         329  
  51         13816  
6              
7 92     92 1 213 sub text { 'requireptr' }
8 4     4 0 18 sub description { 'Email rejected due to missing PTR record or having invalid PTR record' }
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 v5.0.0
15 1142     1142 0 3059 my $class = shift;
16 1142   100     2551 my $argv1 = shift // return 0;
17              
18 1141         1598 state $index = [
19             "cannot find your hostname",
20             "cannot resolve your address.",
21             "corresponding forward dns entry does not point to the sending ip", # Google
22             "ip name lookup failed",
23             "no matches to nameserver query",
24             "sender ip reverse lookup rejected",
25             "unresolvable relay host name",
26             ];
27 1141         1410 state $pairs = [
28             ["domain "," mismatches client ip"],
29             ["domain name verification on your ip address ", "failed"],
30             ["dns lookup failure: ", " try again later"],
31             ["ptr", "record"],
32             ["reverse", " dns"],
33             ["server access ", " forbidden by invalid rdns record of your mail server"],
34             ["service permits ", " unverifyable sending ips"],
35             ];
36              
37 1141 100       1930 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  7987         11863  
38 1131 100       2081 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  7917         10222  
39 1058         2814 return 0;
40             }
41              
42             sub true {
43             # Rejected due to missing PTR record or having invalid PTR record
44             # @param [Sisimai::Fact] argvs Object to be detected the reason
45             # @return [Integer] 1: is missing PTR or invalid PTR
46             # [Integer] 0: is not blocked due to missing PTR record
47             # @see http://www.ietf.org/rfc/rfc2822.txt
48             # @since v5.0.0
49 1152     1152 0 2062 my $class = shift;
50 1152   100     2968 my $argvs = shift // return 0;
51              
52 1151 100       3384 return 1 if $argvs->{'reason'} eq 'requireptr';
53 1150 100 100     3601 return 1 if (Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || '') eq 'requireptr';
54 1140         3885 return __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
55             }
56              
57             1;
58             __END__