Quota fixes/doc improvements
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 4 Feb 2010 07:24:35 +0000 (00:24 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 4 Feb 2010 07:45:21 +0000 (00:45 -0700)
13 files changed:
imp/config/servers.php.dist
imp/lib/Ajax/Application.php
imp/lib/IMP.php
imp/lib/Quota/Command.php
imp/lib/Quota/Hook.php
imp/lib/Quota/Imap.php
imp/lib/Quota/Logfile.php [deleted file]
imp/lib/Quota/Maildir.php
imp/lib/Quota/Mdaemon.php
imp/lib/Quota/Mercury32.php
imp/lib/Quota/Sql.php
imp/templates/index/index-dimp.inc
imp/themes/screen-dimp.css

index eb00690..8aeabdf 100644 (file)
  *           This value overrides any existing
  *           $conf['mailer']['params']['port'] value at runtime.
  *
- * quota: (array) Use this if you want to display a user's quota status on
- *        various IMP pages. Set 'driver' equal to the mailserver and 'params'
- *        equal to any extra parameters needed by the driver (see the
- *        comments located at the top of imp/lib/Quota/[quotadriver].php
- *        for the parameters needed for each driver). Set
- *        'hide_when_unlimited' to true if you want to hide quota output
- *        when the server reports an unlimited quota.
- *
- *        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 ([UNIT] will be replaced with the
- *        value of the 'unit' parameter):
- *          'long'          - Quota status: %.2f [UNIT] / %.2f [UNIT] (%.2f%%)
- *          'nolimit_long'  - Quota status: %.2f [UNIT] / NO LIMIT
- *          'short'         - %.0f%% of %.0f [UNIT]
- *          'nolimit_short' - %.0f [UNIT]
- *
- *        Currently available drivers:
- *          'command' - Use the UNIX quota command to handle quotas.
- *          'hook' - Use the quota hook to handle quotas (see
- *                   imp/config/hooks.php).
- *          'imap' - Use the IMAP QUOTA extension to handle quotas.
- *                   You must be connecting to a IMAP server capable of the
- *                   QUOTAROOT command to use this driver. This is the
- *                   RECOMMENDED way of handling quotas if the IMAP server
- *                   supports it.
- *          'logfile' - Allow quotas on servers where IMAP Quota commands are
- *                      not supported, but quota info appears in the servers
- *                      messages log for the IMAP server.
- *          'maildir' - Use Maildir++ quota files to handle quotas.
- *          'mdaemon' - Use Mdaemon servers to handle quotas.
- *          'mercury32' - Use Mercury/32 servers to handle quotas.
- *          'sql' - Use arbitrary SQL queries to handle quotas.
- *
  * admin: (array) Use this if you want to enable mailbox management for
  *        administrators via Horde's user administration interface.  The
  *        mailbox management gets enabled if you let IMP handle the Horde
  *
  *             ((Horde_Auth::getAuth() == 'foo') ? '/tmp/imaplog' : false)
  *
+ * quota: (array) Use this if you want to display a user's quota status on
+ *        various IMP pages. Set to an empty value to disable quota status
+ *        (DEFAULT).
+ *
+ *        The entry is configured as follows:
+ *
+ *          'quota' => array(
+ *              /* Driver name: see below */
+ *              'driver' => [string] (REQUIRED),
+
+ *              'params' => array(
+ *                  /* True if you want to hide quota output when the server
+ *                  * reports an unlimited quota. */
+ *                  'hide_when_unlimited' => true | false,
+ *
+ *                  /* What storage unit the quota messages should be
+ *                   * displayed in. */
+ *                  'unit' => 'GB' | 'MB' (DEFAULT) | 'KB',
+ *
+ *                  /* Output format: see below. */
+ *                  'format' => array(),
+ *
+ *                  /* Additional driver parameters: see below. */
+ *              )
+ *          )
+ *
+ *        'driver'/'params' can be the following:
+ *
+ *           DRIVER: 'command'
+ *                   Use the UNIX quota command to handle quotas.
+ *           PARAMS: 'quota_path' - [string] Path to the quota binary
+ *                                  (REQUIRED)
+ *                   'grep_path' - [string] Path to the grep binary (REQUIRED)
+ *                   'partition' - [string] If all user mailboxes are on a
+ *                                 single partition, the partition label. By
+ *                                 default, quota will determine quota
+ *                                 information using the user's home directory
+ *                                 value.
+ *
+ *           DRIVER: 'hook'
+ *                   Use the quota hook to handle quotas (see
+ *                   imp/config/hooks.php).
+ *           PARAMS: 'params' - [array] Parameters to pass to the quota
+ *                              hook function.
+ *
+ *           DRIVER: 'imap'
+ *                   Use the IMAP QUOTA extension to handle quotas.
+ *                   You must be connecting to a IMAP server capable of the
+ *                   QUOTAROOT command to use this driver. This is the
+ *                   RECOMMENDED way of handling quotas if the IMAP server
+ *                   supports it.
+ *           PARAMS: NONE
+ *
+ *           DRIVER: 'maildir'
+ *                   Use Maildir++ quota files to handle quotas.
+ *           PARAMS: '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 that location. E.g.,
+ *                            '/home/~U/Maildir/' or '/var/mail/~U/Maildir/'.
+ *
+ *           DRIVER: 'mdaemon'
+ *                    Use Mdaemon servers to handle quotas.
+ *           PARAMS: 'app_location' - [string] Location of the application.
+ *
+ *           DRIVER: 'mercury32'
+ *                   Use Mercury/32 servers to handle quotas.
+ *           PARAMS: 'mail_user_folder' - [string] The path to folder mail
+ *                   mercury.
+ *
+ *           DRIVER: 'sql'
+ *                   Use arbitrary SQL queries to handle quotas.
+ *           PARAMS: 'query_quota' - (string) SQL query which returns single
+ *                   row/column with user quota (in bytes). %u is replaced
+ *                   with current user name, %U with the user name without the
+ *                   domain part, %d with the domain.
+ *                   'query_used' - (string) SQL query which returns single
+ *                   row/column with user used space (in bytes). Placeholders
+ *                   are the same like in query_quota.
+ *
+ *                   Additionally, the driver takes SQL connection parameters
+ *                   'phptype', 'hostspec',' 'username', 'password', and
+ *                   'database'. See horde/config/conf.php for further
+ *                   information on these parameters. If using the Horde DB,
+ *                   these parameters can be found in the
+ *                   $GLOBALS['conf']['sql'] variable and may be merged into
+ *                   the parameter configuration like this:
+ *
+ *                     'params' => array_merge(
+ *                         $GLOBALS['conf']['sql'],
+ *                         array(
+ *                             'query_quota' => [...],
+ *                             'query_used' => [...],
+ *                         )
+ *                     )
+ *
+ *        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'. The strings will be passed through sprintf().
+ *        These are the built-in default values, though they may appear
+ *        differently in some translations ([UNIT] will be replaced with the
+ *        value of the 'unit' parameter):
+ *          'long'          - Quota status: %.2f [UNIT] / %.2f [UNIT] (%.2f%%)
+ *          'nolimit_long'  - Quota status: %.2f [UNIT] / NO LIMIT
+ *          'short'         - %.0f%% of %.0f [UNIT]
+ *          'nolimit_short' - %.0f [UNIT]
+ *
  *
  * *** The following options should NOT be set unless you REALLY know what ***
  * *** you are doing! FOR MOST PEOPLE, AUTO-DETECTION OF THESE PARAMETERS  ***
index 43d1e8d..472c858 100644 (file)
@@ -331,7 +331,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
 
         $quota = $this->_getQuota();
         if (!is_null($quota)) {
-            $result['quota'] = $quota;
+            $result->quota = $quota;
         }
 
         return $result;
@@ -1820,11 +1820,14 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      */
     protected function _getQuota()
     {
-        if (isset($_SESSION['imp']['quota']) &&
-            is_array($_SESSION['imp']['quota'])) {
+        if (isset($_SESSION['imp']['imap']['quota']) &&
+            is_array($_SESSION['imp']['imap']['quota'])) {
             $quotadata = IMP::quotaData(false);
             if (!empty($quotadata)) {
-                return array('p' => round($quotadata['percent']), 'm' => $quotadata['message']);
+                return array(
+                    'm' => $quotadata['message'],
+                    'p' => round($quotadata['percent'])
+                );
             }
         }
 
index 48ef92e..734f493 100644 (file)
@@ -578,19 +578,23 @@ class IMP
      */
     static public function quotaData($long = true)
     {
-        if (!isset($_SESSION['imp']['quota']) ||
-            !is_array($_SESSION['imp']['quota'])) {
+        if (!isset($_SESSION['imp']['imap']['quota']) ||
+            !is_array($_SESSION['imp']['imap']['quota'])) {
             return false;
         }
 
         try {
-            $quotaDriver = IMP_Quota::singleton($_SESSION['imp']['quota']['driver'], $_SESSION['imp']['quota']['params']);
+            $quotaDriver = IMP_Quota::singleton($_SESSION['imp']['imap']['quota']['driver'], isset($_SESSION['imp']['imap']['quota']['params']) ? $_SESSION['imp']['imap']['quota']['params'] : array());
             $quota = $quotaDriver->getQuota();
         } catch (Horde_Exception $e) {
             Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
             return false;
         }
 
+        if (empty($quota)) {
+            return false;
+        }
+
         $strings = $quotaDriver->getMessages();
         list($calc, $unit) = $quotaDriver->getUnit();
         $ret = array('percent' => 0);
index aa8183f..fec3d71 100644 (file)
@@ -7,13 +7,15 @@
  * authentication and file servers (e.g. via NIS/NFS).  And last, it (as
  * written) requires the POSIX PHP extensions.
  *
- * You must configure this driver in horde/imp/config/servers.php.  The
- * driver supports the following parameters:
- *   'quota_path' => Path to the quota binary - REQUIRED
- *   'grep_path'  => Path to the grep binary - REQUIRED
- *   'partition'  => If all user mailboxes are on a single partition, the
- *                   partition label.  By default, quota will determine
- *                   quota information using the user's home directory value.
+ * You must configure this driver in imp/config/servers.php.  The driver
+ * supports the following parameters:
+ * <pre>
+ * 'grep_path' - (string) [REQUIRD] Path to the grep binary.
+ * 'partition' - (string) If all user mailboxes are on a single partition, the
+ *               partition label.  By default, quota will determine quota
+ *               information using the user's home directory value.
+ * 'quota_path' - (string) [REQUIRED] Path to the quota binary.
+ * </pre>
  *
  * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
  *
index 526018e..e1976f7 100644 (file)
@@ -1,14 +1,13 @@
 <?php
 /**
  * Implementation of IMP_Quota API for a generic hook function.  This
- * requires hook_get_quota to be set in config/hooks.php .  The
- * function takes an array as argument and returns an array where the
- * first item is the disk space used in bytes and the second the
- * maximum diskspace in bytes.  See there for an example.
+ * requires the quota hook to be set in config/hooks.php.
  *
- * You must configure this driver in horde/imp/config/servers.php.  The
- * driver supports the following parameters:
- *   'params' => Array of parameters to pass to the quota function.
+ * You must configure this driver in imp/config/servers.php.  The driver
+ * supports the following parameters:
+ * <pre>
+ * 'params' - (array) Parameters to pass to the quota function.
+ * </pre>
  *
  * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
  *
index cfedb0e..ad5c157 100644 (file)
@@ -2,6 +2,9 @@
 /**
  * Implementation of the IMP_Quota API for IMAP servers.
  *
+ * You must configure this driver in imp/config/servers.php.  The driver does
+ * not require any parameters.
+ *
  * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (GPL). If you
@@ -28,8 +31,15 @@ class IMP_Quota_Imap extends IMP_Quota
             throw new Horde_Exception(_("Unable to retrieve quota"), 'horde.error');
         }
 
+        if (empty($quota)) {
+            return array();
+        }
+
         $quota_val = reset($quota);
-        return array('usage' => $quota['storage']['usage'] * 1024, 'limit' => $quota['storage']['limit'] * 1024);
+        return array(
+            'usage' => $quota_val['storage']['usage'] * 1024,
+            'limit' => $quota_val['storage']['limit'] * 1024
+        );
     }
 
 }
diff --git a/imp/lib/Quota/Logfile.php b/imp/lib/Quota/Logfile.php
deleted file mode 100644 (file)
index 0afd2ca..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-/**
- * Implementation of the Quota API for servers where IMAP Quota is not
- * supported, but it appears in the servers messages log for the IMAP
- * server.
- *
- * Requires the following parameter settings in imp/servers.php:
- * <pre>
- * 'quota' => array(
- *     'driver' => 'logfile',
- *     'params' => array(
- *         'logfile' => '/path/to/log/file',
- *         'taillines' => 10,
- *         'FTPmail'   => 'FTP',
- *         'beginocc'  => 'usage = ',
- *         'midocc'    => ' of ',
- *         'endocc'    => ' bytes'
- *     )
- * );
- *
- * logfile - The path/to/filename of the log file to use.
- * taillines - The number of lines to look at in the tail of the logfile.
- * FTPmail - If you want to show what FTP space is available (IMAP folder)
- *           or what mail space is available (INBOX).
- *           Defines the search string to username:
- *             FTPmail to identify the line with QUOTA info.
- * beginocc - String that designates the characters before the usage
- *            number.
- * midocc - String between usage and total storage space.
- * endocc - String after the storage number.
- * </pre>
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Tim Gorter <email@teletechnics.co.nz>
- * @package IMP
- */
-class IMP_Quota_Logfile extends IMP_Quota
-{
-    /**
-     * Constructor
-     *
-     * @param array $params  Hash containing connection parameters.
-     */
-    protected function __construct($params = array())
-    {
-        parent::__construct(array_merge(array(
-            'logfile' => '',
-            'taillines' => 10,
-            'FTPmail' => 'FTP',
-            'beginocc' => 'usage = ',
-            'midocc' => ' of ',
-            'endocc' => ' bytes'
-        ), $params));
-    }
-
-    /**
-     * Get 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)
-     * @throws Horde_Exception
-     */
-    public function getQuota()
-    {
-        if (!is_file($this->_params['logfile'])) {
-            throw new Horde_Exception(_("Unable to retrieve quota"), 'horde.error');
-        }
-
-        $full = file($this->_params['logfile']);
-        for (; $this->_params['taillines'] > 0; --$this->_params['taillines']) {
-            $tail[] = $full[count($full) - $this->_params['taillines']];
-        }
-
-        $uname = $_SESSION['imp']['user'];
-        $FTPmail = $this->_params['FTPmail'];
-        $virtline = preg_grep("[$uname: $FTPmail]", $tail);
-        $virtline = array_values($virtline);
-        $usage = substr($virtline[0], strpos($virtline[0], $this->_params['beginocc']) + strlen($this->_params['beginocc']), strpos($virtline[0], $this->_params['midocc']));
-        $storage  = substr($virtline[0], strpos($virtline[0], $this->_params['midocc']) + strlen($this->_params['midocc']), strpos($virtline[0], $this->_params['endocc']));
-
-        return array('usage' => $usage, 'limit' => $storage);
-    }
-
-}
index 9a88930..990317d 100644 (file)
@@ -5,22 +5,17 @@
  * expanded to be configurable to support storage or message limits in the
  * configuration array.
  *
- * Requires the following parameter settings in imp/servers.php:
+ * You must configure this driver in imp/config/servers.php.  The driver
+ * supports the following parameters:
  * <pre>
- * 'quota' => array(
- *     'driver' => 'maildir',
- *     'params' => array(
- *         'path' => '/path/to/users/Maildir'
- *         // TODO: Add config param for storage vs message quota
- *     )
- * );
- *
- * path - The path to the user's Maildir directory. You may use the
+ * 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 that location.
  *        E.g., '/home/~U/Maildir/' or '/var/mail/~U/Maildir/'
  * </pre>
  *
+ * TODO: Add config param for storage vs message quota
+ *
  * Copyright 2007-2010 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (GPL). If you
@@ -57,8 +52,7 @@ class IMP_Quota_Maildir extends IMP_Quota
         $full = $this->_params['path'] . '/maildirsize';
 
         // Substitute the username in the string if needed.
-        $uname = $_SESSION['imp']['user'];
-        $full = str_replace('~U', $uname, $full);
+        $full = str_replace('~U', $GLOBALS['imp_imap']->ob()->getParam('username'), $full);
 
         // Read in the quota file and parse it, if possible.
         if (!is_file($full)) {
index de53b4e..30c9dd5 100644 (file)
@@ -2,9 +2,10 @@
 /**
  * Implementation of the Quota API for MDaemon servers.
  *
- * Parameters required:
+ * You must configure this driver in imp/config/servers.php.  The driver
+ * supports the following parameters:
  * <pre>
- * 'app_location'  --  TODO
+ * 'app_location' - (string) Location of the application.
  * </pre>
  *
  * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
index 73d6a9d..4a4cc99 100644 (file)
@@ -3,16 +3,10 @@
  * Implementation of the Quota API for Mercury/32 IMAP servers.
  * For reading Quota, read size folder user.
  *
- * Requires the following parameter settings in imp/servers.php:
+ * You must configure this driver in imp/config/servers.php.  The driver
+ * supports the following parameters:
  * <pre>
- * 'quota' => array(
- *     'driver' => 'mercury32',
- *     'params' => array(
- *         'mail_user_folder' => 'c:/mercry/mail'
- *     )
- * );
- *
- * 'mail_user_folder' --  The path to folder mail mercury
+ * 'mail_user_folder' - (string) The path to folder mail mercury.
  * </pre>
  *
  *****************************************************************************
index 90d62aa..95a326e 100644 (file)
@@ -3,34 +3,21 @@
  * Implementation of the Quota API for servers keeping quota information in a
  * custom SQL database.
  *
- * Driver must be configured in imp/config/servers.php. Parameters supported:
+ * You must configure this driver in imp/config/servers.php.  The driver
+ * supports the following parameters:
  * <pre>
- * phptype     -- Database type to connect to
- * hostspec    -- Database host
- * username    -- User name for DB connection
- * password    -- Password for DB connection
- * database    -- Database name
- * query_quota -- SQL query which returns single row/column with user quota
- *                (in bytes). %u is replaced with current user name, %U with
- *                the user name without the domain part, %d with the domain.
- * query_used  -- SQL query which returns single row/column with user used
- *                space (in bytes). Placeholders are the same like in
- *                query_quota.
+ * query_quota - (string) SQL query which returns single row/column with user
+ *               quota (in bytes). %u is replaced with current user name, %U
+ *               with the user name without the domain part, %d with the
+ *               domain.
+ * query_used - (string) SQL query which returns single row/column with user
+ *              used space (in bytes). Placeholders are the same like in
+ *              query_quota.
  * </pre>
  *
- * Example how to reuse Horde's global SQL configuration:
- * <code>
- * 'quota' => array(
- *     'driver' => 'sql',
- *     'params' => array_merge(
- *         $GLOBALS['conf']['sql'],
- *         array(
- *             'query_quota' => 'SELECT quota FROM quotas WHERE user = ?',
- *             'query_used' => 'SELECT used FROM quotas WHERE user = ?'
- *         )
- *     )
- * ),
- * </code>
+ * Additionally, the driver takes SQL connection parameters 'phptype',
+ * 'hostspec',' 'username', 'password', and 'database'. See
+ * horde/config/conf.php for further information on these parameters
  *
  * Copyright 2006-2007 Tomas Simonaitis <haden@homelan.lt>
  * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
index bd2aceb..f1415ae 100644 (file)
@@ -15,7 +15,7 @@ $has_blacklist = $registry->hasMethod('mail/blacklistFrom');
 $has_whitelist = $registry->hasMethod('mail/whitelistFrom');
 
 // Quota information
-$show_quota = (isset($_SESSION['imp']['quota']) && is_array($_SESSION['imp']['quota']));
+$show_quota = (isset($_SESSION['imp']['imap']['quota']) && is_array($_SESSION['imp']['imap']['quota']));
 
 // Get the list of available IMAP flags
 $flag_list = $injector->getInstance('IMP_Imap_Flags')->getList(array('imap' => true));
@@ -137,14 +137,14 @@ function _simpleButton($id, $text, $image, $nodisplay = false)
 <?php endforeach; ?>
 <?php if ($show_quota): ?>
         <li id="quota">
-         <span class="used"><span class="iconImg"></span></span>
+         <span class="used"><?php echo Horde::img('quotauncover.gif', '', '', $registry->get('webroot', 'imp') . '/themes/graphics') ?></span>
         </li>
 <?php endif; ?>
        </ul>
       </div>
 <?php elseif ($show_quota): ?>
       <div id="quota">
-       <span class="used"><span class="iconImg"></span></span>
+        <span class="used"><?php echo Horde::img('quotauncover.gif', '', '', $registry->get('webroot', 'imp') . '/themes/graphics') ?></span>
       </div>
 <?php endif; ?>
      </div>
index f73452e..ed9d9f9 100644 (file)
@@ -47,7 +47,6 @@ input {
     border: 1px #000 solid;
     margin-right: 2px;
 }
-/* TODO? */
 #quota .used img {
     display: inline;
     float: none;
@@ -55,6 +54,9 @@ input {
     border-left: 1px #000 solid;
     height: 14px;
 }
+.tabset li#quota {
+    border-top: 0;
+}
 
 #logo {
     display: none;
@@ -341,11 +343,12 @@ div.vpRowVert.flagUnseen {
     padding-left: 10px;
 }
 #sidebar span.iconSpan {
+    background-position: left center;
+    background-repeat: no-repeat;
     display: inline;
     float: left;
-    width: 20px;
     height: 100%;
-    background-repeat: no-repeat;
+    width: 20px;
 }
 #ctx_folder_sub span.contextImg, #ctx_folder_unsub span.contextImg, #ctx_folderopts_sub span.contextImg, #ctx_folderopts_unsub span.contextImg {
     background-image: url("graphics/folders/folder.png");
@@ -1021,11 +1024,6 @@ div.msgSubject span.treeImg {
     margin-left: 4px;
     margin-right: 0;
 }
-#quota span.iconImg {
-    background-image: url("graphics/quotauncover.gif");
-    width: 0;
-    margin-right: 0;
-}
 #th_expand span.iconImg, #partlist_col, #msgloglist_col {
     background-image: url("graphics/arrow_collapsed.png");
     cursor: pointer;