[imp] imp_show_quota....
Michael Bellears
michael.bellears@staff.datafx.com.au
Sat, 25 May 2002 23:39:48 +1000
> Hi all,
>
> Does anybody have a working configuration of
> IMP in which imp_show_quota function working?
>
Yes:
Firstly ensure you have quota enabled in Courier ->
#telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK Courier-IMAP ready. Copyright 1998-2002 Double Precision, Inc. See
COPYING for distribution information.
1 capability
* CAPABILITY IMAP4rev1 CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT
THREAD=REFERENCES SORT QUOTA
1 OK CAPABILITY completed
Then in imp_show_quota() ->
if (!function_exists('imp_show_quota')) {
function imp_show_quota ($imp) {
$quota_html = '';
// Use the following two lines instead for Courier.
$imap_admin = $imp['user'];
$imap_passwd = Secret::read(Secret::getKey('imp'), $imp['pass']);
$stream = @imap_open(IMP::serverString(), $imap_admin, $imap_passwd,
OP_HALFOPEN);
$quota = @imap_get_quota($stream, 'user.' . $imp['user']);
// Use the following line instead for Courier.
$quota = @imap_get_quota($stream, 'ROOT');
imap_close($stream);
if (!empty($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;
}
}
HTH,
MB