Extend get_quota() so it's possible to specify GETQUOTAROOT folder and return full quota info (including all roots and types, e.g. MESSAGE) - for future use

pull/198/head
Aleksander Machniak 10 years ago
parent 750de3189c
commit 6fa1a0da1f

@ -1678,6 +1678,7 @@ class rcmail extends rcube
$quota = $this->storage->get_quota(); $quota = $this->storage->get_quota();
$quota = $this->plugins->exec_hook('quota', $quota); $quota = $this->plugins->exec_hook('quota', $quota);
unset($quota['abort']);
$quota_result = (array) $quota; $quota_result = (array) $quota;
$quota_result['type'] = isset($_SESSION['quota_display']) ? $_SESSION['quota_display'] : ''; $quota_result['type'] = isset($_SESSION['quota_display']) ? $_SESSION['quota_display'] : '';

@ -3067,14 +3067,15 @@ class rcube_imap extends rcube_storage
/** /**
* Get mailbox quota information * Get mailbox quota information
* added by Nuny *
* @param string $folder Folder name
* *
* @return mixed Quota info or False if not supported * @return mixed Quota info or False if not supported
*/ */
public function get_quota() public function get_quota($folder = null)
{ {
if ($this->get_capability('QUOTA') && $this->check_connection()) { if ($this->get_capability('QUOTA') && $this->check_connection()) {
return $this->conn->getQuota(); return $this->conn->getQuota($folder);
} }
return false; return false;

@ -2873,50 +2873,51 @@ class rcube_imap_generic
/** /**
* Returns QUOTA information * Returns QUOTA information
* *
* @param string $mailbox Mailbox name
*
* @return array Quota information * @return array Quota information
*/ */
function getQuota() function getQuota($mailbox = null)
{ {
/* if ($mailbox === null || $mailbox === '') {
* GETQUOTAROOT "INBOX" $mailbox = 'INBOX';
* QUOTAROOT INBOX user/rchijiiwa1 }
* QUOTA user/rchijiiwa1 (STORAGE 654 9765)
* OK Completed // a0001 GETQUOTAROOT INBOX
*/ // * QUOTAROOT INBOX user/sample
// * QUOTA user/sample (STORAGE 654 9765)
// a0001 OK Completed
list($code, $response) = $this->execute('GETQUOTAROOT', array($this->escape($mailbox)));
$result = false; $result = false;
$quota_lines = array(); $min_free = PHP_INT_MAX;
$key = $this->nextTag(); $all = array();
$command = $key . ' GETQUOTAROOT INBOX';
// get line(s) containing quota info if ($code == self::ERROR_OK) {
if ($this->putLine($command)) { foreach (explode("\n", $response) as $line) {
do {
$line = rtrim($this->readLine(5000));
if (preg_match('/^\* QUOTA /', $line)) { if (preg_match('/^\* QUOTA /', $line)) {
$quota_lines[] = $line; list(, , $quota_root) = $this->tokenizeResponse($line, 3);
}
} while (!$this->startsWith($line, $key, true, true)); while ($line) {
list($type, $used, $total) = $this->tokenizeResponse($line, 1);
$type = strtolower($type);
if ($type && $total) {
$all[$quota_root][$type]['used'] = intval($used);
$all[$quota_root][$type]['total'] = intval($total);
} }
else {
$this->setError(self::ERROR_COMMAND, "Unable to send command: $command");
} }
// return false if not found, parse if found if (empty($all[$quota_root]['storage'])) {
$min_free = PHP_INT_MAX;
foreach ($quota_lines as $key => $quota_line) {
$quota_line = str_replace(array('(', ')'), '', $quota_line);
$parts = explode(' ', $quota_line);
$storage_part = array_search('STORAGE', $parts);
if (!$storage_part) {
continue; continue;
} }
$used = intval($parts[$storage_part+1]); $used = $all[$quota_root]['storage']['used'];
$total = intval($parts[$storage_part+2]); $total = $all[$quota_root]['storage']['total'];
$free = $total - $used; $free = $total - $used;
// return lowest available space from all quotas // calculate lowest available space from all storage quotas
if ($free < $min_free) { if ($free < $min_free) {
$min_free = $free; $min_free = $free;
$result['used'] = $used; $result['used'] = $used;
@ -2925,6 +2926,12 @@ class rcube_imap_generic
$result['free'] = 100 - $result['percent']; $result['free'] = 100 - $result['percent'];
} }
} }
}
}
if (!empty($result)) {
$result['all'] = $all;
}
return $result; return $result;
} }

@ -918,9 +918,11 @@ abstract class rcube_storage
/** /**
* Get mailbox quota information. * Get mailbox quota information.
* *
* @param string $folder Folder name
*
* @return mixed Quota info or False if not supported * @return mixed Quota info or False if not supported
*/ */
abstract function get_quota(); abstract function get_quota($folder = null);
/* ----------------------------------------- /* -----------------------------------------

Loading…
Cancel
Save