File Coverage

lib/Sisimai/Reason/RateLimited.pm
Criterion Covered Total %
statement 24 24 100.0
branch 7 8 87.5
condition 6 6 100.0
subroutine 7 7 100.0
pod 2 4 50.0
total 46 49 93.8


line stmt bran cond sub pod time code
1             package Sisimai::Reason::RateLimited;
2 44     44   4248 use v5.26;
  44         176  
3 44     44   343 use strict;
  44         103  
  44         1506  
4 44     44   239 use warnings;
  44         119  
  44         18349  
5              
6 12     12 1 57 sub text { 'ratelimited' }
7 4     4 0 16 sub description { "Rejected due to exceeding a rate limit: sending too fast or too many concurrency connections" }
8             sub match {
9             # Try to match that the given text and regular expressions
10             # @param [String] argv1 String to be matched with regular expressions
11             # @return [Integer] 0: Did not match
12             # 1: Matched
13             # @since v4.1.26
14 1170     1170 1 3756 my $class = shift;
15 1170   100     8545 my $argv1 = shift // return 0;
16              
17 1169         1801 state $index = [
18             "has exceeded the max emails per hour ",
19             "please try again slower",
20             "receiving mail at a rate that prevents additional messages from being delivered",
21             "temporarily deferred due to unexpected volume or user complaints",
22             "throttling failure: ",
23             "too many errors from your ip", # Free.fr
24             "too many recipients", # ntt docomo
25             "too many smtp sessions for this host", # Sendmail(daemon.c)
26             "trop de connexions, ",
27             "we have already made numerous attempts to deliver this message",
28             ];
29 1169         1715 state $pairs = [
30             ["exceeded ", "allowable number of posts without solving a captcha"],
31             ["connection ", "limit"],
32             ["temporarily", "rate limited"],
33             ["too many con", "s"],
34             ];
35 1169 100       2582 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  11690         23704  
36 1167 100       2945 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  4668         14840  
37 1156         4380 return 0;
38             }
39              
40             sub true {
41             # Blocked due to that connection rate limit exceeded
42             # @param [Sisimai::Fact] argvs Object to be detected the reason
43             # @return [Integer] 1: Rate limited
44             # 0: Not rate limited
45             # @since v4.1.26
46             # @see http://www.ietf.org/rfc/rfc2822.txt
47 670     670 0 1687 my $class = shift;
48 670   100     2312 my $argvs = shift // return 0;
49              
50 669 100       3509 return 1 if $argvs->{'reason'} eq 'ratelimited';
51 668 50 100     3152 return 1 if (Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || '') eq 'ratelimited';
52 668         3912 return __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
53             }
54              
55             1;
56             __END__