ispman/bin ispman.warnNearQuotaMailboxes,NONE,1.1

Joerg Delker <[email protected]>
Newsgroups gmane.comp.isp.ispman.cvs
Message-ID <[email protected]>
Update of /cvsroot/ispman/ispman/bin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30713

Added Files:
	ispman.warnNearQuotaMailboxes 
Log Message:
new ispman CLI script provided by Tony Wasson
Warn mailboxes who are near their quota


--- NEW FILE: ispman.warnNearQuotaMailboxes ---
#!/usr/bin/perl
# Warn mailboxes who are near their quota, default is 60%
# Usage: ispman.warnNearQuotaMailboxes -h mailhost.example.com


BEGIN{
   use FindBin; unshift @INC, ($FindBin::Bin , "$FindBin::Bin/../lib", "$FindBin::Bin/../conf");
}

#Customize these 2 lines and the message at the bottom of the script
$mail{smtp} = [qw(mail.example.com)];
$mail{from} = 'CompanyName Email Postmaster <[email protected]>';

require "cyrusadmin.pm";
use ISPMan;
use Mail::Sendmail;
use vars qw($ispman);
$ispman=ISPMan->new();


#Default to 60% of quota
my $percent=60;
my $multiplier=$percent /100;
my $uid_filter="*";
my $users=$ispman->getEntriesAsHashRef($ispman->{'Config'}{'ldapBaseDN'}, "&(objectclass=ispmanDomainUser)(uid=$uid_filter)");


USER: for (keys %$users) {
   @uids=$ispman->as_array($users->{$_}{'uid'});
   #We want the user_example_com uid
   if ($uids[0] =~ /@/) {$uid=$uids[1];}
   else { $uid=$uids[0]; }
   $mailbox=join "", ($mailbox_prefix, $uid);
   @q=$imap->get_quota($mailbox);
   next unless $q[2];
   $threshold=$multiplier * $q[2];
   #print "$uid used: $q[1] thresh: $threshold\n";
   if ($q[1]>=$threshold){
        #Determine mailbox usage in simple xx% value as $percent
        $usage = ($q[1] / $q[2]) * 100;
        ($percent,$trailingjunk)=split(/\./, $usage);

        #Email settings
        @email=$ispman->as_array($users->{$_}{'mailLocalAddress'});
        $mail{to}=$email[0];
        $mail{subject}="MAILBOX $percent% FULL - From YourISP ";
        #Customize here, don't forget escapes amd put it all on one line
        $mail{message}="Your email box is at $percent% of your email quota.\nYour Quota is:  $q[2] kilo bytes\nYou have Used:  $q[1] kilobytes\n\nPlease dump your trash and erase unneeded email. If you need more space, please contact our office at hosting-support\@example.com. There may be an additional charge.\nOnce y our mailbox is full, no more mail will be delivered until some email is erased.\nNOTE: You will receive this alert once a day if your mailbox is in danger of being full.";

        sendmail(%mail) or die $Mail::Sendmail::error;
   }

} 



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.