Notify Users by Mail if Mailbox is over a specific size
 
I wrote a script for a server running confixx to notify users, if theyr mailbox is over (e.g.) 10 mb.
It's a php script that is used as a shellscript in a way. You can execute it like this: php clean.php (php must be installed, run as root).
You can also add this script to your cronjobs, just add "php /path/to/clean.php".
The section "CONFIGURATION" has to be configured by you manually.

clean.php:
<?php
// This file lets you remind users which have full mailboxes (over a specific amount of mb).
// Lucas @ Oct. 2005
//*******************************************************************************************//
// CONFIGURATION                                       //
//*******************************************************************************************//
// GENERAL
$from_email = "e@mail.com"; // Who is the sender of the alert emails?
$to_email = "e@mail.com"; // To who does it send administrator messages?
// E-MAIL CONFIGURATION
echo "Starting Cleanup Operationn"; // Script-Launching Message
$virtusertable = "/etc/mail/virtusertable"; // Location of virtusertable file in filesystem
$mailboxlocation = "/var/mail/"; // Location of mailboxes in filesystem
$maxmailboxsize = 10485760; // Max Size of Mailbox (bytes) [1 MB = 1048576 bytes]
$mail_subject = "Your mailbox is full"; // The subject of the Mail
$mail_msg = "Your mailbox is full.nPlease clean it!"; // The body of the Mail
//*******************************************************************************************//
// E-MAIL CLEANING / REMINDING OPERATIONS                          //
//*******************************************************************************************//
function BytesToMb($bytes) {
if($bytes > 0) {
$bytes = $bytes/1024/1024;
return round($bytes,1);
}
else {
return $bytes;
}
}
// GET E-MAIL ACCOUTNS //
$file = file($virtusertable);
$counter = 0;
for($i=0;$i<sizeof($file);$i++) {
// get the current line ---------------------------------------------------------------------
$currentline = substr($file[$i],0,-1);
$currentlinearray = explode("t",$currentline);
// if its just an email forwarder, continue -------------------------------------------------
if(strpos($currentlinearray[1],"@")==true) {
continue;
}
// check if already exists ------------------------------------------------------------------
$continue = "no";
for($a=0;$a<sizeof($emailaccounts);$a++) {
if($currentlinearray[1] == $emailaccounts[$a][0]) {
$continue = "yes";
}
}
if($continue == "yes") {
continue;
}
// if its a catchall, make info@ ------------------------------------------------------------
if(substr($currentlinearray[0],0,1) == "@") {
$currentlinearray[0] = "info".$currentlinearray[0];
}
// get size of the current mailbox ----------------------------------------------------------
$currentlinearray[2] = @filesize($mailboxlocation.$currentlinearray[1]);
// write into array -------------------------------------------------------------------------
$emailaccounts[$counter][0] = $currentlinearray[1]; //Postfachname
$emailaccounts[$counter][1] = $currentlinearray[0]; //E-Mail Adresse dazu
$emailaccounts[$counter][2] = $currentlinearray[2]; //Verwendeter Speicherplatz
$counter++;
}
for($i=0;$i<sizeof($emailaccounts);$i++) {
echo $emailaccounts[$i][0]." (".$emailaccounts[$i][2].") ------> ".$emailaccounts[$i][1];
if($emailaccounts[$i][2]>$maxmailboxsize) {
//Send E-Mail
mail($emailaccounts[$i][1],$mail_subject,$mail_msg,"From: ".$from_email);
}
echo "n";
}
//************************************************************************************************//
//                                                //
//************************************************************************************************//
?>
 
admin / Oct 31, 2004
   
 
 
Login: 
Pass: 
 
 
     
     
2004 - 2019 / lookass.ch
makememad@lookass.ch