Courier-IMAP and $conf['hooks']['quota']

Joshua E Warchol jwarchol@dsl.net
Tue, 11 Dec 2001 08:47:31 -0500


I just want to share how I got $conf['hooks']['quota'] working with
courier-imap. Maybe someone else will be able to safe themselves some time
by reading this.

Basically the problem is that PHP's IMAP quota functions are really geared
towards cyrus imapd. For example, the whole idea of sending user.username
as the quota root is a cyrus-ism. There are no administrative IMAP users
in Courier-IMAP, and the only valid quota roots are "ROOT" and "SHARED". 

So to get it working you can use something like this (taken from conf.php
in IMP 3.0rc3...

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

/* Gets the quota usage from the imap server. $imap_admin &
 * $imap_passwd must be set to fit your own settings.
 */
if (!function_exists('imp_show_quota')) {
   function imp_show_quota ($imp) {
        $imap_admin = $imp['user'];
        $imap_passwd = Secret::read(Secret::getKey('imp'), $imp['pass']);
        //echo "$imap_admin $imap_passwd<p>";

        $stream = @imap_open(IMP::serverString(), $imap_admin, $imap_passwd, OP_HALFOPEN);
        $quota = @imap_get_quota($stream, 'ROOT');
        imap_close($stream);

        if (!empty($quota)) {
            $taken   = $quota['usage'] / 1024.0;
            $total   = $quota['limit'] / 1024.0;
            $percent = $taken * 100 / $total;

            echo '<table width="30%" border="0" cellpadding="0" cellspacing="0"><tr><td><table border="0" cellspacing="2" cellpadding="2" width="100%"><tr><td align="left"><font color=white>';
            echo sprintf("Mailbox Size: %.2fMB / %.2fMB  (%.2f%% Full)", $taken, $total, $percent);
            echo '</font></td></tr></table></td></tr></table>';
        }
    }
}
[end]

Hope this helps. Comments?

-- 
Joshua Warchol
UNIX Systems Administrator
DSL.net