[plug] mailclean.pl
Patrick Tehvand
Patrick at perthix.net
Fri Jun 7 13:38:47 WST 2002
Has anyone used this perl script before? just want to know what people thought...
#!/usr/bin/perl
#Copyright (C) 1999 Mark Wagner
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
$sendmail = "/usr/sbin/sendmail";
opendir(homedir, "/home");
foreach $user (readdir(homedir)) {
local $onecount;
local $fivecount;
local $zerocount;
$userdir = "/home/" . $user;
if (-d $userdir && $user ne "." && $user ne ".."){
# Edit the following line if neccessary to properly point it at
# the users mail directory that you want mailclean to look at
$maildir = $userdir . "/Maildir/cur";
if ( -e $maildir) {
opendir(curmaildir,$maildir);
while ($email = readdir(curmaildir)){
$email = $maildir . "/" . $email;
if (-f $email && -M $email > 30) {
if (! -l $email) {
$zerocount += 1;}
} elsif (-f $email && -M $email > 29 && -M $email < 30) {
$onecount += 1;
} elsif (-f $email && -M $email > 25 && -M $email < 26) {
$fivecount += 1;
}
}
closedir(curmaildir);
}
}
if ($zerocount > 0) {
&sendemail(30,$zerocount)
&removethirty ($maildir) }
if ($fivecount > 0) {
&sendemail(25,$fivecount)}
if ($onecount > 0) {
&sendemail(29,$onecount)}
}
closedir(homedir);
sub sendemail {
open(SENDMAIL, "|$sendmail $user");
# Customize this section for your individual needs
# This is the message that gets sent to the user
print SENDMAIL <<EOH;
From: Cleaner Daemon <sysadmin\@cybertrails.com>
Subject: Storing Email on the Mail Server
EOH
if ($_[0] =~ 30) {
print SENDMAIL <<EOH;
$_[1] messages are over 30 days old.
$_[1] messages have been deleted for residing on our
mail server for over 30 days.
EOH
}elsif ($_[0] =~ 29){
print SENDMAIL <<EOH;
$_[1] messages are 29 days old.
These $_[1] messages will be deleted in 1 day, unless they
are removed from our server.
EOH
}elsif ($_[0] =~ 25){
print SENDMAIL <<EOH;
$_[1] messages are 25 days old.
This $_[1] messages will be deleted in 5 days, unless they
are removed from our server.
EOH
}
print SENDMAIL <<EOH;
If you need help removing older messages or don't understand
why there are messages being left on the server.
Please Call Technical Support at 1-800-924-5298 or in Phoenix
call 602-861-4755
Thank you for your cooperation
Cyber Trails System Administrators
EOH
close(SENDMAIL);
}
sub removethirty {
opendir(curmaildir,$_[0]);
while ($email = readdir(curmaildir)){
$email = $_[0] . "/" . $email;
if (-f $email && -M $email > 30) {
if (! -l $email) {
unlink ($email);}
}
}
closedir(curmaildir);
}
Patrick Tehvand
.-.
/v\ L I N U X
// \\ >Phear the Penguin<
/( )\
^^-^^
_____________________________________________________________________
This e-mail is brought to you 100% virus free by Perth iX using MessageLabs SkyScan scanning service. For more information please call Perth iX on +61 8 92166600 or email info at perthix.net.
More information about the plug
mailing list