[qmailtoaster] learn-spam.pl

2008-07-06 Thread Jon Ernster
Figured I'd share something I wrote that others here might use since 
many of you have shared or helped me out as well.


I wrote this because when I go on vacation I usually shut down the 
laptop that has my mail rules which sends all my spam to the spam 
folder.  By the time I get back the shell script that I have that runs 
on a daily basis (courtesy of Jake Vickers) gives this error because 
there are too many spam files:


/root/learn-spam: /usr/bin/sa-learn: /usr/bin/perl: bad interpreter: Argument 
list too long
/root/learn-spam: line 10: /bin/rm: Argument list too long

So I just wrote this to process the files individually.  Not the fastest script 
in the world (because of SpamAssassin, not becaues of my code, obviously) ;), 
but it works.

J.






#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Std;

#~ $Id: learn-spam.pl 15 2008-07-03 17:27:09Z jernster $

my %opts = ();

getopts( 'd:u:', \%opts );

my ( $domain, $user ) = @opts{ qw( d u ) };

my $usage =EOF;
Usage:

   $0 -d example.com -u user

EOF

die $usage unless ( $domain  $user );

my $dir = /home/vpopmail/domains/$domain/$user/Maildir/cur;
my $starttime = time;
my $count = 0;

opendir(DIR, $dir);
my @files = readdir(DIR);
close(DIR);

foreach my $file ( @files )
{
   if ( $file =~ /^\./ )
   {
  next;

   }
   else
   {
  my $fpfile = $dir/$file;

  $count++;

  print Learning SPAM - $file\n;
  
  system(/usr/bin/sa-learn --spam $fpfile);

  print Deleting $file\n;

  unlink($fpfile);

   }

}

print Syncing databases...\n;
system(/usr/bin/sa-learn --sync);

print De-linting files...\n;
system(/usr/bin/spamassassin --lint);

