Add option to use message count limit for maildir quota
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 1 Sep 2010 08:31:52 +0000 (02:31 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 1 Sep 2010 08:31:52 +0000 (02:31 -0600)
imp/config/servers.php.dist
imp/lib/Quota/Maildir.php

index a69e585..dcd01ea 100644 (file)
  *
  *           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
index 885e599..ed6e2bb 100644 (file)
@@ -1,9 +1,7 @@
 <?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/)
  *
@@ -14,7 +12,6 @@
  * @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
 {
@@ -23,6 +20,9 @@ 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
@@ -36,6 +36,7 @@ class IMP_Quota_Maildir extends IMP_Quota_Base
     public function __construct($params = array())
     {
         parent::__construct(array_merge(array(
+            'msg_count' => false,
             'path' => '',
             'username' => ''
         ), $params));
@@ -45,13 +46,15 @@ class IMP_Quota_Maildir extends IMP_Quota_Base
      * 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';
@@ -80,34 +83,36 @@ class IMP_Quota_Maildir extends IMP_Quota_Base
                     $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
         );
     }