[imp] mailbox quota
Eero Volotinen
security at jlug.org
Sun Oct 19 02:43:58 PDT 2003
> You should add QUOTA to cabability line of courier imapd settings.
> My quota script works better, that one that you tried to use.
-- snips--
function courierimapd_vpopmail_quota($imp)
{
$quota_html = '';
$imap_admin = $imp['user'];
$imap_passwd = Secret::read(Secret::getKey('imp'), $imp['pass']);
$ip = $imp['server'];
$port = $imp['port'];
if($port != "143") return;
// only imap is supported
//$stream = @imap_open(IMP::serverString(), $imap_admin,
$imap_passwd, OP_HALFOPEN);
$fp = fsockopen($ip,$port);
if (!$fp) {
return;
} else {
$str=@fgets($fp);
fwrite($fp,"a001 login $imap_admin $imap_passwd\r\n");
// login ok
$str=@fgets($fp);
if(strstr($str,"Ok")==FALSE) {
// login failed
return;
}
//echo $str . "<br>";
fwrite($fp,"a001 GETQUOTAROOT INBOX\r\n");
// quotaroot
$str=@fgets($fp);
//echo $str ."<br>";
$str=@fgets($fp);
if(strlen($str) ==0) return;
if(strstr($str,"STORAGE") == FALSE) return;
$quota=sscanf($str,"* QUOTA \"ROOT\" (STORAGE %d %d))");
$quota['limit']=$quota[1];
$quota['usage']=$quota[0];
fwrite($fp,"a001 logout");
fclose($fp);
}
if (is_array($quota) && $quota['limit'] != 0) {
$taken = $quota['usage'] / 1024.0;
$total = $quota['limit'] / 1024.0;
$percent = $taken * 100 / $total;
if ($percent >= 90) {
$class = 'quotaalert';
} elseif ($percent >= 75) {
$class = 'quotawarn';
} else {
$class = 'control';
}
$quota_html = '<table width="100%" border="0" cellpadding="0"
cellspacing="0"><tr><td class="item">'
. '<table border="0" cellspacing="2"
cellpadding="2" width="100%"><tr><td align="center" class="' . $class . '">'
. sprintf("%.2fMB / %.2fMB (%.2f%%)", $taken,
$total, $percent)
. '</td></tr></table></td></tr></table>';
}
return $quota_html;
}
---
You can get it from http://jlug.fi/~eero/hacks/quota.txt if is paste is
fucked up.
I am using it with courier imapd + qmail + vpopmail.
If you have problems, please mail me to address eero at ping-viini.org and I
can modify it for your use.
-- this message passed virusscanner at host jlug.fi --
More information about the imp
mailing list