SESSION->imp->user does not exist anymore
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 8 Oct 2010 21:00:58 +0000 (15:00 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 8 Oct 2010 21:01:50 +0000 (15:01 -0600)
imp/config/backends.php.dist
imp/config/hooks.php.dist
imp/lib/Injector/Factory/Quota.php
imp/lib/Quota/Base.php
imp/lib/Quota/Command.php
imp/lib/Quota/Maildir.php
imp/lib/Quota/Mdaemon.php
imp/lib/Quota/Mercury32.php
imp/lib/Quota/Sql.php

index 2c238cf..8cdd94f 100644 (file)
  *           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.
+ *           PARAMS: Any parameters defined here will be passed to the quota
+ *                   hook function.
  *
  *           DRIVER: 'imap'
  *                   Use the IMAP QUOTA extension to handle quotas.
index dd626b2..9cd91a0 100644 (file)
@@ -612,10 +612,14 @@ class IMP_Hooks
 //    {
 //        // Example #1: Sample function for returning the quota.
 //        // Uses the PECL ssh2 extension.
-//        $host = $_SESSION['imp']['server'];
-//        $user = $_SESSION['imp']['user'];
-//        $pass = $GLOBALS['registry']->getAuthCredential('password');
-//        $command = $params[0];
+//        // Requires the 'command' parameter to be defined in backends.php,
+//        // which defines the quota reporting function to run on the SSH
+//        // host.
+//        $imap_ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create();
+//        $host = $imap_ob->ob->getParam('hostspec');
+//        $user = $params['host'];
+//        $pass = $imap_ob->ob->getParam('password');
+//        $command = $params['command'];
 //
 //        $session = ssh2_connect($host);
 //        if (!$session) {
index 3128fe1..29d85ec 100644 (file)
@@ -54,15 +54,13 @@ class IMP_Injector_Factory_Quota
                 : IMP::$mailbox;
             break;
 
-        case 'maildir':
-            $params['username'] = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->getParam('username');
-            break;
-
         case 'sql':
             $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('imp', $params);
             break;
         }
 
+        $params['username'] = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->getParam('username');
+
         return IMP_Quota::factory($driver, $params);
     }
 
index 5138824..584bf6c 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 /**
- * The IMP_Quota_Base:: class is the abstract class that all driver
+ * The IMP_Quota_Base:: class is the abstract class that all drivers inherit
+ * from.
  *
  * Copyright 2010 The Horde Project (http://www.horde.org/)
  *
@@ -34,6 +35,7 @@ abstract class IMP_Quota_Base
      *            strings will be passed through sprintf().
      * 'unit' - (string) What storage unit the quota messages should be
      *          displayed in. Either 'GB', 'MB', or 'KB'.
+     * 'username' - (string) The username to query.
      * </pre>
      */
     public function __construct(array $params = array())
index 624d1d9..75623e1 100644 (file)
@@ -73,12 +73,12 @@ class IMP_Quota_Command extends IMP_Quota_Base
     public function getQuota()
     {
         if (empty($this->_params['partition'])) {
-            $passwd_array = posix_getpwnam($_SESSION['imp']['user']);
+            $passwd_array = posix_getpwnam($this->_params['username']);
             list($junk, $search_string, $junk) = explode('/', $passwd_array['dir']);
         } else {
             $search_string = $this->_params['partition'];
         }
-        $cmdline = $this->_params['quota_path'] . ' -u ' . escapeshellarg($_SESSION['imp']['user']) . ' | ' . escapeshellcmd($this->_params['grep_path']) . ' ' . escapeshellarg($search_string);
+        $cmdline = $this->_params['quota_path'] . ' -u ' . escapeshellarg($this->_params['username']) . ' | ' . escapeshellcmd($this->_params['grep_path']) . ' ' . escapeshellarg($search_string);
         exec($cmdline, $quota_data, $return_code);
         if (($return_code == 0) && (count($quota_data) == 1)) {
             $quota = split("[[:blank:]]+", trim($quota_data[0]));
index ed6e2bb..094366c 100644 (file)
@@ -29,16 +29,13 @@ class IMP_Quota_Maildir extends IMP_Quota_Base
      *          that location.
      *          E.g., '/home/~U/Maildir/' or '/var/mail/~U/Maildir/'
      *          DEFAULT: ''
-     * 'username' - (string) Username to substitute into the string.
-     *              DEFAULT: none
      * </pre>
      */
     public function __construct($params = array())
     {
         parent::__construct(array_merge(array(
             'msg_count' => false,
-            'path' => '',
-            'username' => ''
+            'path' => ''
         ), $params));
     }
 
index 4724f49..643401b 100644 (file)
@@ -43,7 +43,11 @@ class IMP_Quota_Mdaemon extends IMP_Quota_Base
      */
     public function getQuota()
     {
-        $userDetails = $this->_getUserDetails($_SESSION['imp']['user'], $_SESSION['imp']['maildomain']);
+        $imap_ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create();
+        $userDetails = $this->_getUserDetails(
+            $this->_params['username'],
+            $_SESSION['imp']['maildomain']
+        );
 
         if ($userDetails !== false) {
             $userHome = trim(substr($userDetails, 105, 90));
index c0608d7..a1bb68c 100644 (file)
@@ -65,7 +65,7 @@ class IMP_Quota_Mercury32 extends IMP_Quota_Base
         $quota = 0;
 
         try {
-            $di = new DirectoryIterator($this->_params['mail_user_folder'] . '/' . $_SESSION['imp']['user'] . '/');
+            $di = new DirectoryIterator($this->_params['mail_user_folder'] . '/' . $this->_params['username'] . '/');
         } catch (UnexpectedValueException $e) {
             throw new IMP_Exception(_("Unable to retrieve quota"));
         }
index 0ab7e10..f8706b1 100644 (file)
@@ -69,7 +69,6 @@ class IMP_Quota_Sql extends IMP_Quota_Base
      */
     public function getQuota()
     {
-        $user = $_SESSION['imp']['user'];
         $quota = array(
             'limit' => 0,
             'usage' => 0
@@ -78,10 +77,10 @@ class IMP_Quota_Sql extends IMP_Quota_Base
         if (empty($this->_params['query_quota'])) {
             Horde::logMessage(__CLASS__ . ': query_quota SQL query not set.', 'ERR');
         } else {
-            @list($bare_user, $domain) = explode('@', $user, 2);
+            @list($bare_user, $domain) = explode('@', $this->_params['username'], 2);
             $query = str_replace(array('?', '%u', '%U', '%d'),
-                                 array($this->_db->quote($user),
-                                       $this->_db->quote($user),
+                                 array($this->_db->quote($this->_params['username']),
+                                       $this->_db->quote($this->_params['username']),
                                        $this->_db->quote($bare_user),
                                        $this->_db->quote($domain)),
                                  $this->_params['query_quota']);
@@ -97,10 +96,10 @@ class IMP_Quota_Sql extends IMP_Quota_Base
         if (empty($this->_params['query_used'])) {
             Horde::logMessage(__CLASS__ . ': query_used SQL query not set.', 'ERR');
         } else {
-            @list($bare_user, $domain) = explode('@', $user, 2);
+            @list($bare_user, $domain) = explode('@', $this->_params['username'], 2);
             $query = str_replace(array('?', '%u', '%U', '%d'),
-                                 array($this->_db->quote($user),
-                                       $this->_db->quote($user),
+                                 array($this->_db->quote($this->_params['username']),
+                                       $this->_db->quote($this->_params['username']),
                                        $this->_db->quote($bare_user),
                                        $this->_db->quote($domain)),
                                  $this->_params['query_used']);