Filtering Spam New

From Veximwiki

Jump to: navigation, search

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'])) && ($row['spamassassin'] = 1)) {
   $_POST['on_spamassassin'] = 1;
 } else {
   $_POST['on_spamassassin'] = 0;
 }

also the following code

               spam_drop={$_POST['spam_drop']},
               on_spamreport={$_POST['on_spamreport']}

after

   $query = "UPDATE users SET on_avscan='{$_POST['on_avscan']}',
               on_spamassassin={$_POST['on_spamassassin']},

exim4.conf

add this line to your exim4.conf ditch_spam router (the new one, see above)

 and users.spam_drop = '0' \

after the line:

 and users.on_spamassassin = '1' \


ditch_spam_drop router

rename the old router to ditch_spam_drop and add the following condition line

 and users.spam_drop = '1' \

after the line:

 and users.on_spamassassin = '1' \


that's it. Users can enable SPAM Dropping in their user configs. If set all Spam is dropped silently. If not it is delivered to Inbox or SPAM Folder. You can use the on_spamreport field to send an report about new SPAM Mails. Maybe I will post an script for this purpose later.


Enhanced by DK

If you'd like the Admin user also to be able to tweak this settings fpr users, then simply patch your adminuserchange.php and adminuserchangesubmit.php as follows: [edit] In your adminuserchange.php

Add the following code

 <tr>
   <td><?php echo _('SPAM Report'); ?>:</td>
   <td><input name="on_spamreport" type="checkbox" <?php
     if ($row['on_spamreport'] == "1") {
       print " checked ";
     } ?> class="textfield">
     Daily staus report about new mails in Spam folder
   </td>
 </tr>
 <tr>
   <td><? echo _('Drop SPAM'); ?>:</td>
   <td><input name="spam_drop" type="checkbox" <?php
     if ($row['spam_drop'] == "1") {
       print " checked ";
     }?> class="textfield">
     Warning: This will delete all mails regarded as SPAM without warnings!!
   </td>
 </tr>

after

 <tr>
   <td><?php echo _('Spamassassin refuse score'); ?>:</td>
   <td>
     <input type="text" size="5" name="sa_refuse"
       value="<?php echo $row['sa_refuse']; ?>" class="textfield">
   </td>
 </tr>

In your adminuserchangesubmit.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'])) && ($row['spamassassin'] = 1)) {
   $_POST['on_spamassassin'] = 1;
 } else {
   $_POST['on_spamassassin'] = 0;
 }

also the following code

   spam_drop={$_POST['spam_drop']},
   on_spamreport={$_POST['on_spamreport']},

after

   on_forward={$_POST['on_forward']},
   on_piped={$_POST['on_piped']},
   on_spamassassin={$_POST['on_spamassassin']},

and you're done. This should also enable the possibility to translate the text-strings into other languages.

Personal tools