File Coverage

lib/Sisimai/SMTP/Failure.pm
Criterion Covered Total %
statement 57 57 100.0
branch 35 36 97.2
condition 53 56 94.6
subroutine 9 9 100.0
pod 3 4 75.0
total 157 162 96.9


line stmt bran cond sub pod time code
1             package Sisimai::SMTP::Failure;
2 87     87   137761 use v5.26;
  87         230  
3 87     87   308 use strict;
  87         117  
  87         1553  
4 87     87   292 use warnings;
  87         120  
  87         3378  
5 87     87   33400 use Sisimai::SMTP::Reply;
  87         203  
  87         3245  
6 87     87   45739 use Sisimai::SMTP::Status;
  87         188  
  87         36149  
7              
8             sub is_permanent {
9             # Returns true if the given string indicates a permanent error
10             # @param [String] argv1 String including SMTP Status code
11             # @return [Integer] 1: Is a permanet error
12             # 0: Is not a permanent error
13             # @since v4.17.3
14 814     814 1 245012 my $class = shift;
15 814   100     1575 my $argv1 = shift || return 0;
16              
17 803         2344 my $statuscode = Sisimai::SMTP::Status->find($argv1);
18 803   100     3770 $statuscode ||= Sisimai::SMTP::Reply->find($argv1) || '';
      100        
19              
20 803 100       2028 return 1 if substr($statuscode, 0, 1) eq "5";
21 568 100       1925 return 1 if index(lc $argv1, " permanent ") > -1;
22 543         1092 return 0;
23             }
24              
25             sub is_temporary {
26             # Returns true if the given string indicates a temporary error
27             # @param [String] argv1 String including SMTP Status code
28             # @return [Integer] 1: Is a temporary error
29             # 0: Is not a temporary error
30             # @since v5.2.0
31 1140     1140 1 1392 my $class = shift;
32 1140   100     2552 my $argv1 = shift || return 0;
33              
34 1065         2178 my $statuscode = Sisimai::SMTP::Status->find($argv1);
35 1065   100     3527 $statuscode ||= Sisimai::SMTP::Reply->find($argv1) || '';
      100        
36 1065         2182 my $issuedcode = lc $argv1;
37              
38 1065 100       2374 return 1 if substr($statuscode, 0, 1) eq "4";
39 1007 100       2325 return 1 if index($issuedcode, " temporar") > -1;
40 997 50       2005 return 1 if index($issuedcode, " persistent") > -1;
41 997         2177 return 0;
42             }
43              
44             sub is_hardbounce {
45             # Checks the reason sisimai detected is a hard bounce or not
46             # @param [String] argv1 The bounce reason sisimai detected
47             # @param [String] argv2 String including SMTP Status code
48             # @return [Bool] 1: is a hard bounce
49             # @since v5.2.0
50 3534     3534 1 17303 my $class = shift;
51 3534   50     7220 my $argv1 = shift || return 0;
52 3534   100     7707 my $argv2 = shift // '';
53              
54 3534 100 100     10619 return 0 if $argv1 eq "undefined" || $argv1 eq "onhold";
55 3490 100 100     15022 return 0 if $argv1 eq "delivered" || $argv1 eq "feedback" || $argv1 eq "vacation";
      100        
56 3487 100 100     15438 return 1 if $argv1 eq "hasmoved" || $argv1 eq "userunknown" || $argv1 eq "hostunknown";
      100        
57 2386 100       7256 return 0 if $argv1 ne "notaccept";
58              
59             # NotAccept: 5xx => hard bounce, 4xx => soft bounce
60 71         221 my $hardbounce = 0;
61 71 100       201 if( length $argv2 > 0 ) {
62             # Check the 2nd argument(a status code or a reply code)
63 70   100     209 my $cv = Sisimai::SMTP::Status->find($argv2, "") || Sisimai::SMTP::Reply->find($argv2, "") || '';
64 70 100       173 if( substr($cv, 0, 1) eq "5" ) {
65             # The SMTP status code or the SMTP reply code starts with "5"
66 32         45 $hardbounce = 1
67              
68             } else {
69             # Deal as a hard bounce when the error message does not indicate a temporary error
70 38 100       122 $hardbounce = 1 unless __PACKAGE__->is_temporary($argv2);
71             }
72             } else {
73             # Deal "NotAccept" as a hard bounce when the 2nd argument is empty
74 1         1 $hardbounce = 1;
75             }
76 71         237 return $hardbounce;
77             }
78              
79             sub is_softbounce {
80             # Checks the reason sisimai detected is a soft bounce or not
81             # @param [String] argv1 The bounce reason sisimai detected
82             # @param [String] argv2 String including SMTP Status code
83             # @return [Bool] 1: is a soft bounce
84             # @since v5.2.0
85 29     29 0 53 my $class = shift;
86 29   50     55 my $argv1 = shift || return 0;
87 29   100     89 my $argv2 = shift // '';
88              
89 29 100 100     107 return 0 if $argv1 eq "delivered" || $argv1 eq "feedback" || $argv1 eq "vacation";
      100        
90 26 100 100     71 return 0 if $argv1 eq "hasmoved" || $argv1 eq "userunknown" || $argv1 eq "hostunknown";
      100        
91 23 100 100     49 return 1 if $argv1 eq "undefined" || $argv1 eq "onhold";
92 21 100       63 return 1 if $argv1 ne "notaccept";
93              
94             # NotAccept: 5xx => hard bounce, 4xx => soft bounce
95 3         4 my $softbounce = 0;
96 3 100       5 if( length $argv2 > 0 ) {
97             # Check the 2nd argument(a status code or a reply code)
98 2   50     8 my $cv = Sisimai::SMTP::Status->find($argv2, "") || Sisimai::SMTP::Reply->find($argv2, "") || '';
99 2 100       5 $softbounce = 1 if substr($cv, 0, 1) eq "4";
100             }
101 3         12 return $softbounce;
102             }
103              
104             1;
105             __END__