*
* Set this to an empty value to disable quota (the DEFAULT).
*
+ * The optional 'unit' parameter indicates what storage unit the quota
+ * messages hould be displayed in. It can be one of three possible
+ * values: 'GB', 'MB' (DEFAULT), or 'KB'.
+ *
* The optional 'format' parameter is supported by all drivers and
* specifies the formats of the quota messages in the user
* interface. The parameter must be specified as a hash with the four
* possible elements 'long', 'short', 'nolimit_long', and
* 'nolimit_short' with according versions of the quota message. The
* strings will be passed through sprintf().
- *
* These are the built-in default values, though they may appear
- * differently in some translations:
- * 'long' -- Quota status: %.2f MB / %.2f MB (%.2f%%)
- * 'short' -- %.0f%% of %.0f MB
- * 'nolimit_long' -- Quota status: %.2f MB / NO LIMIT
- * 'nolimit_short' -- %.0f MB
+ * differently in some translations ([UNIT] will be replaced with the
+ * value of the 'unit' parameter):
+ * 'long' -- Quota status: %.2f [UNIT] / %.2f [UNIT] (%.2f%%)
+ * 'short' -- %.0f%% of %.0f [UNIT]
+ * 'nolimit_long' -- Quota status: %.2f [UNIT] / NO LIMIT
+ * 'nolimit_short' -- %.0f [UNIT]
*
* Currently available drivers:
* 'command' -- Use the UNIX quota command to handle quotas.
),
'quota' => array(
'driver' => 'imap',
- 'hide_when_unlimited' => true,
- 'params' => array()
+ 'params' => array(
+ 'hide_when_unlimited' => true,
+ 'unit' => 'MB'
+ )
),
'acl' => true,
'cache' => false,
'preferred' => '',
'quota' => array(
'driver' => 'imap',
- 'params' => array('hide_quota_when_unlimited' => true),
+ 'params' => array(
+ 'hide_quota_when_unlimited' => true,
+ 'unit' => 'MB'
+ )
),
'acl' => true,
'cache' => false,
v5.0-cvs
--------
+[mms] Add 'unit' parameter for quota display (Carlos Pires <acmpires@sapo.pt>,
+ Request #7044).
[mms] Add support for '$Forwarded' IMAP keyword (Request #3402).
[mms] Attachments in a signed message now can be downloaded via the
download all attachments link (Bug #2939).
}
$strings = $quotaDriver->getMessages();
+ list($calc, $unit) = $quotaDriver->getUnit();
$ret = array('percent' => 0);
if ($quota['limit'] != 0) {
- $quota['usage'] = $quota['usage'] / (1024 * 1024.0);
- $quota['limit'] = $quota['limit'] / (1024 * 1024.0);
+ $quota['usage'] = $quota['usage'] / $calc;
+ $quota['limit'] = $quota['limit'] / $calc;
$ret['percent'] = ($quota['usage'] * 100) / $quota['limit'];
if ($ret['percent'] >= 90) {
$ret['class'] = 'quotaalert';
} else {
$ret['class'] = 'control';
}
- if ($long) {
- $ret['message'] = sprintf($strings['long'], $quota['usage'],
- $quota['limit'], $ret['percent']);
- } else {
- $ret['message'] = sprintf($strings['short'], $ret['percent'],
- $quota['limit']);
- }
+
+ $ret['message'] = $long
+ ? sprintf($strings['long'], $quota['usage'], $unit, $quota['limit'], $unit, $ret['percent'])
+ : sprintf($strings['short'], $ret['percent'], $quota['limit'], $unit);
+ $ret['percent'] = sprintf("%.2f", $ret['percent']);
} else {
// Hide unlimited quota message?
if (!empty($_SESSION['imp']['quota']['hide_when_unlimited'])) {
$ret['class'] = 'control';
if ($quota['usage'] != 0) {
- $quota['usage'] = $quota['usage'] / (1024 * 1024.0);
- if ($long) {
- $ret['message'] = sprintf($strings['nolimit_long'],
- $quota['usage']);
- } else {
- $ret['message'] = sprintf($strings['nolimit_short'],
- $quota['usage']);
- }
+ $quota['usage'] = $quota['usage'] / $calc;
+
+ $ret['message'] = $long
+ ? sprintf($strings['nolimit_long'], $quota['usage'], $unit)
+ : sprintf($strings['nolimit_short'], $quota['usage'], $unit);
} else {
- if ($long) {
- $ret['message'] = sprintf(_("Quota status: NO LIMIT"));
- } else {
- $ret['message'] = _("No limit");
- }
+ $ret['message'] = $long
+ ? sprintf(_("Quota status: NO LIMIT"))
+ : _("No limit");
}
}
*
* @param array $params Hash containing connection parameters.
*/
- function __construct($params = array())
+ public function __construct($params = array())
{
$this->_params = $params;
return array(
'long' => isset($this->_params['format']['long'])
? $this->_params['format']['long']
- : _("Quota status: %.2f MB / %.2f MB (%.2f%%)"),
+ : _("Quota status: %.2f %s / %.2f %s (%.2f%%)"),
'short' => isset($this->_params['format']['short'])
? $this->_params['format']['short']
- : _("%.0f%% of %.0f MB"),
+ : _("%.0f%% of %.0f %s"),
'nolimit_long' => isset($this->_params['format']['nolimit_long'])
? $this->_params['format']['nolimit_long']
- : _("Quota status: %.2f MB / NO LIMIT"),
+ : _("Quota status: %.2f %s / NO LIMIT"),
'nolimit_short' => isset($this->_params['format']['nolimit_short'])
? $this->_params['format']['nolimit_short']
- : _("%.0f MB")
+ : _("%.0f %s")
);
}
+
+ /**
+ * Determine the units of storage to display in the quota message.
+ *
+ * @return array An array of size and unit type.
+ */
+ public function getUnit()
+ {
+ $unit = isset($this->_params['unit']) ? $this->_params['unit'] : 'MB';
+
+ switch ($unit) {
+ case 'GB':
+ $calc = 1024 * 1024 * 1024.0;
+ break;
+
+ case 'KB':
+ $calc = 1024.0;
+ break;
+
+ case 'MB':
+ default:
+ $calc = 1024 * 1024.0;
+ $unit = 'MB';
+ break;
+ }
+
+ return array($calc, $unit);
+ }
}