#!/usr/local/cpanel/3rdparty/bin/perl ############################################################################### # Copyright 2004-2016, Way to the Web Limited # URL: http://www.configserver.com # Email: sales@waytotheweb.com ############################################################################### # # IMPORTANT NOTE: # # # By default this will keep the last 2 days of your incoming mail. # You can change this here: use strict; my $days_to_keep = 2; my $incoming_dir = '/var/spool/MailScanner/incoming'; my $temp_dir = '/var/spool/MailScanner/incoming/SpamAssassin-Temp'; # Standardise the format of the directory name die 'Path for incoming_dir must be absolute' unless $incoming_dir =~ /^\//; $incoming_dir =~ s/\/$//; # Delete trailing slash # Now get the content list for the directory. opendir(QDIR, $incoming_dir) or die "Couldn't read directory $incoming_dir"; # Loop through this list looking for any *directory* which hasn't been # modified in the last $days_to_keep days. # Unfortunately this will do nothing if the filesystem is backed up using tar. while(my $entry = readdir(QDIR)) { next if $entry =~ /^\./; next if $entry eq "SpamAssassin.cache.db"; next if $entry eq "SpamAssassin-Temp"; next if $entry eq "Locks"; $entry = $incoming_dir . '/' . $entry; system("rm -rf $entry") if -d $entry && -M $entry > $days_to_keep; } closedir(QDIR); opendir(TDIR, $temp_dir) or die "Couldn't read directory $temp_dir"; while(my $entry = readdir(TDIR)) { next if $entry =~ /^(\.|\.\.)$/; $entry = $temp_dir . '/' . $entry; unlink $entry if -M $entry > $days_to_keep; } closedir(TDIR);