File Coverage

lib/Sisimai/Reason/SpamDetected.pm
Criterion Covered Total %
statement 33 33 100.0
branch 11 12 91.6
condition 6 6 100.0
subroutine 9 9 100.0
pod 2 4 50.0
total 61 64 95.3


line stmt bran cond sub pod time code
1             package Sisimai::Reason::SpamDetected;
2 48     48   3151 use v5.26;
  48         189  
3 48     48   311 use strict;
  48         96  
  48         2626  
4 48     48   228 use warnings;
  48         1826  
  48         2459  
5 48     48   313 use Sisimai::String;
  48         122  
  48         1371  
6 48     48   237 use Sisimai::SMTP::Command;
  48         147  
  48         24924  
7              
8 52     52 1 151 sub text { 'spamdetected' }
9 4     4 0 15 sub description { 'Email rejected by spam filter running on the remote host' }
10             sub match {
11             # Try to match that the given text and regular expressions
12             # @param [String] argv1 String to be matched with regular expressions
13             # @return [Integer] 0: Did not match
14             # 1: Matched
15             # @since v4.1.19
16 1399     1399 1 3653 my $class = shift;
17 1399   100     3802 my $argv1 = shift // return 0;
18              
19 1398         2339 state $index = [
20             "blacklisted url in message",
21             "block for spam",
22             "blocked by policy: no spam please",
23             "blocked by spamassassin", # rejected by SpamAssassin
24             "classified as spam and is rejected",
25             "content filter rejection",
26             "denied due to spam list",
27             "identified spam", # 554 SpamBouncer identified SPAM, message permanently rejected (#5.3.0)
28             "may consider spam",
29             "message content rejected",
30             "message has been temporarily blocked by our filter",
31             "message is being rejected as it seems to be a spam",
32             "message was rejected by recurrent pattern detection system",
33             "our email server thinks this email is spam",
34             "reject bulk.advertising",
35             "spam check",
36             "spam content ",
37             "spam detected",
38             "spam email",
39             "spam-like header",
40             "spam message",
41             "spam not accepted",
42             "spam refused",
43             "spamming not allowed",
44             "unsolicited ",
45             "your email breaches local uribl policy",
46             ];
47 1398         2769 state $pairs = [
48             ["accept", " spam"],
49             ["appears", " to ", "spam"],
50             ["bulk", "mail"],
51             ["considered", " spam"],
52             ["contain", " spam"],
53             ["detected", " spam"],
54             ["greylisted", " please try again in"],
55             ["mail score (", " over "],
56             ["mail rejete. mail rejected. ", "506"],
57             ["message ", "as spam"],
58             ["message ", "like spam"],
59             ["message ", "spamprofiler"],
60             ["probab", " spam"],
61             ["refused by", " spamprofiler"],
62             ["reject", " content"],
63             ["reject, id=", "spam"],
64             ["rejected by ", " (spam)"],
65             ["rejected due to spam ", "classification"],
66             ["rule imposed as ", " is blacklisted on"],
67             ["score", "spam"],
68             ["spam ", "block"],
69             ["spam ", "filter"],
70             ["spam ", " exceeded"],
71             ["spam ", "score"],
72             ];
73 1398 100       3041 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  36348         62085  
74 1335 100       2728 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  32040         71239  
75 1293         6551 return 0;
76             }
77              
78             sub true {
79             # Rejected due to spam content in the message
80             # @param [Sisimai::Fact] argvs Object to be detected the reason
81             # @return [Integer] 1: rejected due to spam
82             # 0: is not rejected due to spam
83             # @since v4.1.19
84             # @see http://www.ietf.org/rfc/rfc2822.txt
85 1678     1678 0 13849 my $class = shift;
86 1678 100 100     4295 my $argvs = shift // return 0; return 0 unless $argvs->{'deliverystatus'};
  1677         5926  
87              
88 1213 100       3231 return 1 if $argvs->{'reason'} eq 'spamdetected';
89 1212 50 100     4582 return 1 if (Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || '') eq 'spamdetected';
90              
91             # The value of "reason" isn't "spamdetected" when the value of "command" is an SMTP command to
92             # be sent before the SMTP DATA command because all the MTAs read the headers and the entire
93             # message body after the DATA command.
94 1212 100       4652 return 0 if grep { $argvs->{'command'} eq $_ } Sisimai::SMTP::Command->ExceptDATA->@*;
  6060         12148  
95 818         3545 return __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
96             }
97              
98             1;
99             __END__