$params['password'] = $secret->read($secret->getKey('imp'), $params['password']);
}
+ switch (Horde_String::lower($driver)) {
+ case 'imap':
+ $params['imap_ob'] = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+ $params['mbox'] = $GLOBALS['injector']->getInstance('IMP_Search')->isSearchMbox(IMP::$mailbox)
+ ? 'INBOX'
+ : IMP::$mailbox;
+ break;
+
+ case 'maildir':
+ $params['username'] = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getParam('username');
+ break;
+ }
+
return IMP_Quota::factory($driver, $params);
}
class IMP_Quota_Imap extends IMP_Quota_Driver
{
/**
+ * Constructor.
+ *
+ * @param array $params Parameters:
+ * <pre>
+ * 'imap_ob' - (Horde_Imap_Client_Base) IMAP client object.
+ * 'mbox' - (string) IMAP mailbox to query.
+ * </pre>
+ *
+ * @throws InvalidArgumentException
+ */
+ public function __construct(array $params = array())
+ {
+ foreach (array('imap_ob', 'mbox') as $val) {
+ if (!isset($params[$val])) {
+ throw new InvalidArgumentException('Missing ' . $val . ' parameter');
+ }
+ }
+
+ parent::__construct($params);
+ }
+
+ /**
* Get quota information (used/allocated), in bytes.
*
* @return array An array with the following keys:
public function getQuota()
{
try {
- $quota = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getQuotaRoot($GLOBALS['injector']->getInstance('IMP_Search')->isSearchMbox(IMP::$mailbox) ? 'INBOX' : IMP::$mailbox);
+ $quota = $this->_params['imap_ob']->getQuotaRoot($this->_params['mbox']);
} catch (Horde_Imap_Client_Exception $e) {
throw new IMP_Exception(_("Unable to retrieve quota"));
}
* account name, and the actual username will be substituted in
* that location.
* E.g., '/home/~U/Maildir/' or '/var/mail/~U/Maildir/'
+ * DEFAULT: ''
+ * 'username' - (string) Username to substitute into the string.
+ * DEFAULT: none
* </pre>
*/
public function __construct($params = array())
{
parent::__construct(array_merge(array(
- 'path' => ''
+ 'path' => '',
+ 'username' => ''
), $params));
}
$full = $this->_params['path'] . '/maildirsize';
// Substitute the username in the string if needed.
- $full = str_replace('~U', $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getParam('username'), $full);
+ $full = str_replace('~U', $this->_params['username'], $full);
// Read in the quota file and parse it, if possible.
if (!is_file($full)) {
--FILE--
<?php
-$_SESSION['imp']['user'] = null;
-require_once dirname(__FILE__) . '/../Quota.php';
-$quota = IMP_Quota::factory('maildir',
- array('path' => dirname(__FILE__) . '/fixtures'));
+require_once dirname(__FILE__) . '/../Application.php';
+Horde_Registry::appInit('imp', array(
+ 'authentication' => 'none',
+ 'cli' => true
+));
+
+$quota = IMP_Quota::factory('Maildir', array(
+ 'path' => dirname(__FILE__) . '/fixtures'
+));
+
var_export($quota->getQuota());
?>
--EXPECT--
array (
- 'usage' => 550839239,
'limit' => 1000000000,
+ 'usage' => 550839239,
)