[imp] imp_show_quota + cyrus-imapd
Gary C. New
garycnew at yahoo.com
Sat Jul 5 02:02:28 PDT 2003
Leena,
I appreciate that snippet of code. It worked like a
charm. I guess I'll stick with it until I get
php-4.3.x installed.
Thanks, again.
Gary
--- Leena Heino <Leena.Heino at uta.fi> wrote:
> On Thu, 3 Jul 2003, Gary C. New wrote:
>
> > I'm trying to get imp_show_quota to work with
> IMP-3.1,
> > php-4.2.3, and cyrus-imapd-2.0.16. It seems that
> the
> > php imap_get_quota function is erroring at the
> > following line with the respective error:
>
> You might want to try this with imp-3.1 and
> php-4.2.3 as your
> imp_show_quota function. Just replace the existing
> function in
> imp's config/conf.php.
>
> /*
> * Gets the quota usage from the IMAP server.
> * This function uses GETQUOTAROOT. This function
> can be used
> * as a ordinary user with Cyrus IMAP server.
> * This function should be used with IMP 3.1
> */
> if (!function_exists('imp_show_quota')) {
> function imp_show_quota ($imp) {
> if (function_exists('imap_get_quotaroot')) {
> $stream =
> @imap_open(IMP::serverString(), $imp['user'],
> Secret::read(Secret::getKey('imp'), $imp['pass']),
> OP_HALFOPEN);
> if ($stream !== false) {
> $quotas =
> @imap_get_quotaroot($stream, "INBOX");
> @imap_close($stream);
> }
> if (is_array($quotas)) {
> if (isset($quotas['limit'])) {
> $quota[1] = $quotas['usage'];
> $quota[2] = $quotas['limit'];
> } elseif
> (isset($quotas['STORAGE']['limit'])) {
> $quota[1] =
> $quotas['STORAGE']['usage'];
> $quota[2] =
> $quotas['STORAGE']['limit'];
> } elseif (empty($quotas['usage']) &&
> empty($quotas['limit'])) {
> $quota[1] = $quota[2] = 'none';
> } elseif
> (empty($quotas['STORAGE']['usage']) &&
> empty($quotas['STORAGE']['limit'])) {
> $quota[1] = $quota[2] = 'none';
> }
> }
> } else {
> $imap_admin = $imp['user'];
> $imap_passwd =
> Secret::read(Secret::getKey('imp'), $imp['pass']);
>
> ereg
> ("([a-zA-Z0-9.-]+)",$imp['server'],$quotaserver);
> $fp = fsockopen($quotaserver[1], '143',
> $errno, $errstr, 30);
> if ($fp) {
> $r = fgets($fp,128);
> if (substr($r,0,4) == '* OK') {
> fputs($fp,"0 LOGIN
> ".$imap_admin."
> \"".addslashes($imap_passwd)."\"\n");
> $r = fgets($fp,128);
> if (substr($r,0,4) == '0 OK') {
> fputs($fp,"1 GETQUOTAROOT
> INBOX\n");
> $r = fgets($fp,128);
> if (substr($r,0,3) == '* Q')
> {
> $r = fgets($fp,128);
> $quota[1] = $quota[2] =
> 'none';
> ereg ("STORAGE ([0-9]+)
> ([0-9]+)",$r,$quota);
> }
> fputs($fp,"2 LOGOUT\n");
> }
> }
> fclose($fp);
> }
> }
>
> if (isset($quota)) {
> if ($quota[1] !== 'none' && $quota[2]
> !== 'none' ) {
> $qusage = $quota[1];
> $qlimit = $quota[2];
> $percent = $qusage * 100 / $qlimit;
> if ($percent >= 90) {
> $class = 'quotaalert';
> } elseif ($percent >= 75) {
> $class = 'quotawarn';
> } else {
> $class = 'control';
> }
> $quota_str = sprintf("Quota status:
> %dKB / %dKB (%.2f%%)", $qusage, $qlimit, $percent);
> } else {
> $class = 'control';
> $quota_str = sprintf("Quota status:
> NO LIMIT");
> }
> $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("%s",
> $quota_str)
> .
> '</td></tr></table></td></tr></table>';
> return $quota_html;
> }
> return '';
> }
> return '';
> }
>
>
> --
> -- Leena Heino (liinu at uta.fi)
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
More information about the imp
mailing list