[imp] More efficient way of getting IMAP quota?
Richard Gilbert
R.Gilbert at sheffield.ac.uk
Tue Nov 18 10:45:23 PST 2003
While looking at ways to add authorisation to the login process I came
across the fact that from PHP version 4.3.0 there is a new function
imap_get_quotaroot which gets the quota for the currently logged in user.
This means it is not necessary to do an extra log in as the admin user.
I have used this to replace the suggested code (IMP 3.2.2):
$imap_admin = 'admin';
$imap_passwd = 'password';
$stream = @imap_open(IMP::serverString(), $imap_admin, $imap_passwd, OP_HALFOPEN);
$quota = @imap_get_quota($stream, 'user.' . $imp['user']);
imap_close($stream);
by the following single call:
$quota = @imap_get_quotaroot($imp['stream'], "INBOX");
I then needed to replace $quota['usage'] and $quota['limit'] by
$quota['STORAGE']['usage'] and $quota['STORAGE']['limit'] respectively,
i.e.
if (is_array($quota) && $quota['STORAGE']['limit'] != 0) {
$taken = $quota['STORAGE']['usage'] / 1000.0;
$total = $quota['STORAGE']['limit'] / 1000.0;
It seems to do the job.
Richard
--
Richard Gilbert
Corporate Information and Computing Services
University of Sheffield, Sheffield, S10 2TN, UK
Phone: +44 114 222 3028 Fax: +44 114 222 3040
More information about the imp
mailing list