From 59963205301f767297d3bd74deddd901cc7b2e09 Mon Sep 17 00:00:00 2001
From: J. Nick Koston <nick@cpanel.net>
Date: Tue, 30 Oct 2012 01:02:05 -0500
Subject: [PATCH] Allow the outgoing spam score rejection threshold to be
 defined in WHM

case 62004: Allow defining a specific spam score for rejection of outgoing
 messages (instead of the internal SA spam_score setting)
---
 Cpanel/Exim/Config/Def.pm                          |    1 +
 Whostmgr/TweakSettings/Mail.pm                     |   12 +++++++++++-
 .../outgoing_spam_scan_over_int                    |   18 ++++++++++++++++++
 .../outgoing_spam_scan_over_int                    |   19 +++++++++++++++++++
 whostmgr/docroot/themes/x/tweaksettings/Mail.yaml  |    8 +++++++-
 5 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 etc/exim/acls/ACL_OUTGOING_NOTSMTP_CHECKALL_BLOCK/outgoing_spam_scan_over_int
 create mode 100644 etc/exim/acls/ACL_OUTGOING_SMTP_CHECKALL_BLOCK/outgoing_spam_scan_over_int

diff --git a/Cpanel/Exim/Config/Def.pm b/Cpanel/Exim/Config/Def.pm
index 45d8a95..71bdba9 100644
--- a/Cpanel/Exim/Config/Def.pm
+++ b/Cpanel/Exim/Config/Def.pm
@@ -38,6 +38,7 @@ our @OFF_DEFAULT_ACLS = qw(
   deny_rcpt_hard_limit
   deny_rcpt_soft_limit
   outgoing_spam_scan
+  outgoing_spam_scan_over_int
   outgoing_malware_scan
 );
 
diff --git a/Whostmgr/TweakSettings/Mail.pm b/Whostmgr/TweakSettings/Mail.pm
index 187f450..bc54751 100644
--- a/Whostmgr/TweakSettings/Mail.pm
+++ b/Whostmgr/TweakSettings/Mail.pm
@@ -52,9 +52,19 @@ our %Conf = (
     },
     'acl_outgoing_spam_scan' => {
         'default'  => 0,
-        'excludes' => 'useoldspam',
+        'excludes' => [ 'useoldspam', 'acl_outgoing_spam_scan_over_int' ],
         'type'     => 'binary',
     },
