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 43     43   2655 use v5.26;
  43         128  
3 43     43   469 use strict;
  43         57  
  43         1097  
4 43     43   141 use warnings;
  43         70  
  43         12709  
5              
6 12     12 1 29 sub text { 'ratelimited' }
7 4     4 0 18 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 822     822 1 2469 my $class = shift;
15 822   100     1684 my $argv1 = shift // return 0;
16              
17 821         934 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 821         1025 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 821 100       1342 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  8210         11053  
36 819 100       1370 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  3276         4796  
37 808         1900 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 737     737 0 1249 my $class = shift;
48 737   100     1776 my $argvs = shift // return 0;
49              
50 736 100       1945 return 1 if $argvs->{'reason'} eq 'ratelimited';
51 735 50 100     1800 return 1 if (Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || '') eq 'ratelimited';
52 735         2390 return __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
53             }
54              
55             1;
56             __END__