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 85     85   96534 use v5.26;
  85         473  
3 85     85   534 use strict;
  85         197  
  85         2438  
4 85     85   441 use warnings;
  85         135  
  85         4527  
5 85     85   42206 use Sisimai::SMTP::Reply;
  85         251  
  85         3977  
6 85     85   53427 use Sisimai::SMTP::Status;
  85         248  
  85         53240  
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 789     789 1 326578 my $class = shift;
15 789   100     2631 my $argv1 = shift || return 0;
16              
17 778         3333 my $statuscode = Sisimai::SMTP::Status->find($argv1);
18 778   100     5859 $statuscode ||= Sisimai::SMTP::Reply->find($argv1) || '';
      100        
19              
20 778 100       3889 return 1 if substr($statuscode, 0, 1) eq "5";
21 543 100       3057 return 1 if index(lc $argv1, " permanent ") > -1;
22 518         2058 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 1115     1115 1 2160 my $class = shift;
32 1115   100     4341 my $argv1 = shift || return 0;
33              
34 1040         3669 my $statuscode = Sisimai::SMTP::Status->find($argv1);
35 1040   100     5915 $statuscode ||= Sisimai::SMTP::Reply->find($argv1) || '';
      100        
36 1040         7618 my $issuedcode = lc $argv1;
37              
38 1040 100       3875 return 1 if substr($statuscode, 0, 1) eq "4";
39 982 100       3542 return 1 if index($issuedcode, " temporar") > -1;
40 972 50       3434 return 1 if index($issuedcode, " persistent") > -1;
41 972         4347 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 3514     3514 1 49147 my $class = shift;
51 3514   50     9899 my $argv1 = shift || return 0;
52 3514   100     12051 my $argv2 = shift // '';
53              
54 3514 100 100     16267 return 0 if $argv1 eq "undefined" || $argv1 eq "onhold";
55 3475 100 100     23665 return 0 if $argv1 eq "delivered" || $argv1 eq "feedback" || $argv1 eq "vacation";
      100        
56 3472 100 100     27864 return 1 if $argv1 eq "hasmoved" || $argv1 eq "userunknown" || $argv1 eq "hostunknown";
      100        
57 2381 100       14999 return 0 if $argv1 ne "notaccept";
58              
59             # NotAccept: 5xx => hard bounce, 4xx => soft bounce
60 71         201 my $hardbounce = 0;
61 71 100       287 if( length $argv2 > 0 ) {
62             # Check the 2nd argument(a status code or a reply code)
63 70   100     356 my $cv = Sisimai::SMTP::Status->find($argv2, "") || Sisimai::SMTP::Reply->find($argv2, "") || '';
64 70 100       382 if( substr($cv, 0, 1) eq "5" ) {
65             # The SMTP status code or the SMTP reply code starts with "5"
66 32         88 $hardbounce = 1
67              
68             } else {
69             # Deal as a hard bounce when the error message does not indicate a temporary error
70 38 100       223 $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         3 $hardbounce = 1;
75             }
76 71         346 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 64 my $class = shift;
86 29   50     105 my $argv1 = shift || return 0;
87 29   100     114 my $argv2 = shift // '';
88              
89 29 100 100     168 return 0 if $argv1 eq "delivered" || $argv1 eq "feedback" || $argv1 eq "vacation";
      100        
90 26 100 100     141 return 0 if $argv1 eq "hasmoved" || $argv1 eq "userunknown" || $argv1 eq "hostunknown";
      100        
91 23 100 100     82 return 1 if $argv1 eq "undefined" || $argv1 eq "onhold";
92 21 100       111 return 1 if $argv1 ne "notaccept";
93              
94             # NotAccept: 5xx => hard bounce, 4xx => soft bounce
95 3         6 my $softbounce = 0;
96 3 100       13 if( length $argv2 > 0 ) {
97             # Check the 2nd argument(a status code or a reply code)
98 2   50     10 my $cv = Sisimai::SMTP::Status->find($argv2, "") || Sisimai::SMTP::Reply->find($argv2, "") || '';
99 2 100       10 $softbounce = 1 if substr($cv, 0, 1) eq "4";
100             }
101 3         21 return $softbounce;
102             }
103              
104             1;
105             __END__