| Welcome to the Zimbra :: Forums! | |
Welcome, if you would like to post a comment please register.
We also encourage you to explore all things Zimbra with our team and members of the community.
|  | | 
11-20-2006, 02:05 AM
| | Project Contributor | |
Posts: 116
| | Get mailbox size (for create quota warning SMTP script) Hi Everybody.
In order to create a home-made script for warning users before quota limit is reached, I would need a method to query mailbox size in server.
I've evaluated IMAP approach, but it's is very slow cause all code I've found scans full mailbox to get mailbox size.
Is there any other way to get mailbox size without having to scan folders? Perhaps with a direct mysql query... but I don't have datamodel here.
Thanks in advance. | 
11-20-2006, 02:18 AM
| | | Doesn't Zimbra IMAP implementation support "GETQUOTA" ? | 
11-20-2006, 02:40 AM
| | Project Contributor | |
Posts: 116
| | Yes, it's... Quote: |
Originally Posted by Klug Doesn't Zimbra IMAP implementation support "GETQUOTA" ? | Yes, it's... I'm embarrased
I will post php script as soon as possible, since I think it's very useful. | 
11-20-2006, 07:46 AM
| | Project Contributor | |
Posts: 116
| | IMAP login with admin account I've almost finished a PHP script for getting users account.
However, I cannot login with admin user to other mailboxes but admin one.
One approach would be resetting user passwords before login, and then restore, but I think it could be a bit dangerous.
Any suggestion? (zimbra imap server doesn't support adminuser flag).
---- Quote:
$user=$users[$i];
$mbox = imap_open("{localhost:993/imap/ssl/novalidate-cert/user=$user/adminuser=admin}", admin, "mypassword", OP_HALFOPEN);
$quota_values = imap_get_quotaroot($mbox, "INBOX");
if (is_array($quota_values)) {
$storage = $quota_values['STORAGE'];
//echo "Usage:".$storage['usage']."\n";
//echo "Storage:".$storage['limit']."\n";
if ($storage['usage'] > $storage['limit']*0.9)
echo "Storage for user $user over 90%\n";
else
echo "Storage for user $user under 90%\n";
---
| | 
11-20-2006, 10:02 AM
| | Zimbra Employee | |
Posts: 1,434
| | SOAP is *by far* the easiest way Easiest way to do this: Get an admin auth token, then issue the GetInfo SOAP request for each user and look for <used> in the response.
Second-easiest way to do this: Authenticate as the user to IMAP using the admin user/password and AUTH=PLAIN, then issue GETQUOTA. | 
11-20-2006, 10:22 AM
| | Zimbra Employee | |
Posts: 228
| | The easieset approach is to simply use zmprov: Code: $ /opt/zimbra/bin/zmprov gqu localhost
user1@macpro.local 62914560 7703249
spam-sink@macpro.local 0 15168
wiki@macpro.local 0 4996
admin@macpro.local 0 0
ham-sink@macpro.local 0 0
user2@macpro.local 0 0
user3@macpro.local 0 0
user4@macpro.local 0 0 Second column is maximum quote in bytes (0 means unlimited), third column is used quota, in bytes.
This uses the admin GetQuotaUsageRequest soap call. | 
11-20-2006, 10:23 AM
| | Zimbra Employee | |
Posts: 1,434
| | Busted! Yeah, what Roland said. | 
11-21-2006, 01:57 AM
| | Project Contributor | |
Posts: 116
| | Quota warning script. Hi everybody.
I've created a script for quota checking.
This script should be launched by zimbra user and it's "crontable".
It warns everyday when a user reach 90% quota usage, and weekly (on Sunday) when reaching 75%. Please, modify at your own. Quote:
<?php
$users=array();
$user=array();
$return = exec ("zmprov gqu localhost",$users_quota, $status);
for ($i = 1; $i < count($users_quota); $i++)
{
$user['email']=strtok ($users_quota[$i]," ");
$user['max']= strtok (" ");
$user['act']= strtok (" ");
switch ($user['email']) {
case "kuns1kesoy@vectorsf.com":
break;
case "ud2qtlgeld@vectorsf.com":
break;
case "beveg2wn@vectorsf.com":
break;
case "wiki@vectorsf.com":
break;
default:
if ($user['act'] > $user['max']*0.9) {
echo "Storage for user ".$user['email']." over 90%\n";
sendwarning ($user['email'],$user['act'],$user['max'],2);
}
else if ($user['act'] > $user['max']*0.75 && $user['act'] < $user['max']*0.90 ) {
echo "Storage for user ".$user['email']." over 75%\n";
sendwarning ($user['email'],$user['act'],$user['max'],1);
}
}
}
function sendwarning ($email,$usage,$maxquota,$warntype)
{
$dow = date ("D");
$to = $email;
$subject = 'Aviso de utilizacion de cuota de mail';
$headers = 'From: postmaster@vectorsf.com' . "\r\n" .
'Reply-To: postmaster@vectorsf.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if ($warntype == 1 && $dow == "Sun")
$message = "Tu cuota de correo ha superado el 75% de su asignacion.\nTe recomendamos vayas eliminando o archivando los mensajes mas antiguos para evitar problemas de almacenamiento futuros.\nEn estos momentos estas utilizando ".round($usage/1024/1024)." MB de un total de ".round($maxquota/1024/1024)." MB.\n";
else if ($warntype == 2)
$message = "Tu cuota de correo ha superado el 90% de su asignacion.\nTe recomendamos vayas eliminando o archivando los mensajes mas antiguos para evitar problemas de almacenamiento futuros.\nEn estos momentos estas utilizando ".round($usage/1024/1024)." MB de un total de ".round($maxquota/1024/1024)." MB.\n";
else return;
mail($to, $subject, $message, $headers);
}
?>
| | 
11-21-2006, 02:17 AM
| | Zimbra Consultant & Moderator | |
Posts: 20,316
| | Nice one, I'll give it a run later.  Does it also give the users current quota as well as warnings or is it just a warning at the 75% & 90%? Does it email the user or admin or both - sorry about the questions, I'm not much of a coder.
Could you stick this in the wiki if you have time?
__________________
Regards
Bill
| 
11-21-2006, 09:09 AM
| | Partner (VAR/HSP) | |
Posts: 80
| | I wrote another ugly script in bash to do the same thing. I'll also post it on the wiki Code: #!/bin/sh
warn_percentage=85
tmpFile=`mktemp`
zmprov gqu localhost > $tmpFile
while read line ; do
userReport=$line
user=`echo $userReport | cut -f1 -d\ `
max_quota=`echo $userReport | cut -f2 -d\ `
used_quota=`echo $userReport | cut -f3 -d\ `
if [ $max_quota -ne 0 ] ; then
quota_percentage=`echo "scale=1; (($used_quota * 100)/ $max_quota)" | bc`
if [ `echo "$quota_percentage >= $warn_percentage" | bc` -eq 1 ] ; then
max_quota_megs=`echo "scale=1; ($max_quota / 1048576)" | bc`
echo "You are currently using $quota_percentage% of your mailbox quota of $max_quota_megs megabytes" | mail -s \"Quota Warning - $quota_percentage%\" $user
fi
fi
done < $tmpFile
rm -f tmpFile
Last edited by zaf; 11-21-2006 at 09:20 AM..
| | Thread Tools | Search this Thread | | | | | Display Modes | Linear Mode | | Why Join? Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.  |