The server’s upward spiral for system load continued; we’re currently examining the qpopper process. What it does is copy the mailbox file over to a temporary place, parse the copy, and then if the user leaves mail on the server copies it back. Some of the users have over 20MB of saved mail. People, we’re not gmail here. So I’ve been writing a perl script to weed out some older files; I’m letting them keep 14 days of stuff, and only checking files over a certain size.
Here’s the completed script; obviously I’m not a perl master.
#!/usr/local/bin/perl
# need this to run through the mailboxes.
use Mail::Box::Manager;
# this size is the maximum we allow them to grow to
# let's start with 5 MB
my $maximumsize=5*1024*1024;
# this is the maximum age of a file in a lage mailbox;
# start with 28 days, measured in seconds
my $maximumage=14*24*3600;
my $now=time();
# get the list of all the mailboxes on the system.
my @mailboxes=;
my $mgr=Mail::Box::Manager->new;
my $worklog="";
foreach $mailbox (@mailboxes) {
# if the message ends in 'old' then skip it
next if /\.old$/;
if ( -s $mailbox > $maximumsize ) {
cleanout ($mailbox );
}
}
print $worklog;
sub cleanout {
my ( $checkme ) = @_;
`cp -f $checkme $checkme.old`;
# if we don't change the file we don't need to rewrite it
my $writeme = false;
my ( $imfrom, $imto, $imon );
$workdir .= "Now opening $checkme\n";
my $folder = $mgr->open(folder=>$checkme, access=>"rw");
foreach $msg ($folder->messages) {
my $howlongago = $now-$msg->timestamp;
if ( $howlongago > $maximumage ) {
my Mail::Message::Head $head = $msg->head;
$imfrom=$head->get('from');
$imto=$head->get('to');
$imon=$head->get('Date');
$workdir .= "Removing message from $imfrom to $imto on $imon\n";
$msg->delete;
$writeme=true;
}
}
if ( $writeme ) {
$folder->write;
$workdir .= "writing folder\n";
}
}