system(chown vpopmail:vchkpw /home/vpopmail/.spamassassin/*);

system(/usr/bin/qmail-spam restart);

print Done!\n;

my $duration = time - $starttime;

print \nTotal duration: $duration seconds\n;
print Processed $count SPAM files.\n;

-
 QmailToaster hosted by: VR Hosted http://www.vr.org
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Re: [qmailtoaster] Issues after upgrade

2008-07-06 Thread Eric Shubert
[EMAIL PROTECTED] wrote:
 Hi Eric,
 
 looking in the archives, I noticed that in some cases, qmailctl would not
 start/stop all the process and sometimes you need to stop them manually. 
 Up until thursday(july 3rd), when I made a new tls certificate, I have
 always been able to stop/start the toaster with qmailctl.
 
 I noticed this in my /var/log/qmail/pop3-ssl
 Enter PEM pass phrase:tcpserver: status: 2/40
 @40004870446e2fe31dfc tcpserver: pid 17144 from 32.134.75.224

Here's  your problem. You need to create the cert with no pass phrase,
because there's no way for qmail to access it (entering the pass phrase)
that way.

 I was able to set the cert when I first set up my server, but that was a
 while ago.  Im not sure what Im doing wrong.  Im using centos 5 and I used
 http://wiki.qmailtoaster.com/index.php/Certificate to sign my own cert.

Looks like somehow step 2 got missed.

 Apache is very slow when going to webmail and pop3/imapd is not allowing
 any connections. There are several couriertls instances running in top.

That would be symptomatic.

 Whatever is running is really causing my server to run slow. SSH is timing
 out and/or running slow periodically as well.
 
 If this is a cert issue,
 would this be the correct way to set the cert with Centos 5?
 # cd /etc/pki/tls/certs
 # make stunnel.pem
 # mv stunnel.pem /var/qmail/control/servercert.pem
 # cd /var/qmail/control
 # chown root:qmail /var/qmail/control/servercert.pem
 # chmod 644 /var/qmail/control/servercert.pem
 # ln -s /var/qmail/control/servercert.pem /var/qmail/control/clientcert.pem

I don't know off hand.

 Im alittle confused on the permissions.  The perms set for servercert.pem
 above this method on the cert page uses these perms
 
 # chown root:vchkpw /var/qmail/control/servercert.pem
 # chmod 640 /var/qmail/control/servercert.pem

These are the correct permissions for that file.

 Thanks for all your help,

Sure.

Just out of curiousity, is LSU using the toaster, or is this just a project
of yours?

 Chris Penn...
 
 1) restarting qmail doesn't stop and start all toaster-related processes,
 only smtp
 2) stopping qmail doesn't always successfully stop all toaster-related
 processes. Sometimes you need to manually kill some of them. When in doubt,
 rebooting will clear them all.
 
 [EMAIL PROTECTED] wrote:
 Sorry for the double post, I needed to resend because the first issue
 didnt have the message included.


 I think the issue is with the certificate.

 When I restart qmail, the message
 supervise: fatal: unable to acquire log/supervise/lock: temporary failure

 starts to appear in terminal.  Unless I logout and log back in, the
 message continues forever.

 This problem is causing pop/imap to fail connection and the apache is
 really slow when resolving page.

 I appear to be able to send my self emails and send emails out through
 squirrel mail, but in case there is an issue, please cc me at
 [EMAIL PROTECTED]

 Any advice is welcome.

 Thanks in advance,

 Chris Penn


 I have a Centos 5 qmailtoaster as described here:
 http://wiki.qmailtoaster.com/index.php/CentOS_5_QmailToaster_Install


 When I restart qmail with qmailctl (via stop, start) I am getting this
 error.
 supervise: fatal: unable to acquire log/supervise/lock: temporary failure

 over and over.

 On thursday, I did two things.
 I created a new tls cert and servercert.pem, self signed.

 I upgraded the qmailtoaster using qtp-newmodel, which in turn upgrade clam
 to .93.

 the way I created a new cert is as follows:

 openssl genrsa -des3 -rand file1:file2:file3:file4:file5 -out server.key
 1024
 openssl req -new -key server.key -out server.csr
 openssl x509 -req -days 3600 -in server.csr -signkey server.key -out
 server.crt
 cat /etc/pki/tls/private/server.key server.crt 
 /var/qmail/control/servercert.pem
 chown root:vchkpw /var/qmail/control/servercert.pem
 chmod 640 /var/qmail/control/servercert.pem

 
 


-- 
-Eric 'shubes'

-
 QmailToaster hosted by: VR Hosted http://www.vr.org
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [qmailtoaster] learn-spam.pl

2008-07-06 Thread Jon Ernster

Eric Shubert wrote:

Jon Ernster wrote:
  

Figured I'd share something I wrote that others here might use since
many of you have shared or helped me out as well.

I wrote this because when I go on vacation I usually shut down the
laptop that has my mail rules which sends all my spam to the spam
folder.  By the time I get back the shell script that I have that runs
on a daily basis (courtesy of Jake Vickers) gives this error because
there are too many spam files:

/root/learn-spam: /usr/bin/sa-learn: /usr/bin/perl: bad interpreter:
Argument list too long
/root/learn-spam: line 10: /bin/rm: Argument list too long

So I just wrote this to process the files individually.  Not the fastest
script in the world (because of SpamAssassin, not becaues of my code,
obviously) ;), but it works.

J.



#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Std;

#~ $Id: learn-spam.pl 15 2008-07-03 17:27:09Z jernster $

my %opts = ();

getopts( 'd:u:', \%opts );

my ( $domain, $user ) = @opts{ qw( d u ) };

my $usage =EOF;
Usage:

   $0 -d example.com -u user

EOF

die $usage unless ( $domain  $user );

my $dir = /home/vpopmail/domains/$domain/$user/Maildir/cur;
my $starttime = time;
my $count = 0;

opendir(DIR, $dir);
my @files = readdir(DIR);
close(DIR);

foreach my $file ( @files )
{
   if ( $file =~ /^\./ )
   {
  next;

   }
   else
   {
  my $fpfile = $dir/$file;

  $count++;

  print Learning SPAM - $file\n;
  
  system(/usr/bin/sa-learn --spam $fpfile);


  print Deleting $file\n;

  unlink($fpfile);

   }

}

print Syncing databases...\n;
system(/usr/bin/sa-learn --sync);

print De-linting files...\n;
system(/usr/bin/spamassassin --lint);

system(chown vpopmail:vchkpw /home/vpopmail/.spamassassin/*);

system(/usr/bin/qmail-spam restart);

print Done!\n;

my $duration = time - $starttime;

print \nTotal duration: $duration seconds\n;
print Processed $count SPAM files.\n;




Thanks, Jon. I wish we had a little more of this.

Observations:
.) I like the way you've handled parameters
.) Is this learning everything in the user's cur directory as spam? Doesn't
seem appropriate to me
.) all sa-learn and spamassassin commands need to be run as user vpopmail.
How is that happening?
.) qmail-spam is usually in /usr/sbin, not /usr/bin

  

Eric,

I create a user named spam and I forward everything to that 
user/directory.  You're right that this wouldn't be ideal for someone to 
run this against their personal mail box.  Alternatively this could 
easily be modified to learn email as HAM instead of SPAM.


I just run the script as root - seems to work.

Location is pretty much irrelevant as long as it's some where in the 
PATH as to not have to reference it WITH the full path if necessary.


Appreciate the comments!

Jon


Re: [qmailtoaster] learn-spam.pl

2008-07-06 Thread Eric Shubert
Jon Ernster wrote:
 Eric Shubert wrote:
 Jon Ernster wrote:
   
 Figured I'd share something I wrote that others here might use since
 many of you have shared or helped me out as well.

 I wrote this because when I go on vacation I usually shut down the
 laptop that has my mail rules which sends all my spam to the spam
 folder.  By the time I get back the shell script that I have that runs
 on a daily basis (courtesy of Jake Vickers) gives this error because
 there are too many spam files:

 /root/learn-spam: /usr/bin/sa-learn: /usr/bin/perl: bad interpreter:
 Argument list too long
 /root/learn-spam: line 10: /bin/rm: Argument list too long

 So I just wrote this to process the files individually.  Not the fastest
 script in the world (because of SpamAssassin, not becaues of my code,
 obviously) ;), but it works.

 J.

 

 #!/usr/bin/perl

 use strict;
 use warnings;
 use Getopt::Std;

 #~ $Id: learn-spam.pl 15 2008-07-03 17:27:09Z jernster $

 my %opts = ();

 getopts( 'd:u:', \%opts );

 my ( $domain, $user ) = @opts{ qw( d u ) };

 my $usage =EOF;
 Usage:

$0 -d example.com -u user

 EOF

 die $usage unless ( $domain  $user );

 my $dir = /home/vpopmail/domains/$domain/$user/Maildir/cur;
 my $starttime = time;
 my $count = 0;

 opendir(DIR, $dir);
 my @files = readdir(DIR);
 close(DIR);

 foreach my $file ( @files )
 {
if ( $file =~ /^\./ )
{
   next;

}
else
{
   my $fpfile = $dir/$file;

   $count++;

   print Learning SPAM - $file\n;
   
   system(/usr/bin/sa-learn --spam $fpfile);

   print Deleting $file\n;

   unlink($fpfile);

}

 }

 print Syncing databases...\n;
 system(/usr/bin/sa-learn --sync);

 print De-linting files...\n;
 system(/usr/bin/spamassassin --lint);

 system(chown vpopmail:vchkpw /home/vpopmail/.spamassassin/*);

 system(/usr/bin/qmail-spam restart);

 print Done!\n;

 my $duration = time - $starttime;

 print \nTotal duration: $duration seconds\n;
 print Processed $count SPAM files.\n;


 
 Thanks, Jon. I wish we had a little more of this.

 Observations:
 .) I like the way you've handled parameters
 .) Is this learning everything in the user's cur directory as spam? Doesn't
 seem appropriate to me
 .) all sa-learn and spamassassin commands need to be run as user vpopmail.
 How is that happening?
 .) qmail-spam is usually in /usr/sbin, not /usr/bin

   
 Eric,
 
 I create a user named spam and I forward everything to that
 user/directory.  You're right that this wouldn't be ideal for someone to
 run this against their personal mail box.  Alternatively this could
 easily be modified to learn email as HAM instead of SPAM.
 
 I just run the script as root - seems to work.

It would update root's bayes database ok (the database is created if it
doesn't exist). That's not the same database which is used on incoming mail
though.

 Location is pretty much irrelevant as long as it's some where in the
 PATH as to not have to reference it WITH the full path if necessary.

That's a little confusing to me. If the full path isn't necessary, why
specify one (especially an incorrect one)? This is typically done for
security purposes (in case $PATH is somehow modified).

 Appreciate the comments!
 
 Jon


-- 
-Eric 'shubes'

-
 QmailToaster hosted by: VR Hosted http://www.vr.org
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [qmailtoaster] learn-spam.pl

2008-07-06 Thread Jon Ernster

Eric Shubert wrote:

Jon Ernster wrote:
  

Eric Shubert wrote:


Jon Ernster wrote:
  
  

Figured I'd share something I wrote that others here might use since
many of you have shared or helped me out as well.

I wrote this because when I go on vacation I usually shut down the
laptop that has my mail rules which sends all my spam to the spam
folder.  By the time I get back the shell script that I have that runs
on a daily basis (courtesy of Jake Vickers) gives this error because
there are too many spam files:

/root/learn-spam: /usr/bin/sa-learn: /usr/bin/perl: bad interpreter:
Argument list too long
/root/learn-spam: line 10: /bin/rm: Argument list too long

So I just wrote this to process the files individually.  Not the fastest
script in the world (because of SpamAssassin, not becaues of my code,
obviously) ;), but it works.

J.



#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Std;

#~ $Id: learn-spam.pl 15 2008-07-03 17:27:09Z jernster $

my %opts = ();

getopts( 'd:u:', \%opts );

my ( $domain, $user ) = @opts{ qw( d u ) };

my $usage =EOF;
Usage:

   $0 -d example.com -u user

EOF

die $usage unless ( $domain  $user );

my $dir = /home/vpopmail/domains/$domain/$user/Maildir/cur;
my $starttime = time;
my $count = 0;

opendir(DIR, $dir);
my @files = readdir(DIR);
close(DIR);

foreach my $file ( @files )
{
   if ( $file =~ /^\./ )
   {
  next;

   }
   else
   {
  my $fpfile = $dir/$file;

  $count++;

  print Learning SPAM - $file\n;
  
  system(/usr/bin/sa-learn --spam $fpfile);


  print Deleting $file\n;

  unlink($fpfile);

   }

}

print Syncing databases...\n;
system(/usr/bin/sa-learn --sync);

print De-linting files...\n;
system(/usr/bin/spamassassin --lint);

system(chown vpopmail:vchkpw /home/vpopmail/.spamassassin/*);

system(/usr/bin/qmail-spam restart);

print Done!\n;

my $duration = time - $starttime;

print \nTotal duration: $duration seconds\n;
print Processed $count SPAM files.\n;





Thanks, Jon. I wish we had a little more of this.

Observations:
.) I like the way you've handled parameters
.) Is this learning everything in the user's cur directory as spam? Doesn't
seem appropriate to me
.) all sa-learn and spamassassin commands need to be run as user vpopmail.
How is that happening?
.) qmail-spam is usually in /usr/sbin, not /usr/bin

  
  

Eric,

I create a user named spam and I forward everything to that
user/directory.  You're right that this wouldn't be ideal for someone to
run this against their personal mail box.  Alternatively this could
easily be modified to learn email as HAM instead of SPAM.

I just run the script as root - seems to work.



It would update root's bayes database ok (the database is created if it
doesn't exist). That's not the same database which is used on incoming mail
though.

  

[EMAIL PROTECTED] ~]# perl learn-spam.pl -d dumbfounded.net -u spam
Learning SPAM - 
1215351471.M922793P3482V004AI098D13EC_417.vps.dumbfounded.net,S=2432:2,

Learned tokens from 1 message(s) (1 message(s) examined)
Deleting 
1215351471.M922793P3482V004AI098D13EC_417.vps.dumbfounded.net,S=2432:2,
Learning SPAM - 
1215370267.M407813P30062V004AI098D1994_2.vps.dumbfounded.net,S=2260:2,

Learned tokens from 1 message(s) (1 message(s) examined)
Deleting 
1215370267.M407813P30062V004AI098D1994_2.vps.dumbfounded.net,S=2260:2,
Learning SPAM - 
1215344032.M28632P3482V004AI098D1066_416.vps.dumbfounded.net,S=3416:2,

Learned tokens from 1 message(s) (1 message(s) examined)
Deleting 
1215344032.M28632P3482V004AI098D1066_416.vps.dumbfounded.net,S=3416:2,
Learning SPAM - 
1215381127.M194384P30062V004AI098D1A54_5.vps.dumbfounded.net,S=1986:2,

Learned tokens from 1 message(s) (1 message(s) examined)
Deleting 
1215381127.M194384P30062V004AI098D1A54_5.vps.dumbfounded.net,S=1986:2,
Learning SPAM - 
1215361414.M459353P3482V004AI098D161C_419.vps.dumbfounded.net,S=2887:2,

Learned tokens from 1 message(s) (1 message(s) examined)
Deleting 
1215361414.M459353P3482V004AI098D161C_419.vps.dumbfounded.net,S=2887:2,
Learning SPAM - 
1215366247.M890863P30062V004AI098D1972_0.vps.dumbfounded.net,S=20120:2,

Learned tokens from 1 message(s) (1 message(s) examined)
Deleting 
1215366247.M890863P30062V004AI098D1972_0.vps.dumbfounded.net,S=20120:2,
Learning SPAM - 
1215343789.M956277P3482V004AI098D083E_415.vps.dumbfounded.net,S=3323:2,

Learned tokens from 1 message(s) (1 message(s) examined)
Deleting 
1215343789.M956277P3482V004AI098D083E_415.vps.dumbfounded.net,S=3323:2,
Learning SPAM - 
1215336171.M990235P3482V004AI098D105C_414.vps.dumbfounded.net,S=2384:2,

Learned tokens from 1 message(s) (1 message(s) examined)
Deleting 

Re: [qmailtoaster] learn-spam.pl

2008-07-06 Thread Eric Shubert
Jon Ernster wrote:
 Eric Shubert wrote:
 Jon Ernster wrote:
   
 Eric Shubert wrote:
 
 Jon Ernster wrote:
   
   
 Figured I'd share something I wrote that others here might use since
 many of you have shared or helped me out as well.

 I wrote this because when I go on vacation I usually shut down the
 laptop that has my mail rules which sends all my spam to the spam
 folder.  By the time I get back the shell script that I have that runs
 on a daily basis (courtesy of Jake Vickers) gives this error because
 there are too many spam files:

 /root/learn-spam: /usr/bin/sa-learn: /usr/bin/perl: bad interpreter:
 Argument list too long
 /root/learn-spam: line 10: /bin/rm: Argument list too long

 So I just wrote this to process the files individually.  Not the fastest
 script in the world (because of SpamAssassin, not becaues of my code,
 obviously) ;), but it works.

 J.

 

 #!/usr/bin/perl

 use strict;
 use warnings;
 use Getopt::Std;

 #~ $Id: learn-spam.pl 15 2008-07-03 17:27:09Z jernster $

 my %opts = ();

 getopts( 'd:u:', \%opts );

 my ( $domain, $user ) = @opts{ qw( d u ) };

 my $usage =EOF;
 Usage:

$0 -d example.com -u user

 EOF

 die $usage unless ( $domain  $user );

 my $dir = /home/vpopmail/domains/$domain/$user/Maildir/cur;
 my $starttime = time;
 my $count = 0;

 opendir(DIR, $dir);
 my @files = readdir(DIR);
 close(DIR);

 foreach my $file ( @files )
 {
if ( $file =~ /^\./ )
{
   next;

}
else
{
   my $fpfile = $dir/$file;

   $count++;

   print Learning SPAM - $file\n;
   
   system(/usr/bin/sa-learn --spam $fpfile);

   print Deleting $file\n;

   unlink($fpfile);

}

 }

 print Syncing databases...\n;
 system(/usr/bin/sa-learn --sync);

 print De-linting files...\n;
 system(/usr/bin/spamassassin --lint);

 system(chown vpopmail:vchkpw /home/vpopmail/.spamassassin/*);

 system(/usr/bin/qmail-spam restart);

 print Done!\n;

 my $duration = time - $starttime;

 print \nTotal duration: $duration seconds\n;
 print Processed $count SPAM files.\n;


 
 
 Thanks, Jon. I wish we had a little more of this.

 Observations:
 .) I like the way you've handled parameters
 .) Is this learning everything in the user's cur directory as spam? Doesn't
 seem appropriate to me
 .) all sa-learn and spamassassin commands need to be run as user vpopmail.
 How is that happening?
 .) qmail-spam is usually in /usr/sbin, not /usr/bin

   
   
 Eric,

 I create a user named spam and I forward everything to that
 user/directory.  You're right that this wouldn't be ideal for someone to
 run this against their personal mail box.  Alternatively this could
 easily be modified to learn email as HAM instead of SPAM.

 I just run the script as root - seems to work.
 

 It would update root's bayes database ok (the database is created if it
 doesn't exist). That's not the same database which is used on incoming mail
 though.

   
 [EMAIL PROTECTED] ~]# perl learn-spam.pl -d dumbfounded.net -u spam
 Learning SPAM -
 1215351471.M922793P3482V004AI098D13EC_417.vps.dumbfounded.net,S=2432:2,
 Learned tokens from 1 message(s) (1 message(s) examined)
 Deleting
 1215351471.M922793P3482V004AI098D13EC_417.vps.dumbfounded.net,S=2432:2,
 Learning SPAM -
 1215370267.M407813P30062V004AI098D1994_2.vps.dumbfounded.net,S=2260:2,
 Learned tokens from 1 message(s) (1 message(s) examined)
 Deleting
 1215370267.M407813P30062V004AI098D1994_2.vps.dumbfounded.net,S=2260:2,
 Learning SPAM -
 1215344032.M28632P3482V004AI098D1066_416.vps.dumbfounded.net,S=3416:2,
 Learned tokens from 1 message(s) (1 message(s) examined)
 Deleting
 1215344032.M28632P3482V004AI098D1066_416.vps.dumbfounded.net,S=3416:2,
 Learning SPAM -
 1215381127.M194384P30062V004AI098D1A54_5.vps.dumbfounded.net,S=1986:2,
 Learned tokens from 1 message(s) (1 message(s) examined)
 Deleting
 1215381127.M194384P30062V004AI098D1A54_5.vps.dumbfounded.net,S=1986:2,
 Learning SPAM -
 1215361414.M459353P3482V004AI098D161C_419.vps.dumbfounded.net,S=2887:2,
 Learned tokens from 1 message(s) (1 message(s) examined)
 Deleting
 1215361414.M459353P3482V004AI098D161C_419.vps.dumbfounded.net,S=2887:2,
 Learning SPAM -
 1215366247.M890863P30062V004AI098D1972_0.vps.dumbfounded.net,S=20120:2,
 Learned tokens from 1 message(s) (1 message(s) examined)
 Deleting
 1215366247.M890863P30062V004AI098D1972_0.vps.dumbfounded.net,S=20120:2,
 Learning SPAM -
 1215343789.M956277P3482V004AI098D083E_415.vps.dumbfounded.net,S=3323:2,
 Learned tokens from 1 message(s) (1 message(s) examined)
 Deleting
 1215343789.M956277P3482V004AI098D083E_415.vps.dumbfounded.net,S=3323:2,
 Learning SPAM -
 1215336171.M990235P3482V004AI098D105C_414.vps.dumbfounded.net,S=2384:2,
 Learned tokens from 

[qmailtoaster] new clamav package

2008-07-06 Thread Erik A. Espinoza
Greetings,

I have updated the website with the new clamav package.

If you are using a version of ClamAV prior to 0.93, please ensure you
remove that package BEFORE executing the rpmbuild. If this is not
done, it will cause a circular dependency as you attempt to upgrade.

Thanks,
Erik

-
 QmailToaster hosted by: VR Hosted http://www.vr.org
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [qmailtoaster] learn-spam.pl

2008-07-06 Thread Jon Ernster

Eric Shubert wrote:

Jon Ernster wrote:
  

Eric Shubert wrote:


Jon Ernster wrote:
  
  

Eric Shubert wrote:



Jon Ernster wrote:
  
  
  

Figured I'd share something I wrote that others here might use since
many of you have shared or helped me out as well.

I wrote this because when I go on vacation I usually shut down the
laptop that has my mail rules which sends all my spam to the spam
folder.  By the time I get back the shell script that I have that runs
on a daily basis (courtesy of Jake Vickers) gives this error because
there are too many spam files:

/root/learn-spam: /usr/bin/sa-learn: /usr/bin/perl: bad interpreter:
Argument list too long
/root/learn-spam: line 10: /bin/rm: Argument list too long

So I just wrote this to process the files individually.  Not the fastest
script in the world (because of SpamAssassin, not becaues of my code,
obviously) ;), but it works.

J.



#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Std;

#~ $Id: learn-spam.pl 15 2008-07-03 17:27:09Z jernster $

my %opts = ();

getopts( 'd:u:', \%opts );

my ( $domain, $user ) = @opts{ qw( d u ) };

my $usage =EOF;
Usage:

   $0 -d example.com -u user

EOF

die $usage unless ( $domain  $user );

my $dir = /home/vpopmail/domains/$domain/$user/Maildir/cur;
my $starttime = time;
my $count = 0;

opendir(DIR, $dir);
my @files = readdir(DIR);
close(DIR);

foreach my $file ( @files )
{
   if ( $file =~ /^\./ )
   {
  next;

   }
   else
   {
  my $fpfile = $dir/$file;

  $count++;

  print Learning SPAM - $file\n;
  
  system(/usr/bin/sa-learn --spam $fpfile);


  print Deleting $file\n;

  unlink($fpfile);

   }

}

print Syncing databases...\n;
system(/usr/bin/sa-learn --sync);

print De-linting files...\n;
system(/usr/bin/spamassassin --lint);

system(chown vpopmail:vchkpw /home/vpopmail/.spamassassin/*);

system(/usr/bin/qmail-spam restart);

print Done!\n;

my $duration = time - $starttime;

print \nTotal duration: $duration seconds\n;
print Processed $count SPAM files.\n;






Thanks, Jon. I wish we had a little more of this.

Observations:
.) I like the way you've handled parameters
.) Is this learning everything in the user's cur directory as spam? Doesn't
seem appropriate to me
.) all sa-learn and spamassassin commands need to be run as user vpopmail.
How is that happening?
.) qmail-spam is usually in /usr/sbin, not /usr/bin

  
  
  

Eric,

I create a user named spam and I forward everything to that
user/directory.  You're right that this wouldn't be ideal for someone to
run this against their personal mail box.  Alternatively this could
easily be modified to learn email as HAM instead of SPAM.

I just run the script as root - seems to work.



It would update root's bayes database ok (the database is created if it
doesn't exist). That's not the same database which is used on incoming mail
though.

  
  

[EMAIL PROTECTED] ~]# perl learn-spam.pl -d dumbfounded.net -u spam
Learning SPAM -
1215351471.M922793P3482V004AI098D13EC_417.vps.dumbfounded.net,S=2432:2,
Learned tokens from 1 message(s) (1 message(s) examined)
Deleting
1215351471.M922793P3482V004AI098D13EC_417.vps.dumbfounded.net,S=2432:2,
Learning SPAM -
1215370267.M407813P30062V004AI098D1994_2.vps.dumbfounded.net,S=2260:2,
Learned tokens from 1 message(s) (1 message(s) examined)
Deleting
1215370267.M407813P30062V004AI098D1994_2.vps.dumbfounded.net,S=2260:2,
Learning SPAM -
1215344032.M28632P3482V004AI098D1066_416.vps.dumbfounded.net,S=3416:2,
Learned tokens from 1 message(s) (1 message(s) examined)
Deleting
1215344032.M28632P3482V004AI098D1066_416.vps.dumbfounded.net,S=3416:2,
Learning SPAM -
1215381127.M194384P30062V004AI098D1A54_5.vps.dumbfounded.net,S=1986:2,
Learned tokens from 1 message(s) (1 message(s) examined)
Deleting
1215381127.M194384P30062V004AI098D1A54_5.vps.dumbfounded.net,S=1986:2,
Learning SPAM -
1215361414.M459353P3482V004AI098D161C_419.vps.dumbfounded.net,S=2887:2,
Learned tokens from 1 message(s) (1 message(s) examined)
Deleting
1215361414.M459353P3482V004AI098D161C_419.vps.dumbfounded.net,S=2887:2,
Learning SPAM -
1215366247.M890863P30062V004AI098D1972_0.vps.dumbfounded.net,S=20120:2,
Learned tokens from 1 message(s) (1 message(s) examined)
Deleting
1215366247.M890863P30062V004AI098D1972_0.vps.dumbfounded.net,S=20120:2,
Learning SPAM -
1215343789.M956277P3482V004AI098D083E_415.vps.dumbfounded.net,S=3323:2,
Learned tokens from 1 message(s) (1 message(s) examined)
Deleting
1215343789.M956277P3482V004AI098D083E_415.vps.dumbfounded.net,S=3323:2,
Learning SPAM -
1215336171.M990235P3482V004AI098D105C_414.vps.dumbfounded.net,S=2384:2,
Learned tokens from 1 message(s) (1