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 51     51   2473 use v5.26;
  51         144  
3 51     51   224 use strict;
  51         64  
  51         873  
4 51     51   149 use warnings;
  51         70  
  51         3164  
5 51     51   186 use Sisimai::String;
  51         83  
  51         1014  
6 51     51   168 use Sisimai::SMTP::Command;
  51         77  
  51         18453  
7              
8 52     52 1 124 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 1489     1489 1 3215 my $class = shift;
17 1489   100     2714 my $argv1 = shift // return 0;
18              
19 1488         1641 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 1488         2244 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 1488 100       2399 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  38688         47242  
74 1420 100       2100 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  34080         40724  
75 1378         3143 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 1817     1817 0 2228 my $class = shift;
86 1817 100 100     3269 my $argvs = shift // return 0; return 0 unless $argvs->{'deliverystatus'};
  1816         4579  
87              
88 1193 100       2481 return 1 if $argvs->{'reason'} eq 'spamdetected';
89 1192 50 100     3068 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 1192 100       3014 return 0 if grep { $argvs->{'command'} eq $_ } Sisimai::SMTP::Command->ExceptDATA->@*;
  5960         8515  
95 798         2185 return __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
96             }
97              
98             1;
99             __END__