hello,
my name is becki and i'm using dbmail successfully since a couple of years.
so really thanks for this nice piece of software which runs stable on my
SuSE Linux server 9.3 and 10.2 without any issues so far.
just recently i browsed through the mailing list and dbmail wikki to
look for news and updates, etc ...
then i found a couple of messages regarding the missing mail quota
features which i also sort of missed a few times.
anyway ... because of that missing feature i programmed a tiny php shell
script a while ago.
the script runs as a daily cron job and simply browses through every
user in the dbmail users table, then runs the 'dbmail-adduser s' command
on the CLI and checks the output via a regular expression. if a
percentage quota is met then the script sends out a notify to the mail
user account.
the script is really nothing fancy but does its job pretty well on my
suse box since a few years.
the script needs PHP >= 4.3.0
and ONLY supports the dbmail branch of 1.2.x
on my system it runs stable with dbmail 1.2.12.1
on top of the script there's a config section to setup your mysql info
like, user name, password, table, quote percentage, etc ...
line 129 - 162 defines the message which will be send to the user and
someone is more than welcome to modify this message to their specific need.
like i said earlier ... really nothing too fancy ... but it might
probably help someone out there!
so i would like to contribute this script to the dbmail wikki section if
that is okay with you.
if you have any questions or whatsoever then please don't hesitate and
get in contact with me.
thanks a lot for your time & wish you a nice day
with best regards
becki beckmann
### SCRIPT START ###
#!/usr/bin/php -Cq
<?php
/*
// Becki's Mail Quota Script
// http://beckspaced.com
// [EMAIL PROTECTED]
//
// Checks quota of mailbox address via shell
// returns $percent usage of specified mailbox
//
*/
//error_reporting(E_ALL);
// CONFIGS
$db_host = "localhost";
$db_user = "dbmailuser"; // mysql user with access to db dbmail
$db_pass = "secretpassword"; // mysql user password
$db_name = "dbmail"; // name of dbmail database
$db_table = "users"; // name of dbmail users table
$quota_limit = 85; // quota limit in % - once this is reached a notify
mail is send to the user
// CONFIGS
// PRIVATE
$mysql_connect_id = false;
// FUNCTIONS
function connect_mysql()
{
global $db_host, $db_name, $db_pass, $db_user, $mysql_connect_id;
$mysql_connect_id = mysql_connect($db_host, $db_user, $db_pass);
if (!$mysql_connect_id) return false;
if (!mysql_select_db($db_name, $mysql_connect_id)) return false;
return true;
}
function get_mailaccounts()
{
global $db_table, $mysql_connect_id;
if (!$mysql_connect_id) connect_mysql();
$query = "SELECT * FROM " . $db_table;
$result = mysql_query($query, $mysql_connect_id);
while ($row = mysql_fetch_assoc($result))
{
$mailaccounts[] = $row['userid'];
}
return $mailaccounts;
}
// FUNCTIONS
// REGEX
$href_regex = "Max\. mailboxsize:"; // start
$href_regex .="\s+"; // zero or more whitespace
$href_regex .= "("; // start capture
$href_regex .= "[0-9]{1,2}"; // 1 or 2 digits
$href_regex .= "\."; // the decimal point
$href_regex .= "[0-9]{2}"; // the decimal digit
$href_regex .= ")"; // end capture
$href_regex .="\s+"; // zero or more whitespace
$href_regex .= "MB"; // the percentag sign
$href_regex .="\s*"; // one or more whitespace
$href_regex .= "Quotum used"; // start
$href_regex .="\s+"; // zero or more whitespace
$href_regex .=":"; // zero or more whitespace
$href_regex .="\s+"; // zero or more whitespace
$href_regex .= "("; // start capture
$href_regex .= "[0-9]{1,2}"; // 1 or 2 digits
$href_regex .= "\."; // the decimal point
$href_regex .= "[0-9]{2}"; // the decimal digit
$href_regex .= ")"; // end capture
$href_regex .="\s+"; // zero or more whitespace
$href_regex .= "MB"; // the percentag sign
$href_regex .="\s*"; // one or more whitespace
$href_regex .= "\("; // start Klammer (
$href_regex .= "("; // start capture
$href_regex .= "[0-9]{1,3}"; // 1 or 2 digits
$href_regex .= "\."; // the decimal point
$href_regex .= "[0-9]{1,2}"; // the decimal digit 1 or 2 digits
$href_regex .= ")"; // end capture
$href_regex .= "%"; // the percentag sign
$href_regex .= "\)"; // end klammer )
$regex = "/"; // regex start delimiter
$regex .= $href_regex; //
$regex .= "/"; // regex end delimiter
$regex .= "i"; // Pattern Modifier - makes regex case insensitive
$regex .= "s"; // Pattern Modifier - makes a dot metacharater in the pattern
// match all characters, including newlines
$regex .= "U"; // Pattern Modifier - makes the regex ungready
// REGEX
$mailaccounts = get_mailaccounts();
foreach ($mailaccounts as $account) {
$handle = popen('/usr/local/sbin/dbmail-adduser s ' . $account . '
2>&1', 'r');
$contents = '';
while (!feof($handle))
{
$contents .= fread($handle, 2096);
}
pclose($handle);
if (preg_match_all($regex, $contents, $percentage)) {
if($percentage[3][0] > $quota_limit) {
print("Mailbox: " . $account . "\n");
print("Max. Mailbox Size: " . $percentage[1][0] . " MB\n");
print("Current Mailbox Usage: " . $percentage[2][0] . " MB\n");
print("Current Mailbox Quota: " . $percentage[3][0] . " %\n\n");
$subject = $percentage[3][0] . "% MAILBOX QUOTA LIMIT
NOTIFICATION!";
$message = "Hello " . $account . ",\n\n";
$message .= "Your MailBox Quota has reached a CRITICAL level
of " . $percentage[3][0] . "%!!!\n\n";
$message .= "Please FREE some MailBox Storage Space by
deleting some E-Mails from your Inbox!\n\n";
$message .= "If you are using the WebMail Client at
http://webmail.yourdomain.com please follow the instructions below:\n\n";
$message .= "- Delete some old E-Mails from your Inbox!\n";
$message .= "- Some people have enabled the option HIDE
DELETED in their settings!\n";
$message .= "- This means you will not see any deleted old
emails which still use up your MailBox Storage Space!\n";
$message .= "- Click SHOW DELETED in the upper right corner
in your INBOX to view all deleted E-Mails!\n";
$message .= "- To finally REMOVE those deleted E-Mails click
the PURGE DELETED link in the upper right corner in the INBOX.\n";
$message .= "- Please remember to regularly click the PURGE
DELETED link to FREE UP some MailBox Storage Space!\n";
$message .= "- Check your WebMail FOLDERS and delete
unnecessary old files!\n";
$message .= "- Check some of the old SENT-MAIL folders,
where outgoing E-Mails have been automatically saved as a copy by the
WebMail Client, and delete as needed!\n\n";
$message .= "ALWAYS remember to clean up your MailBox
Storage regularly to FREE UP some storage space!\n";
$message .= "BE AWARE - With a FULL MailBox you are UNABLE
to receive ANY NEW incoming E-MAILS!!\n\n";
$message .= "This is only a notification E-mail - Please do
not reply!\n\n";
$message .= "THANK YOU & have a nice day\n\n";
$message .= "Best regards\n";
$message .= "Your John Doe\n\n\n";
$message .= "-----------------------\n";
$message .= "YOUR MAILBOX QUOTA DETAILS:\n";
$message .= "-----------------------\n";
$message .= "Account: " . $account . "\n";
$message .= "Max. MailBox Size: " . $percentage[1][0] . " MB\n";
$message .= "Current MailBox Usage: " . $percentage[2][0] .
" MB\n";
$message .= "Current MailBox Quota: " . $percentage[3][0] .
" %\n";
$message .= "-----------------------\n\n\n";
$message .= "If you are experiencing any problems or
whatsoever then please contact us as soon as possible at
[EMAIL PROTECTED]";
$message .= "-----------------------\n";
$message .= date("F j, Y, g:i a") . "\n";
$headers = "From: Postmaster <[EMAIL PROTECTED]>\n";
$headers .= "Reply-To: Postmaster
<[EMAIL PROTECTED]>\n";
$headers .= "X-Mailer: PHP/" . phpversion() . "\n";
mail($account, $subject, $message, $headers);
echo "SEND EMAIL TO USER " . $account . " - SUCCESS!\n\n";
}
}
else
{
print("User: " . $account . " - No Match REGEX!\n\n");
}
}
?>
### SCRIPT END ###
--
Beckspaced.com - WebDesign, Hosting & Solutions
CEO Flederer Ralf
Marienplatz 9
97353 Wiesentheid
Germany
Phone: 09383-425
P.O. Box 15
Thongsala
84280 Koh Phangan
Suratthani / Thailand
Phone: 077-377 733
Mobile: 087-2828826
----------------------------------------------
Optimism is only a lack of information!
----------------------------------------------
WebDesign & Hosting - http://beckspaced.com - Are You Beckspaced?
Phangan Independent News - http://kohphangannews.org - The Awful Truth!
_______________________________________________
DBmail mailing list
[email protected]
https://mailman.fastxs.nl/mailman/listinfo/dbmail