Skip to content

Commit

Permalink
[mms] Add configurable IMAP quota checking interval (Request #12907).
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Apr 22, 2014
1 parent c00d3d8 commit 776517b
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 13 deletions.
2 changes: 2 additions & 0 deletions imp/config/backends.php
Expand Up @@ -120,6 +120,8 @@
* - hide_when_unlimited: (boolean) True if you want to hide quota
* output when the server reports an unlimited
* quota.
* - interval: (integer) Update quota information in the UI at this
* interval (in seconds). Defaults to 15 minutes.
* - unit: (string) What storage unit the quota messages should be
* displayed in. One of:
* - GB
Expand Down
1 change: 1 addition & 0 deletions imp/docs/CHANGES
Expand Up @@ -2,6 +2,7 @@
v6.2.0-git
----------

[mms] Add configurable IMAP quota checking interval (Request #12907).
[mms] Honor 'from_link' preference in dynamic view.
[mms] Add support for storing image data within HTML signatures.
[mms] Ensure that viewing large mailboxes does not overload the session
Expand Down
2 changes: 2 additions & 0 deletions imp/docs/UPGRADING
Expand Up @@ -53,6 +53,8 @@ The 'format' quota option has been removed.
The 'cache_lifetime' option is now honored for the 'cache' and 'hashtable'
caching backends.

The 'interval' parameter has been added to the quota configuration.


Configuration Options (conf.php)
--------------------------------
Expand Down
6 changes: 3 additions & 3 deletions imp/lib/Ajax/Application/Handler/Common.php
Expand Up @@ -37,6 +37,8 @@ public function poll()
* separate poll action because there are other tasks done when
* specifically requesting a poll. */

$this->_base->queue->quota($this->_base->indices->mailbox, false);

if ($this->_base->changed()) {
$this->_base->addTask('viewport', $this->_base->viewPortData(true));
}
Expand Down Expand Up @@ -120,9 +122,7 @@ public function viewPort()
$this->_base->addTask('viewport', $vp);
}

if ($vp_vars->checkcache) {
$this->_base->queue->quota($this->_base->indices->mailbox);
}
$this->_base->queue->quota($this->_base->indices->mailbox, $vp_vars->checkcache);

return $result;
}
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Ajax/Application/ListMessages.php
Expand Up @@ -176,7 +176,7 @@ public function listMessages($args)
/* Actions only done on 'initial' request. */
if ($args['initial']) {
/* Load queue information on original request. */
$injector->getInstance('IMP_Ajax_Queue')->quota($mbox);
$injector->getInstance('IMP_Ajax_Queue')->quota($mbox, true);

if (!$mbox->is_imap) {
$result->setMetadata('pop3', 1);
Expand Down
13 changes: 9 additions & 4 deletions imp/lib/Ajax/Queue.php
Expand Up @@ -99,9 +99,10 @@ class IMP_Ajax_Queue
/**
* Add quota information to response?
*
* Array w/2 keys: mailbox, force
* If null, never sends quota information.
*
* @var string
* @var mixed
*/
protected $_quota = false;

Expand Down Expand Up @@ -281,7 +282,7 @@ public function add(IMP_Ajax_Application $ajax)

/* Add quota information. */
if ($this->_quota &&
($quotadata = $injector->getInstance('IMP_Quota_Ui')->quota($this->_quota))) {
($quotadata = $injector->getInstance('IMP_Quota_Ui')->quota($this->_quota[0], $this->_quota[1]))) {
$ajax->addTask('quota', array(
'm' => $quotadata['message'],
'p' => round($quotadata['percent']),
Expand Down Expand Up @@ -535,11 +536,15 @@ public function poll($mboxes, $explicit = false)
*
* @param string|null $mailbox Mailbox to query for quota. If null,
* disables quota output.
* @param boolean $force If true, force output. If false, output
* based on configured quota interval.
*/
public function quota($mailbox)
public function quota($mailbox, $force = true)
{
if (!is_null($this->_quota)) {
$this->_quota = $mailbox;
$this->_quota = is_null($mailbox)
? null
: array($mailbox, $force);
}
}

Expand Down
6 changes: 6 additions & 0 deletions imp/lib/Imap/Config.php
Expand Up @@ -145,6 +145,12 @@ public function __set($name, $value)

/* Normalize values. */
switch ($name) {
case 'quota':
$value['params']['interval'] = isset($value['params']['interval'])
? intval($value['params']['interval'])
: 900; // DEFAULT: 15 minutes
break;

case 'preferred':
if (!is_array($value)) {
$value = array($value);
Expand Down
33 changes: 29 additions & 4 deletions imp/lib/Quota/Ui.php
Expand Up @@ -22,26 +22,48 @@
*/
class IMP_Quota_Ui
{
/** Session key for interval data. */
const SESSION_INTERVAL_KEY = 'quota_interval';

/**
* Returns data needed to output quota.
*
* @param string $mailbox Mailbox to query.
* @param boolean $force If true, ignore 'interval' config option and
* force quota display.
*
* @return array Array with these keys: class, message, percent.
* @return array|boolean Array with these keys: class, message, percent.
* Returns false if no updated quota information.
*/
public function quota($mailbox = null)
public function quota($mailbox = null, $force = true)
{
global $injector;
global $injector, $session;

if (!$injector->getInstance('IMP_Factory_Imap')->create()->config->quota) {
$qconfig = $injector->getInstance('IMP_Factory_Imap')->create()->config->quota;
if (!$qconfig) {
return false;
}

$qlist = array();

if (!is_null($mailbox)) {
$mailbox = IMP_Mailbox::get($mailbox);
if ($mailbox->nonimap) {
return false;
}

if (!$force) {
$qlist = $session->get(
'imp',
self::SESSION_INTERVAL_KEY,
$session::TYPE_ARRAY
);

if (isset($qlist[strval($mailbox)]) &&
(time() < $qlist[strval($mailbox)])) {
return false;
}
}
}

try {
Expand All @@ -52,6 +74,9 @@ public function quota($mailbox = null)
return false;
}

$qlist[strval($mailbox)] = $qconfig['params']['interval'] + time();
$session->store('imp', self::SESSION_INTERVAL_KEY, $qlist);

if (empty($quota)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/View/Subinfo.php
Expand Up @@ -47,7 +47,7 @@ public function __construct(array $config = array())
$config['templatePath'] = IMP_TEMPLATES . '/basic';
parent::__construct($config);

$quotadata = $GLOBALS['injector']->getInstance('IMP_Quota_Ui')->quota(isset($config['mailbox']) ? $config['mailbox'] : null);
$quotadata = $GLOBALS['injector']->getInstance('IMP_Quota_Ui')->quota(isset($config['mailbox']) ? $config['mailbox'] : null, true);
if (!empty($quotadata)) {
$this->quotaClass = $quotadata['class'];
$this->quotaText = $quotadata['message'];
Expand Down
1 change: 1 addition & 0 deletions imp/package.xml
Expand Up @@ -33,6 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [mms] Add configurable IMAP quota checking interval (Request #12907).
* [mms] Honor &apos;from_link&apos; preference in dynamic view.
* [mms] Add support for storing image data within HTML signatures.
* [mms] Ensure that viewing large mailboxes does not overload the session storage size.
Expand Down

0 comments on commit 776517b

Please sign in to comment.