* DRIVER: 'hook'
* Use the quota hook to handle quotas (see
* imp/config/hooks.php).
- * PARAMS: 'params' - [array] Parameters to pass to the quota
- * hook function.
+ * PARAMS: Any parameters defined here will be passed to the quota
+ * hook function.
*
* DRIVER: 'imap'
* Use the IMAP QUOTA extension to handle quotas.
// {
// // Example #1: Sample function for returning the quota.
// // Uses the PECL ssh2 extension.
-// $host = $_SESSION['imp']['server'];
-// $user = $_SESSION['imp']['user'];
-// $pass = $GLOBALS['registry']->getAuthCredential('password');
-// $command = $params[0];
+// // Requires the 'command' parameter to be defined in backends.php,
+// // which defines the quota reporting function to run on the SSH
+// // host.
+// $imap_ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create();
+// $host = $imap_ob->ob->getParam('hostspec');
+// $user = $params['host'];
+// $pass = $imap_ob->ob->getParam('password');
+// $command = $params['command'];
//
// $session = ssh2_connect($host);
// if (!$session) {
: IMP::$mailbox;
break;
- case 'maildir':
- $params['username'] = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->getParam('username');
- break;
-
case 'sql':
$params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('imp', $params);
break;
}
+ $params['username'] = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->getParam('username');
+
return IMP_Quota::factory($driver, $params);
}
<?php
/**
- * The IMP_Quota_Base:: class is the abstract class that all driver
+ * The IMP_Quota_Base:: class is the abstract class that all drivers inherit
+ * from.
*
* Copyright 2010 The Horde Project (http://www.horde.org/)
*
* strings will be passed through sprintf().
* 'unit' - (string) What storage unit the quota messages should be
* displayed in. Either 'GB', 'MB', or 'KB'.
+ * 'username' - (string) The username to query.
* </pre>
*/
public function __construct(array $params = array())
public function getQuota()
{
if (empty($this->_params['partition'])) {
- $passwd_array = posix_getpwnam($_SESSION['imp']['user']);
+ $passwd_array = posix_getpwnam($this->_params['username']);
list($junk, $search_string, $junk) = explode('/', $passwd_array['dir']);
} else {
$search_string = $this->_params['partition'];
}
- $cmdline = $this->_params['quota_path'] . ' -u ' . escapeshellarg($_SESSION['imp']['user']) . ' | ' . escapeshellcmd($this->_params['grep_path']) . ' ' . escapeshellarg($search_string);
+ $cmdline = $this->_params['quota_path'] . ' -u ' . escapeshellarg($this->_params['username']) . ' | ' . escapeshellcmd($this->_params['grep_path']) . ' ' . escapeshellarg($search_string);
exec($cmdline, $quota_data, $return_code);
if (($return_code == 0) && (count($quota_data) == 1)) {
$quota = split("[[:blank:]]+", trim($quota_data[0]));
* 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(
'msg_count' => false,
- 'path' => '',
- 'username' => ''
+ 'path' => ''
), $params));
}
*/
public function getQuota()
{
- $userDetails = $this->_getUserDetails($_SESSION['imp']['user'], $_SESSION['imp']['maildomain']);
+ $imap_ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create();
+ $userDetails = $this->_getUserDetails(
+ $this->_params['username'],
+ $_SESSION['imp']['maildomain']
+ );
if ($userDetails !== false) {
$userHome = trim(substr($userDetails, 105, 90));
$quota = 0;
try {
- $di = new DirectoryIterator($this->_params['mail_user_folder'] . '/' . $_SESSION['imp']['user'] . '/');
+ $di = new DirectoryIterator($this->_params['mail_user_folder'] . '/' . $this->_params['username'] . '/');
} catch (UnexpectedValueException $e) {
throw new IMP_Exception(_("Unable to retrieve quota"));
}
*/
public function getQuota()
{
- $user = $_SESSION['imp']['user'];
$quota = array(
'limit' => 0,
'usage' => 0
if (empty($this->_params['query_quota'])) {
Horde::logMessage(__CLASS__ . ': query_quota SQL query not set.', 'ERR');
} else {
- @list($bare_user, $domain) = explode('@', $user, 2);
+ @list($bare_user, $domain) = explode('@', $this->_params['username'], 2);
$query = str_replace(array('?', '%u', '%U', '%d'),
- array($this->_db->quote($user),
- $this->_db->quote($user),
+ array($this->_db->quote($this->_params['username']),
+ $this->_db->quote($this->_params['username']),
$this->_db->quote($bare_user),
$this->_db->quote($domain)),
$this->_params['query_quota']);
if (empty($this->_params['query_used'])) {
Horde::logMessage(__CLASS__ . ': query_used SQL query not set.', 'ERR');
} else {
- @list($bare_user, $domain) = explode('@', $user, 2);
+ @list($bare_user, $domain) = explode('@', $this->_params['username'], 2);
$query = str_replace(array('?', '%u', '%U', '%d'),
- array($this->_db->quote($user),
- $this->_db->quote($user),
+ array($this->_db->quote($this->_params['username']),
+ $this->_db->quote($this->_params['username']),
$this->_db->quote($bare_user),
$this->_db->quote($domain)),
$this->_params['query_used']);