Changes

From SME Server
Jump to navigationJump to search
1,639 bytes added ,  12:35, 26 February 2009
Line 5: Line 5:  
The DMZS script (LGPL) works over IMAP. It reads the mail from two folders (LearnAsSpam and LearnAsHam) and feeds it to SpamAssasin's sa-learn. This script is implemented here in a way that it makes use of public folders in Zarafa.
 
The DMZS script (LGPL) works over IMAP. It reads the mail from two folders (LearnAsSpam and LearnAsHam) and feeds it to SpamAssasin's sa-learn. This script is implemented here in a way that it makes use of public folders in Zarafa.
   −
==== Installation ====
+
=== Installation ===
  yum install perl-Mail-IMAPClient --enablerepo=extras
  −
  wget http://www.dmzs.com/tools/files/spam/DMZS-sa-learn.pl
  −
  mv DMZS-sa-learn.pl /usr/bin/
      +
====Bayes====
 +
yum install perl-Mail-IMAPClient --enablerepo=extras
 +
 +
nano -w /usr/bom/DMZS-sa-learn.pl
 +
 +
#!/usr/bin/perl
 +
#
 +
# Process mail from imap server shared folder 'Public folders/LearnAsSpam' & 'Public folders/LearnAsHam' through spamassassin sa-learn
 +
# dmz@dmzs.com - March 19, 2004
 +
# http://www.dmzs.com/tools/files/spam.phtml
 +
# http://www.dmzs.com/tools/files/spam/DMZS-sa-learn.pl [modified for SMEServer]
 +
# LGPL
 +
 +
use Mail::IMAPClient;
 +
 +
my $debug=0;
 +
my $salearn;
 +
 +
#EDIT USER AND PASSWORD
 +
my $imap = Mail::IMAPClient->new( Server=> '127.0.0.1:8143',
 +
                                  User => 'SpamAdminjane',
 +
                                  Password => 'SpamAdminPassword',
 +
                                  Debug => $debug);
 +
 +
if (!defined($imap)) { die "IMAP Login Failed"; }
 +
 +
# If debugging, print out the total counts for each mailbox
 +
if ($debug) {
 +
  my $spamcount = $imap->message_count('Public folders/LearnAsSpam');
 +
  print $spamcount, " Spam to process\n";
 +
 +
  my $nonspamcount = $imap->message_count('Public folders/LearnAsHam');
 +
  print $nonspamcount, " Notspam to process\n" if $debug;
 +
}
 +
 +
# Process the spam mailbox
 +
$imap->select('Public folders/LearnAsSpam');
 +
my @msgs = $imap->search("ALL");
 +
for (my $i=0;$i <= $#msgs; $i++)
 +
{
 +
  # I put it into a file for processing, doing it into a perl var & piping through sa-learn just didn't seem to work
 +
  $imap->message_to_file("/tmp/salearn",$msgs[$i]);
 +
 +
  # execute sa-learn w/data
 +
  if ($debug) { $salearn = `/usr/bin/sa-learn -D --no-sync  --spam /tmp/salearn`; }
 +
  else { $salearn = `/usr/bin/sa-learn --no-sync  --spam /tmp/salearn`; }
 +
  print "-------\nSpam: ",$salearn,"\n-------\n" if $debug;
 +
 +
  # delete processed message
 +
  $imap->delete_message($msgs[$i]);
 +
  unlink("/tmp/salearn");
 +
}
 +
$imap->expunge();
 +
$imap->close();
 +
 +
# Process the not-spam mailbox
 +
$imap->select('Public folders/LearnAsHam');
 +
my @msgs = $imap->search("ALL");
 +
for (my $i=0;$i <= $#msgs; $i++)
 +
{
 +
  $imap->message_to_file("/tmp/salearn",$msgs[$i]);
 +
  # execute sa-learn w/data
 +
  if ($debug) { $salearn = `/usr/bin/sa-learn -D --no-sync  --ham /tmp/salearn`; }
 +
  else { $salearn = `/usr/bin/sa-learn --no-sync  --ham /tmp/salearn`; }
 +
  print "-------\nNotSpam: ",$salearn,"\n-------\n" if $debug;
 +
 +
  # delete processed message
 +
  $imap->delete_message($msgs[$i]);
 +
  unlink("/tmp/salearn");
 +
}
 +
$imap->expunge();
 +
$imap->close();
 +
 +
$imap->logout();
 +
 +
# integrate learned stuff
 +
my $sarebuild = `/usr/bin/sa-learn --sync`;
 +
print "-------\nRebuild: ",$sarebuild,"\n-------\n" if $debug;
 +
 +
====Zarafa====
 
Create a user-account in Zarafa for reading the public spam-folders.  
 
Create a user-account in Zarafa for reading the public spam-folders.  
 
   db method, Replace the <MyPassword> with a proper strong password.
 
   db method, Replace the <MyPassword> with a proper strong password.
Line 17: Line 94:  
   db accounts setprop SpamAdmin zarafa enabled
 
   db accounts setprop SpamAdmin zarafa enabled
 
   /etc/e-smith/events/actions/qmail-update-user
 
   /etc/e-smith/events/actions/qmail-update-user
  −
Now we'll edit the script and replace the Server, User and Password values. We will also have to replace two folder names throughout the script:
  −
  pico /usr/bin/DMZS-sa-learn.pl
  −
  −
Replace the values so it looks like below, replace <MyPassword> for the password you have chosen in a previous step:
  −
  −
  my $imap = Mail::IMAPClient->new( Server=> '127.0.0.1:8143',
  −
                                    User => 'SpamAdmin',
  −
                                    Password => '<MyPassword>',
  −
                                    Debug => $debug);
  −
  −
Throughout the script (be aware of the quotes):
  −
  replace: 'spam'  ->  with: 'Public folders/LearnAsSpam'
  −
  replace: 'not-spam'  ->  with: 'Public folders/LearnAsHam'
  −
  remove: --showdots
      
Set proper permissions on the script:
 
Set proper permissions on the script:
 
   chmod 555 /usr/bin/DMZS-sa-learn.pl
 
   chmod 555 /usr/bin/DMZS-sa-learn.pl
  −
Create a file for the script to write some temporary output to:
  −
  touch /tmp/salearn
      
Login to Zarafa with an account that has admin rights and make two new folders LearnAsSpam and LearnAsHam under: Public folder > Public folders.
 
Login to Zarafa with an account that has admin rights and make two new folders LearnAsSpam and LearnAsHam under: Public folder > Public folders.
Line 54: Line 113:  
{{Note box| Dropping mail in the public 'LearnAsHam' folder may pose a privacy problem if permissions are set less restrictive as shown above!}}
 
{{Note box| Dropping mail in the public 'LearnAsHam' folder may pose a privacy problem if permissions are set less restrictive as shown above!}}
    +
====Cron====
 
Create a new crontab fragment:
 
Create a new crontab fragment:
 
   pico /etc/e-smith/templates/etc/crontab/91_SpamAssasinLearn
 
   pico /etc/e-smith/templates/etc/crontab/91_SpamAssasinLearn

Navigation menu