From: John H. <web...@ew...> - 2006-04-24 15:41:37
|
Ravi Gehlot wrote: > > I have SpamAssasin set up for all clients but I noticed that no one is=20 > deleting their spams from their spam folder. How do I configure=20 > spamassasin so after a certain amount of time all spam gets deleted=20 > from all accounts? Just like Bulk Mail at mail.yahoo.com. They delete=20 > all spams after a period of time if the user doesn=92t delete it on due= =20 > time. > > Thanks. > > !DSPAM:444aa89c204911848244728! Below is not for the faint of heart and for those that have some=20 knowledge of scripting. This is not a SpamAssassin system, but instead=20 scripts which will run from any 'nix server with perl. You'll need to=20 understand what is happening within at least the second script and=20 adjust paths to suit your system. Here's a script that does the actual mail deletion called rmmail.pl. -------------------------------------- #!/usr/bin/perl # print "Starting perl script"; use HTTP::Date; my $days =3D $ARGV[0]; $days =3D 30 if ! defined $days || $days < 1 ; my $mfile =3D $ARGV[1]; my $past =3D time() - $days * 24 * 60 * 60 ; my $skip =3D 0; open M , "<$mfile" || die("cant open mail file $mfile"); while(<M>){ my $line =3D $_; if( /^From / ){ chmop ; my ($f,$e,$d) =3D split(/ /,$_,3); chomp $d; $d =3D~ s/^ *//; $d =3D~ s/-\d\d\d\d$//; ### The next four commented out lines can be useful for debugging during=20 setup of these scripts. # print $d . "\n"; my $t =3D str2time( $d ); # print $t . "\n" ; if( $t < $past ) { # print "Old mail $d\n"; $skip =3D 1 ; } else { # print "doing skip 0\n"; $skip =3D 0; } } print $line if ! $skip ; } close M; ----------------------------------------------------------- Here's a script that I run which uses the above to maintain a folder=20 named spam in a user's IMAP directory. Spam is stored in IMAP maildir=20 your_spam. Adjust the directory names to suit your situation... adjust=20 the days before deletion.. ---------------------------------------- #!/bin/sh IFS=3D":" grep '[501]' /etc/passwd | cut -d : -f 1,6 | \ while read myuser mydir do if [ -e $mydir/IMAP/spam ]; then ### Set Number of Days Spam is Saved in the your_spam Folder #### SDays=3D4 ### Begin Section to Delete your_spam emails LC=3D$mydir/your_spam.lock MC=3D$mydir/your_spam lockfile -s 10 -r 2 $LC ### /var/tmp is a temp directory which needs to be created to contain=20 the mailfile while ### the work is being done. perl /usr/local/bin/rmmail.pl $SDays $MC > /var/tmp/your_spam && mv -f /var/tmp/your_spam $MC && chown $myuser $MC chmod 600 $MC cd $mydir/IMAP rm -f your_spam.lock && cd / ### And lets send a message that it is done echo "Spam File Maintenance is complete for the user $myuser in=20 directory $mydir" ### Lets give the server a break before moving on to the next mail user. ### Not too important unless you're doing more than one folder and perhap= s ### some spam database cleanup at the same time. sleep 15 fi done exit 0 --------------------------------------------- I run this from a cron each day. It removes mail from the spam box which=20 is older than 4 days. There is also a program called archivemail which can do the same thing. Best, John Hinton |