[imp] How do I setup a quota meter on the IMP page?

eculp@encontacto.net eculp@encontacto.net
Thu Nov 28 16:27:50 2002


Quoting "Jorge Frater B." <jfrater@fratec.com>:

 | 
 | Hi:
 | 
 | I have a working IMP with Qmail and Courier IMAP.
 | 
 | I saw in the /imp/config/conf.php file a part to activate the quota usage
 | but it has no effect on how the main IMP page displays.
 | 
 | Has anyone set that up that could tell me the steps to follow?

I haven't used this version for sometime and the HEAD version has been
changed and isn't using hooks for quota anymore.

First you need to be sure that courier is set up properly and that your
maildirsize files are being created.  Then, IIRC, you just need to add
the hook.  Something like the attached file in your 
horde/imp/config/conf.php

I hope this helps.

ed



-------------------------------------------------

-------------- next part --------------
// See the 'imp_show_quota' function below for an example.

$conf['hooks']['quota'] = 'imp_show_quota';

if (!function_exists('imp_show_quota')) {    
   function imp_show_quota ($imp) {
        $quota_html = '';              
        $imap_admin = $imp['user'];
	$splitted  = split("@", $imap_admin);
	$realname = @$splitted[0];
	$realm = @$splitted[1];
	$homedir = '/home/virtual/' .  $realm . '/' . $realname;
        $quota_html = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td class="item"><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr>';
        $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, '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) {
               $color = '#FF0000';
           } elseif ($percent >= 80) {
               $color = '#FCE30D';
           } else {
               $color = '#339933';
           }
           $quota_html .= '<td align="left" class="smallheader">';
           $quota_html .= sprintf("<font size=-3>Quota for %s:</font>", $imap_admin);
           $quota_html .= '<td align="center" class="header">';
           $quota_html .= sprintf("<font size=-3>%.1fMB/%.1fMB (%.1f%%)</font>", $taken, $total, $percent);
           $quota_html .= '</td><td width="30" class="header" align="right"><font size="-3">0%</font></td><td width="200" class="header">';
           $quota_html .= '<table width="100%"><tr><td bgcolor="#ccccff"><div style="height:6px; width:'. sprintf("%.1f%%", $percent). '; font-size:3px; background-color:'.$color.'">';
           $quota_html .= '</div></td></tr></table></td><td width="30" class="header" align="left"><font size="-3">100%</font>';
        } else {
            $quota_html .= '<td align="center" class="header">';
            $quota_html .= "Quota not available";
        }
        $quota_html .= '</td></tr></table></td></tr></table>';
        return $quota_html;
    }
}



More information about the imp mailing list