Filtering Spam
From Veximwiki
Contents |
Filtering Spam New
If you want to store potential Spamemails in a Spamfolder, instead of dropping them, you can replace the existing ditch_spam Router by a new one:
ditch_spam:
driver = redirect
allow_fail
file_transport = ditch_spam_transport
data = ${lookup mysql{select concat(smtp,'/.Spam') \
from users,domains \
where localpart = '${quote_mysql:$local_part}' \
and domain = '${quote_mysql:$domain}' \
and domains.enabled = '1' \
and users.enabled = '1' \
and users.domain_id = domains.domain_id}}
condition = ${if >{$spam_score_int}{${lookup mysql{select \
users.sa_refuse * 10 from users,domains \
where localpart = '${quote_mysql:$local_part}' \
and domain = '${quote_mysql:$domain}' \
and users.on_spamassassin = '1' \
and users.on_forward = '0' \
and users.type = 'local' \
and users.domain_id=domains.domain_id \
and users.sa_refuse > 0 }{$value}fail}} {yes}{no}}
local_part_suffix = -*
local_part_suffix_optional
retry_use_local_part
This Router uses a new Transport ditch_spam_transport:
ditch_spam_transport:
driver = appendfile
envelope_to_add
return_path_add
mode = 0600
maildir_format = true
create_directory = true
user = ${lookup mysql{select users.uid from users,domains \
where localpart = '${quote_mysql:$local_part}' \
and domain = '${quote_mysql:$domain}' \
and users.domain_id = domains.domain_id}}
group = ${lookup mysql{select users.gid from users,domains \
where localpart = '${quote_mysql:$local_part}' \
and domain = '${quote_mysql:$domain}' \
and users.domain_id = domains.domain_id}}
maildir_use_size_file = false
Note:
- The ditch_spam_transport block needs to go below the begin transports section in /etc/exim4/exim4.conf
Or you can let your users decide. Use the following Howto:
Add another two fields to your database: 'spam_drop' and 'on_spamreport'
If you'd like to use the changeable settings below, you have to add two columns to your users table. You can do this by using the phpmyadmin interface or typing the following mysql-statements (while been logged in as root)
use your vexim database
mysql> use vexim;
add the two columns to your users table (I added them after the column "on_spamassassin" to get it clearly arranged)
mysql> ALTER TABLE `users` ADD `spam_drop` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `on_spamassassin`,
> ADD `on_spamreport` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `spam_drop`;
You should get a reply like:
Query OK, 7 rows affected (0.00 sec) Records: 7 Duplicates: 0 Warnings: 0
you can check if it is done by using the "DESCRIBE" command
mysql> DESCRIBE users;
patch your userchange.php
Add the following code
print "<tr><td>" . _("SPAM Report") . ":</td>";
print "<td><input name=\"on_spamreport\" type=\"checkbox\"";
if ($row['on_spamreport'] == "1") { print " checked "; }
print ">" . _("Daily report about new mails in Spam folder") . "</td></tr>\n";
print "<tr><td>" . _("Drop SPAM") . ":</td>";
print "<td><input name=\"spam_drop\" type=\"checkbox\"";
if ($row['spam_drop'] == "1") { print " checked "; }
print ">" . _("Warning: This will delete all mails regarded as SPAM without warnings!!") .
"</td></tr>\n";
after
print "<tr><td>" . _("SpamAssassin refuse score") . ":</td>";
print "<td><input type=\"text\" size=\"5\" name=\"sa_refuse\" value=\"{
$row['sa_refuse']}\" class=\"textfield\"></td></tr>\n";
patch your userchangesubmit.php
Add the following code
if (isset($_POST['on_spamreport'])) {
$_POST['on_spamreport'] = 1;
} else {
$_POST['on_spamreport'] = 0;
}
if (isset($_POST['spam_drop'])) {
$_POST['spam_drop'] = 1;
} else {
$_POST['spam_drop'] = 0;
}
after
if ((isset($_POST['on_spamassassin']))