+    'acl_outgoing_spam_scan_over_int' => {
+        'default'   => undef,
+        'excludes'  => [ 'useoldspam', 'acl_outgoing_spam_scan' ],
+        'can_undef' => 1,
+        'type'      => 'number',
+        'minimum'   => 0.1,
+        'maximum'   => 999.99,
+        'checkval'  => \&_is_spam_score,
+        'format'    => \&_format_spam_score,
+    },
     'trusted_mail_hosts_ips_button' => {
         'type'   => 'button',
         'popup'  => 1,
diff --git a/etc/exim/acls/ACL_OUTGOING_NOTSMTP_CHECKALL_BLOCK/outgoing_spam_scan_over_int b/etc/exim/acls/ACL_OUTGOING_NOTSMTP_CHECKALL_BLOCK/outgoing_spam_scan_over_int
new file mode 100644
index 0000000..0b2c11a
--- /dev/null
+++ b/etc/exim/acls/ACL_OUTGOING_NOTSMTP_CHECKALL_BLOCK/outgoing_spam_scan_over_int
@@ -0,0 +1,18 @@
+warn
+        condition   = ${if <= {$message_size}{[% ACL_MAX_SPAM_SCAN_SIZE %]K}{${if forall{<, $recipients}{match_domain{${domain:$item}}{+local_domains}}{0}{1}}}{0}}
+        condition   = ${if eq{$originator_uid}{0}{0}{1}}
+        set acl_c_outgoing_spam_scan = 1
+
+warn   
+        condition   = ${if eq{$acl_c_outgoing_spam_scan}{1}{1}{0}}
+        spam        = [% ACL_EXIMSCANUSER %]/defer_ok
+        log_message = "SpamAssassin as [% ACL_EXIMSCANUSER %] detected OUTGOING not smtp message as spam ($spam_score)"
+
+deny    
+        message     = This message was classified as SPAM and may not be delivered
+        condition   = ${if eq {$spam_score_int}{}{0}{${if >{$spam_score_int}{[% VALUE %]}{1}{0}}}}
+
+warn
+        log_message = "SpamAssassin as [% ACL_EXIMSCANUSER %] detected OUTGOING not smtp message as NOT spam ($spam_score)"
+        condition   = ${if eq{$acl_c_outgoing_spam_scan}{1}{1}{0}}
+        add_header = X-OutGoing-Spam-Status: No, score=$spam_score
diff --git a/etc/exim/acls/ACL_OUTGOING_SMTP_CHECKALL_BLOCK/outgoing_spam_scan_over_int b/etc/exim/acls/ACL_OUTGOING_SMTP_CHECKALL_BLOCK/outgoing_spam_scan_over_int
new file mode 100644
index 0000000..d1981c9
--- /dev/null
+++ b/etc/exim/acls/ACL_OUTGOING_SMTP_CHECKALL_BLOCK/outgoing_spam_scan_over_int
@@ -0,0 +1,19 @@
+warn
+        condition   = ${if <= {$message_size}{[% ACL_MAX_SPAM_SCAN_SIZE %]K}{1}{0}}
+        condition   = ${if forall{<, $recipients}{match_domain{${domain:$item}}{+local_domains}}{0}{1}}
+        set acl_c_outgoing_spam_scan = 1
+
+warn
+        condition   = ${if eq{$acl_c_outgoing_spam_scan}{1}{1}{0}}
+        spam        = ${if eq{$acl_m1}{}{[% ACL_EXIMSCANUSER %]}{$acl_m1}}/defer_ok
+        log_message = "SpamAssassin as ${if eq{$acl_m1}{}{[% ACL_EXIMSCANUSER %]}{$acl_m1}} detected OUTGOING not smtp message as spam ($spam_score)"
+
+deny
+        message     = This message was classified as SPAM and may not be delivered
+        condition   = ${if eq {$spam_score_int}{}{0}{${if >{$spam_score_int}{[% VALUE %]}{1}{0}}}}
+
+warn
+        log_message = "SpamAssassin as ${if eq{$acl_m1}{}{[% ACL_EXIMSCANUSER %]}{$acl_m1}} detected OUTGOING not smtp message as NOT spam ($spam_score)"
+        condition   = ${if eq{$acl_c_outgoing_spam_scan}{1}{1}{0}}
+        add_header = X-OutGoing-Spam-Status: No, score=$spam_score
+
diff --git a/whostmgr/docroot/themes/x/tweaksettings/Mail.yaml b/whostmgr/docroot/themes/x/tweaksettings/Mail.yaml
index 774dcd3..d165394 100644
--- a/whostmgr/docroot/themes/x/tweaksettings/Mail.yaml
+++ b/whostmgr/docroot/themes/x/tweaksettings/Mail.yaml
@@ -77,6 +77,7 @@ TS_display:
             - globalspamassassin
             - max_spam_scan_size
             - acl_outgoing_spam_scan
+            - acl_outgoing_spam_scan_over_int
 
 
 acl_0tracksenders:
@@ -141,9 +142,14 @@ acl_outgoing_malware_scan:
     help: 'If you have the ClamAVconnector plugin installed, enabling this option will reject mail bound for non-local domains that test positive for malware.'
 
 acl_outgoing_spam_scan:
-    label: 'Scan outgoing messages for spam'
+    label: 'Scan outgoing messages for spam and reject based on SpamAssassin® internal spam_score setting'
     help: 'Scan and reject mail bound for non-local domains that SpamAssassin® classifies as spam.'
 
+acl_outgoing_spam_scan_over_int:
+    label: 'Scan outgoing messages for spam and reject based on defined SpamAssassin® score'
+    help: 'Scan and reject mail bound for non-local domains that SpamAssassin® classifies as spam.'
+    undef: 'Disabled'
+
 acl_spf_bl:
     label: 'Reject SPF failures'
     help: 'Reject mail at SMTP time if the sender fails SPF checks.'
-- 
1.7.5

