*
* DRIVER: 'maildir'
* Use Maildir++ quota files to handle quotas.
- * PARAMS: 'path' - [string] The path to the user's Maildir
+ * PARAMS: 'msg_count' - [boolean] Display information on the
+ * message limit rather than the storage
+ * limit? The storage limit information is
+ * displayed by default.
+ * 'path' - [string] The path to the user's Maildir
* directory. You may use the two-character
* sequence "~U" to represent the user's account
* name, and the actual username will be
<?php
/**
* Implementation of the Quota API for servers using Maildir++ quota files on
- * the local filesystem. Currently only supports storage limit, but should be
- * expanded to be configurable to support storage or message limits in the
- * configuration array.
+ * the local filesystem.
*
* Copyright 2007-2010 The Horde Project (http://www.horde.org/)
*
* @category Horde
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
- * @todo Add config param for storage vs message quota
*/
class IMP_Quota_Maildir extends IMP_Quota_Base
{
*
* @param array $params Parameters:
* <pre>
+ * 'msg_count' - (boolean) Display information on the message limit rather
+ * than the storage limit?
+ * DEFAULT: false
* 'path' - (string) The path to the user's Maildir directory. You may use
* the two-character sequence "~U" to represent the user's
* account name, and the actual username will be substituted in
public function __construct($params = array())
{
parent::__construct(array_merge(array(
+ 'msg_count' => false,
'path' => '',
'username' => ''
), $params));
* Returns quota information (used/allocated), in bytes.
*
* @return array An array with the following keys:
- * 'limit' = Maximum quota allowed
- * 'usage' = Currently used portion of quota (in bytes)
+ * <pre>
+ * 'limit' = Maximum quota allowed.
+ * 'usage' = Currently used portion of quota (in bytes).
+ * </pre>
* @throws IMP_Exception
*/
public function getQuota()
{
- $storage_limit = $message_limit = $storage_used = $message_used = 0;
+ $limit = $used = 0;
// Get the full path to the quota file.
$full = $this->_params['path'] . '/maildirsize';
$v2 = 0;
}
- if ($t1 == 'S') {
- $storage_limit = $v1;
- }
- if ($t1 == 'C') {
- $message_limit = $v1;
- }
- if ($t2 == 'S') {
- $storage_limit = $v2;
- }
- if ($t2 == 'C') {
- $message_limit = $v2;
+ if ($this->_params['msg_count']) {
+ if ($t1 == 'C') {
+ $limit = $v1;
+ }
+ if ($t2 == 'C') {
+ $limit = $v2;
+ }
+ } else {
+ if ($t1 == 'S') {
+ $limit = $v1;
+ }
+ if ($t2 == 'S') {
+ $limit = $v2;
+ }
}
} else {
// Any line other than the first line.
// The quota used is the sum of all lines found.
list($storage, $message) = sscanf(trim($line), '%ld %d');
- if (!is_null($storage)) {
- $storage_used += $storage;
- }
- if (!is_null($message)) {
- $message_used += $message;
+ if ($this->_params['msg_count'] && !is_null($message)) {
+ $used += $message;
+ } elseif (!$this->_params['msg_count'] && !is_null($storage)) {
+ $used += $storage;
}
}
}
return array(
- 'limit' => $storage_limit,
- 'usage' => $storage_used
+ 'limit' => $limit,
+ 'usage' => $used
);
}