1: <?php
2: /**
3: * Implementation of the IMP_Quota API for IMAP servers.
4: *
5: * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (GPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/gpl.
9: *
10: * @author Mike Cochrane <mike@graftonhall.co.nz>
11: * @category Horde
12: * @license http://www.horde.org/licenses/gpl GPL
13: * @package IMP
14: */
15: class IMP_Quota_Imap extends IMP_Quota_Base
16: {
17: /**
18: * Constructor.
19: *
20: * @param array $params Parameters:
21: * <pre>
22: * 'imap_ob' - (Horde_Imap_Client_Base) IMAP client object.
23: * 'mbox' - (string) IMAP mailbox to query.
24: * </pre>
25: *
26: * @throws InvalidArgumentException
27: */
28: public function __construct(array $params = array())
29: {
30: foreach (array('imap_ob', 'mbox') as $val) {
31: if (!isset($params[$val])) {
32: throw new InvalidArgumentException('Missing ' . $val . ' parameter');
33: }
34: }
35:
36: parent::__construct($params);
37: }
38:
39: /**
40: * Get quota information (used/allocated), in bytes.
41: *
42: * @return array An array with the following keys:
43: * 'limit' = Maximum quota allowed
44: * 'usage' = Currently used portion of quota (in bytes)
45: * @throws IMP_Exception
46: */
47: public function getQuota()
48: {
49: try {
50: $quota = $this->_params['imap_ob']->getQuotaRoot($this->_params['mbox']);
51: } catch (IMP_Imap_Exception $e) {
52: throw new IMP_Exception(_("Unable to retrieve quota"));
53: }
54:
55: $quota_val = reset($quota);
56:
57: return isset($quota_val['storage'])
58: ? array(
59: 'limit' => $quota_val['storage']['limit'] * 1024,
60: 'usage' => $quota_val['storage']['usage'] * 1024
61: )
62: : array(
63: 'limit' => 0,
64: 'usage' => 0
65: );
66: }
67:
68: }
69: