Move imp_imap from global to an injectable
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 27 Apr 2010 05:27:54 +0000 (23:27 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 29 Apr 2010 17:18:59 +0000 (11:18 -0600)
33 files changed:
imp/folders.php
imp/lib/Ajax/Application.php
imp/lib/Api.php
imp/lib/Application.php
imp/lib/Auth.php
imp/lib/Block/Newmail.php
imp/lib/Compose.php
imp/lib/Contents.php
imp/lib/Filter.php
imp/lib/Folder.php
imp/lib/IMP.php
imp/lib/Imap.php
imp/lib/Imap/Acl.php
imp/lib/Imap/Flags.php
imp/lib/Imap/Tree.php
imp/lib/Injector/Binder/Imap.php [new file with mode: 0644]
imp/lib/Injector/Factory/Imap.php [new file with mode: 0644]
imp/lib/Mailbox.php
imp/lib/Message.php
imp/lib/Notification/Handler/Decorator/Imap.php
imp/lib/Prefs/Ui.php
imp/lib/Quota/Imap.php
imp/lib/Quota/Maildir.php
imp/lib/Search.php
imp/lib/Spam.php
imp/lib/Ui/Block.php
imp/lib/Ui/Message.php
imp/lib/Views/ListMessages.php
imp/lib/Views/ShowMessage.php
imp/mailbox.php
imp/message-mimp.php
imp/message.php
imp/thread.php

index 6c21a91..66614e1 100644 (file)
@@ -253,7 +253,7 @@ case 'folders_empty_mailbox_confirm':
             }
 
             try {
-                $elt_info = $imp_imap->ob()->status($val, Horde_Imap_Client::STATUS_MESSAGES);
+                $elt_info = $injector->getInstance('IMP_Imap')->getOb()->status($val, Horde_Imap_Client::STATUS_MESSAGES);
             } catch (Horde_Imap_Client_Exception $e) {
                 $elt_info = null;
             }
@@ -420,7 +420,7 @@ if (!empty($newmsgs)) {
     /* Open the mailbox R/W so we ensure the 'recent' flags are cleared from
      * the current mailbox. */
     foreach ($newmsgs as $mbox => $nm) {
-        $imp_imap->ob()->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE);
+        $injector->getInstance('IMP_Imap')->getOb()->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE);
     }
 
     IMP::newmailAlerts($newmsgs);
index 27a02fa..27764db 100644 (file)
@@ -366,7 +366,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         $result = new stdClass;
         $result->poll = array();
 
-        foreach ($GLOBALS['imp_imap']->ob()->statusMultiple($GLOBALS['injector']->getInstance('IMP_Imap_Tree')->getPollList(), Horde_Imap_Client::STATUS_UNSEEN) as $key => $val) {
+        foreach ($GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->statusMultiple($GLOBALS['injector']->getInstance('IMP_Imap_Tree')->getPollList(), Horde_Imap_Client::STATUS_UNSEEN) as $key => $val) {
             $result->poll[$key] = intval($val['unseen']);
         }
 
@@ -420,7 +420,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         if ($this->_vars->add) {
             $imptree->addPollList($this->_vars->view);
             try {
-                if ($info = $GLOBALS['imp_imap']->ob()->status($this->_vars->view, Horde_Imap_Client::STATUS_UNSEEN)) {
+                if ($info = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->status($this->_vars->view, Horde_Imap_Client::STATUS_UNSEEN)) {
                     $result->poll = array($this->_vars->view => intval($info['unseen']));
                 }
             } catch (Horde_Imap_Client_Exception $e) {}
@@ -526,7 +526,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      */
     public function moveMessages()
     {
-        $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($this->_vars->uid);
+        $indices = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->fromSequenceString($this->_vars->uid);
         if (!$this->_vars->mboxto || empty($indices)) {
             return false;
         }
@@ -580,7 +580,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      */
     public function copyMessages()
     {
-        $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($this->_vars->uid);
+        $indices = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->fromSequenceString($this->_vars->uid);
         if (!$this->_vars->mboxto || empty($indices)) {
             return false;
         }
@@ -615,7 +615,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      */
     public function flagMessages()
     {
-        $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($this->_vars->uid);
+        $indices = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->fromSequenceString($this->_vars->uid);
         if (!$this->_vars->flags || empty($indices)) {
             return false;
         }
@@ -676,7 +676,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      */
     public function deleteMessages()
     {
-        $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($this->_vars->uid);
+        $indices = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->fromSequenceString($this->_vars->uid);
         if (empty($indices)) {
             return false;
         }
@@ -738,7 +738,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
     public function reportSpam()
     {
         $change = $this->_changed(false);
-        $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($this->_vars->uid);
+        $indices = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->fromSequenceString($this->_vars->uid);
         $result = false;
 
         if (IMP_Spam::reportSpam($indices, $this->_vars->spam ? 'spam' : 'notspam')) {
@@ -770,7 +770,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      */
     public function blacklist()
     {
-        $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($this->_vars->uid);
+        $indices = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->fromSequenceString($this->_vars->uid);
         if (empty($indices)) {
             return false;
         }
@@ -820,7 +820,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      */
     public function showPreview()
     {
-        $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($this->_vars->uid);
+        $indices = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->fromSequenceString($this->_vars->uid);
         if (count($indices) != 1) {
             return false;
         }
@@ -843,7 +843,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             /* We know we are going to be exclusively dealing with this
              * mailbox, so select it on the IMAP server (saves some STATUS
              * calls). Open R/W to clear the RECENT flag. */
-            $GLOBALS['imp_imap']->ob()->openMailbox($ptr['key'], Horde_Imap_Client::OPEN_READWRITE);
+            $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->openMailbox($ptr['key'], Horde_Imap_Client::OPEN_READWRITE);
             $show_msg = new IMP_Views_ShowMessage();
             $result->preview = (object)$show_msg->showMessage($args);
             if (isset($result->preview->error)) {
@@ -1205,7 +1205,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      */
     public function purgeDeleted()
     {
-        $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($this->_vars->uid);
+        $indices = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->fromSequenceString($this->_vars->uid);
         $change = $this->_changed($indices);
 
         if (is_null($change)) {
@@ -1258,7 +1258,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         }
 
         try {
-            $fetch_ret = $GLOBALS['imp_imap']->ob()->fetch($this->_vars->view, array(
+            $fetch_ret = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->fetch($this->_vars->view, array(
                 Horde_Imap_Client::FETCH_HEADERTEXT => array(array('parse' => true, 'peek' => false))
             ), array('ids' => array($this->_vars->uid)));
         } catch (Horde_Imap_Client_Exception $e) {
@@ -1537,7 +1537,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
     {
         $imp_compose = $GLOBALS['injector']->getInstance('IMP_Compose')->getOb($this->_vars->imp_compose);
         if (!($imp_contents = $imp_compose->getContentsOb())) {
-            $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($this->_vars->uid);
+            $indices = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->fromSequenceString($this->_vars->uid);
             $i = each($indices);
             $imp_contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($i['key'], reset($i['value']));
         }
@@ -1597,7 +1597,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
     protected function _checkUidvalidity($result = false)
     {
         try {
-            $GLOBALS['imp_imap']->checkUidvalidity($this->_vars->view);
+            $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->checkUidvalidity($this->_vars->view);
         } catch (IMP_Exception $e) {
             if (!is_object($result)) {
                 $result = new stdClass;
@@ -1633,7 +1633,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
     {
         $del = new stdClass;
         $del->mbox = $this->_vars->view;
-        $del->uids = $GLOBALS['imp_imap']->ob()->utils->toSequenceString($indices, array('mailbox' => true));
+        $del->uids = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->toSequenceString($indices, array('mailbox' => true));
         $del->remove = intval($GLOBALS['prefs']->getValue('hide_deleted') ||
                               $GLOBALS['prefs']->getValue('use_trash'));
 
@@ -1688,7 +1688,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
          * on the IMAP server (saves some STATUS calls). */
         if (!is_null($rw)) {
             try {
-                $GLOBALS['imp_imap']->ob()->openMailbox($this->_vars->view, $rw ? Horde_Imap_Client::OPEN_READWRITE : Horde_Imap_Client::OPEN_AUTO);
+                $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->openMailbox($this->_vars->view, $rw ? Horde_Imap_Client::OPEN_READWRITE : Horde_Imap_Client::OPEN_AUTO);
             } catch (Horde_Imap_Client_Exception $e) {
                 $GLOBALS['notification']->push($e);
                 return null;
@@ -1767,7 +1767,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         }
 
         try {
-            $count = ($info = $GLOBALS['imp_imap']->ob()->status($mbox, Horde_Imap_Client::STATUS_UNSEEN))
+            $count = ($info = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->status($mbox, Horde_Imap_Client::STATUS_UNSEEN))
                 ? intval($info['unseen'])
                 : 0;
         } catch (Horde_Imap_Client_Exception $e) {
index 2b06a58..1d05a03 100644 (file)
@@ -82,7 +82,7 @@ class IMP_Api extends Horde_Registry_Api
      */
     public function createFolder($folder)
     {
-        $fname = $GLOBALS['imp_imap']->appendNamespace($folder);
+        $fname = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->appendNamespace($folder);
         return $GLOBALS['injector']->getInstance('IMP_Folder')->create($fname, $GLOBALS['prefs']->getValue('subscribe'))
             ? $fname
             : false;
@@ -204,7 +204,7 @@ class IMP_Api extends Horde_Registry_Api
      */
     public function imapOb($mailbox, $indices)
     {
-        return $GLOBALS['imp_imap']->ob();
+        return $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->ob;
     }
 
     /**
index 54d53f0..a235256 100644 (file)
@@ -84,7 +84,6 @@ class IMP_Application extends Horde_Registry_Application
      * Initialization function.
      *
      * Global variables defined:
-     *   $imp_imap     - An IMP_Imap object
      *   $imp_mbox     - Current mailbox information
      */
     protected function _init()
@@ -97,6 +96,7 @@ class IMP_Application extends Horde_Registry_Application
             'IMP_Crypt_Smime' => new IMP_Injector_Binder_Smime(),
             'IMP_Folder' => new IMP_Injector_Binder_Folder(),
             'IMP_Identity' => new IMP_Injector_Binder_Identity(),
+            'IMP_Imap' => new IMP_Injector_Binder_Imap(),
             'IMP_Imap_Tree' => new IMP_Injector_Binder_Imaptree(),
             'IMP_Mailbox' => new IMP_Injector_Binder_Mailbox(),
             'IMP_Quota' => new IMP_Injector_Binder_Quota(),
@@ -108,9 +108,6 @@ class IMP_Application extends Horde_Registry_Application
             $GLOBALS['injector']->addBinder($key, $val);
         }
 
-        // Initialize global $imp_imap object.
-        $GLOBALS['imp_imap'] = new IMP_Imap();
-
         // Set default message character set.
         if ($def_charset = $GLOBALS['prefs']->getValue('default_msg_charset')) {
             Horde_Mime_Part::$defaultCharset = $def_charset;
index 5b4b721..bccea81 100644 (file)
@@ -41,8 +41,10 @@ class IMP_Auth
             throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED);
         }
 
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+
         // Check for valid IMAP Client object.
-        if (!$GLOBALS['imp_imap']->ob()) {
+        if (!$imp_imap->ob) {
             if (!isset($credentials['userId']) ||
                 !isset($credentials['password'])) {
                 throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
@@ -59,14 +61,14 @@ class IMP_Auth
                 return true;
             }
 
-            if (!$GLOBALS['imp_imap']->createImapObject($credentials['userId'], $credentials['password'], $credentials['server'])) {
+            if (!$imp_imap->createImapObject($credentials['userId'], $credentials['password'], $credentials['server'])) {
                 self::_logMessage('failed');
                 throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED);
             }
         }
 
         try {
-            $GLOBALS['imp_imap']->ob()->login();
+            $imp_imap->login();
         } catch (Horde_Imap_Client_Exception $e) {
             self::_logMessage($e->getMessage(), 'ERR');
             if ($e->getCode() == Horde_Imap_Client_Exception::SERVER_CONNECT) {
@@ -139,7 +141,7 @@ class IMP_Auth
         }
 
         $auth_id = Horde_Auth::getAuth();
-        $imap_ob = $GLOBALS['imp_imap']->ob();
+        $imap_ob = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
 
         $msg = sprintf(
             $status_msg . '%s [%s]%s to {%s:%s [%s]}',
@@ -204,7 +206,7 @@ class IMP_Auth
         );
 
         /* Load the server configuration. */
-        $ptr = $GLOBALS['imp_imap']->loadServerConfig($credentials['server']);
+        $ptr = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->loadServerConfig($credentials['server']);
         if ($ptr === false) {
             throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED);
         }
@@ -286,7 +288,7 @@ class IMP_Auth
      */
     static protected function _canAutoLogin($server_key = null, $force = false)
     {
-        if (($servers = $GLOBALS['imp_imap']->loadServerConfig()) === false) {
+        if (($servers = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->loadServerConfig()) === false) {
             return false;
         }
 
@@ -380,7 +382,8 @@ class IMP_Auth
 
         $sess = &$_SESSION['imp'];
 
-        $ptr = $GLOBALS['imp_imap']->loadServerConfig($sess['server_key']);
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+        $ptr = $imp_imap->loadServerConfig($sess['server_key']);
         if ($ptr === false) {
             throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED);
         }
@@ -414,7 +417,7 @@ class IMP_Auth
             }
 
             /* Set the IMAP threading algorithm. */
-            $sess['imap']['thread'] = in_array(isset($ptr['thread']) ? strtoupper($ptr['thread']) : 'REFERENCES', $GLOBALS['imp_imap']->ob()->queryCapability('THREAD'))
+            $sess['imap']['thread'] = in_array(isset($ptr['thread']) ? strtoupper($ptr['thread']) : 'REFERENCES', $imp_imap->queryCapability('THREAD'))
                 ? 'REFERENCES'
                 : 'ORDEREDSUBJECT';
         }
index 3738a8a..0352bd1 100644 (file)
@@ -33,7 +33,7 @@ class IMP_Block_Newmail extends Horde_Block
             $shown = empty($this->_params['msgs_shown']) ? 3 : $this->_params['msgs_shown'];
 
             try {
-                $fetch_ret = $GLOBALS['imp_imap']->ob()->fetch('INBOX', array(
+                $fetch_ret = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->fetch('INBOX', array(
                     Horde_Imap_Client::FETCH_ENVELOPE => true
                 ), array('ids' => array_slice($ids, 0, $shown)));
                 reset($fetch_ret);
index 33c0754..ca22d98 100644 (file)
@@ -237,14 +237,15 @@ class IMP_Compose
         /* Add information necessary to log replies/forwards when finally
          * sent. */
         if ($this->getMetadata('reply_type')) {
+            $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
             try {
-                $imap_url = $GLOBALS['imp_imap']->ob()->utils->createUrl(array(
+                $imap_url = $imp_imap->getUtils()->createUrl(array(
                     'type' => $_SESSION['imp']['protocol'],
-                    'username' => $GLOBALS['imp_imap']->ob()->getParam('username'),
-                    'hostspec' => $GLOBALS['imp_imap']->ob()->getParam('hostspec'),
+                    'username' => $imp_imap->getParam('username'),
+                    'hostspec' => $imp_imap->getParam('hostspec'),
                     'mailbox' => $this->getMetadata('mailbox'),
                     'uid' => $this->getMetadata('uid'),
-                    'uidvalidity' => $GLOBALS['imp_imap']->checkUidvalidity($this->getMetadata('mailbox'))
+                    'uidvalidity' => $imp_imap->checkUidvalidity($this->getMetadata('mailbox'))
                 ));
 
                 switch ($this->getMetadata('reply_type')) {
@@ -304,7 +305,7 @@ class IMP_Compose
 
         /* Add the message to the mailbox. */
         try {
-            $ids = $GLOBALS['imp_imap']->ob()->append($drafts_mbox, array(array('data' => $data, 'flags' => $append_flags)));
+            $ids = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->append($drafts_mbox, array(array('data' => $data, 'flags' => $append_flags)));
 
             if ($old_uid) {
                 $GLOBALS['injector']->getInstance('IMP_Message')->delete(array($old_uid), array('nuke' => true));
@@ -392,15 +393,16 @@ class IMP_Compose
         }
 
         if ($val) {
-            $imap_url = $GLOBALS['imp_imap']->ob()->utils->parseUrl(rtrim(ltrim($val, '<'), '>'));
+            $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+            $imap_url = $imp_imap->getUtils()->parseUrl(rtrim(ltrim($val, '<'), '>'));
 
             try {
                 if (($imap_url['type'] == $_SESSION['imp']['protocol']) &&
-                    ($imap_url['username'] == $GLOBALS['imp_imap']->ob()->getParam('username')) &&
+                    ($imap_url['username'] == $imp_imap->getParam('username')) &&
                     // Ignore hostspec and port, since these can change
                     // even though the server is the same. UIDVALIDITY should
                     // catch any true server/backend changes.
-                    ($GLOBALS['imp_imap']->checkUidvalidity($imap_url['mailbox']) == $imap_url['uidvalidity']) &&
+                    ($imp_imap->checkUidvalidity($imap_url['mailbox']) == $imap_url['uidvalidity']) &&
                     $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($imap_url['mailbox'], $imap_url['uid'])) {
                     $this->_metadata['mailbox'] = $imap_url['mailbox'];
                     $this->_metadata['reply_type'] = $reply_type;
@@ -659,7 +661,7 @@ class IMP_Compose
             }
 
             try {
-                $GLOBALS['imp_imap']->ob()->append(Horde_String::convertCharset($opts['sent_folder'], Horde_Nls::getCharset(), 'UTF-8'), array(array('data' => $fcc, 'flags' => $flags)));
+                $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->append(Horde_String::convertCharset($opts['sent_folder'], Horde_Nls::getCharset(), 'UTF-8'), array(array('data' => $fcc, 'flags' => $flags)));
             } catch (Horde_Imap_Client_Exception $e) {
                 $notification->push(sprintf(_("Message sent successfully, but not saved to %s"), IMP::displayFolder($opts['sent_folder'])));
                 $sent_saved = false;
@@ -1281,7 +1283,7 @@ class IMP_Compose
         $subject = $h->getValue('subject');
         $header['subject'] = empty($subject)
             ? 'Re: '
-            : 'Re: ' . $GLOBALS['imp_imap']->ob()->utils->getBaseSubject($subject, array('keepblob' => true));
+            : 'Re: ' . $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->getBaseSubject($subject, array('keepblob' => true));
 
         $force = false;
         if (in_array($type, array('reply', 'reply_auto', '*'))) {
@@ -1522,7 +1524,7 @@ class IMP_Compose
 
         $header['subject'] = $h->getValue('subject');
         if (!empty($header['subject'])) {
-            $subject = $GLOBALS['imp_imap']->ob()->utils->getBaseSubject($header['subject'], array('keepblob' => true));
+            $subject = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->getBaseSubject($header['subject'], array('keepblob' => true));
             $header['title'] = _("Forward") . ': ' . $subject;
             $header['subject'] = 'Fwd: ' . $subject;
         } else {
@@ -1695,7 +1697,7 @@ class IMP_Compose
             } else {
                 $name = Horde_String::truncate($name, 80);
             }
-            return 'Fwd: ' . $GLOBALS['imp_imap']->ob()->utils->getBaseSubject($name, array('keepblob' => true));
+            return 'Fwd: ' . $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->getBaseSubject($name, array('keepblob' => true));
         } else {
             return 'Fwd: ' . sprintf(_("%u Forwarded Messages"), $attached);
         }
@@ -2713,8 +2715,9 @@ class IMP_Compose
          * current IMAP / POP3 connection are valid for SMTP authentication as
          * well. */
         if (!empty($params['auth']) && empty($params['username'])) {
-            $params['username'] = $GLOBALS['imp_imap']->ob()->getParam('username');
-            $params['password'] = $GLOBALS['imp_imap']->ob()->getParam('password');
+            $imap_ob = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+            $params['username'] = $imap_ob->getParam('username');
+            $params['password'] = $imap_ob->getParam('password');
         }
 
         return array(
index b480645..f928ae2 100644 (file)
@@ -94,7 +94,7 @@ class IMP_Contents
 
             /* Get the Horde_Mime_Part object for the given UID. */
             try {
-                $ret = $GLOBALS['imp_imap']->ob()->fetch($this->_mailbox, array(
+                $ret = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->fetch($this->_mailbox, array(
                     Horde_Imap_Client::FETCH_STRUCTURE => array('parse' => true)
                 ), array('ids' => array($this->_uid)));
             } catch (Horde_Imap_Client_Exception $e) {
@@ -148,7 +148,7 @@ class IMP_Contents
         }
 
         try {
-            $res = $GLOBALS['imp_imap']->ob()->fetch($this->_mailbox, array(
+            $res = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->fetch($this->_mailbox, array(
                 Horde_Imap_Client::FETCH_BODYTEXT => array(array('peek' => true, 'stream' => !empty($options['stream'])))
             ), array('ids' => array($this->_uid)));
             return $res[$this->_uid]['bodytext'][0];
@@ -207,7 +207,7 @@ class IMP_Contents
         }
 
         try {
-            $res = $GLOBALS['imp_imap']->ob()->fetch($this->_mailbox, $query, array('ids' => array($this->_uid)));
+            $res = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->fetch($this->_mailbox, $query, array('ids' => array($this->_uid)));
             if (empty($options['mimeheaders'])) {
                 if (!empty($res[$this->_uid]['bodypartdecode'][$id])) {
                     $this->lastBodyPartDecode = $res[$this->_uid]['bodypartdecode'][$id];
@@ -245,7 +245,7 @@ class IMP_Contents
         }
 
         try {
-            $res = $GLOBALS['imp_imap']->ob()->fetch($this->_mailbox, array(
+            $res = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->fetch($this->_mailbox, array(
                 Horde_Imap_Client::FETCH_HEADERTEXT => array(array('peek' => true)),
                 Horde_Imap_Client::FETCH_BODYTEXT => array(array('peek' => true, 'stream' => !empty($options['stream'])))
             ), array('ids' => array($this->_uid)));
@@ -279,7 +279,7 @@ class IMP_Contents
         }
 
         try {
-            $res = $GLOBALS['imp_imap']->ob()->fetch($this->_mailbox, array(
+            $res = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->fetch($this->_mailbox, array(
                 Horde_Imap_Client::FETCH_HEADERTEXT => array(array('parse' => $parse, 'peek' => true))
             ), array('ids' => array($this->_uid)));
             return $res[$this->_uid]['headertext'][0];
index ce15e8b..585dece 100644 (file)
@@ -108,10 +108,12 @@ class IMP_Filter
             return false;
         }
 
-        /* Get the list of from addresses. */
         $addr = array();
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+
+        /* Get the list of from addresses. */
         foreach ($msgList as $mbox => $msgIndices) {
-            $GLOBALS['imp_imap']->checkUidvalidity($mbox);
+            $imp_imap->checkUidvalidity($mbox);
 
             foreach ($msgIndices as $idx) {
                 $contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($mbox, $idx);
index a3bc490..8346875 100644 (file)
@@ -168,7 +168,7 @@ class IMP_Folder
             }
 
             try {
-                $GLOBALS['imp_imap']->ob()->deleteMailbox($folder);
+                $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->deleteMailbox($folder);
                 $notification->push(sprintf(_("The folder \"%s\" was successfully deleted."), IMP::displayFolder($folder)), 'horde.success');
                 $deleted[] = $folder;
             } catch (Horde_Imap_Client_Exception $e) {
@@ -244,7 +244,7 @@ class IMP_Folder
 
         /* Attempt to create the mailbox. */
         try {
-            $GLOBALS['imp_imap']->ob()->createMailbox($folder);
+            $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->createMailbox($folder);
         } catch (Horde_Imap_Client_Exception $e) {
             $notification->push(sprintf(_("The folder \"%s\" was not created. This is what the server said"), IMP::displayFolder($folder)) . ': ' . $e->getMessage(), 'horde.error');
             return false;
@@ -285,7 +285,7 @@ class IMP_Folder
         }
 
         try {
-            $ret = $GLOBALS['imp_imap']->ob()->listMailboxes($folder, array('flat' => true));
+            $ret = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->listMailboxes($folder, array('flat' => true));
             return !empty($ret);
         } catch (Horde_Imap_Client_Exception $e) {
             return false;
@@ -326,7 +326,7 @@ class IMP_Folder
         $sub_folders = $imaptree->folderList();
 
         try {
-            $GLOBALS['imp_imap']->ob()->renameMailbox($old, $new);
+            $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->renameMailbox($old, $new);
         } catch (Horde_Imap_Client_Exception $e) {
             $GLOBALS['notification']->push(sprintf(_("Renaming \"%s\" to \"%s\" failed. This is what the server said"), IMP::displayFolder($old), IMP::displayFolder($new)) . ': ' . $e->getMessage(), 'horde.error');
             return false;
@@ -370,7 +370,7 @@ class IMP_Folder
 
         foreach (array_filter($folders) as $folder) {
             try {
-                $GLOBALS['imp_imap']->ob()->subscribeMailbox($folder, true);
+                $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->subscribeMailbox($folder, true);
                 $notification->push(sprintf(_("You were successfully subscribed to \"%s\""), IMP::displayFolder($folder)), 'horde.success');
                 $subscribed[] = $folder;
             } catch (Horde_Imap_Client_Exception $e) {
@@ -413,7 +413,7 @@ class IMP_Folder
                 $notification->push(sprintf(_("You cannot unsubscribe from \"%s\"."), IMP::displayFolder($folder)), 'horde.error');
             } else {
                 try {
-                    $GLOBALS['imp_imap']->ob()->subscribeMailbox($folder, false);
+                    $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->subscribeMailbox($folder, false);
                     $notification->push(sprintf(_("You were successfully unsubscribed from \"%s\""), IMP::displayFolder($folder)), 'horde.success');
                     $unsubscribed[] = $folder;
                 } catch (Horde_Imap_Client_Exception $e) {
@@ -457,7 +457,7 @@ class IMP_Folder
 
         foreach ($folder_list as $folder) {
             try {
-                $status = $GLOBALS['imp_imap']->ob()->status($folder, Horde_Imap_Client::STATUS_MESSAGES);
+                $status = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->status($folder, Horde_Imap_Client::STATUS_MESSAGES);
             } catch (Horde_Imap_Client_Exception $e) {
                 continue;
             }
@@ -465,11 +465,11 @@ class IMP_Folder
                 /* Download one message at a time to save on memory
                  * overhead. */
                 try {
-                    $res = $GLOBALS['imp_imap']->ob()->fetch($folder, array(
-                            Horde_Imap_Client::FETCH_FULLMSG => array('peek' => true, 'stream' => true),
-                            Horde_Imap_Client::FETCH_ENVELOPE => true,
-                            Horde_Imap_Client::FETCH_DATE => true,
-                        ), array('ids' => array($i), 'sequence' => true));
+                    $res = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->fetch($folder, array(
+                        Horde_Imap_Client::FETCH_FULLMSG => array('peek' => true, 'stream' => true),
+                        Horde_Imap_Client::FETCH_ENVELOPE => true,
+                        Horde_Imap_Client::FETCH_DATE => true,
+                    ), array('ids' => array($i), 'sequence' => true));
                     $ptr = reset($res);
                 } catch (Horde_Imap_Client_Exception $e) {
                     continue;
@@ -510,6 +510,7 @@ class IMP_Folder
     {
         $message = '';
         $msgcount = 0;
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
 
         $fd = fopen($mbox, 'r');
         while (!feof($fd)) {
@@ -518,7 +519,7 @@ class IMP_Folder
             if (preg_match('/From (.+@.+|- )/A', $line)) {
                 if (!empty($message)) {
                     try {
-                        $GLOBALS['imp_imap']->ob()->append($folder, array(array('data' => $message)));
+                        $imp_imap->append($folder, array(array('data' => $message)));
                         ++$msgcount;
                     } catch (Horde_Imap_Client_Exception $e) {}
                 }
@@ -531,11 +532,12 @@ class IMP_Folder
 
         if (!empty($message)) {
             try {
-                $GLOBALS['imp_imap']->ob()->append($folder, array(array('data' => $message)));
+                $imp_imap->append($folder, array(array('data' => $message)));
                 ++$msgcount;
             } catch (Horde_Imap_Client_Exception $e) {}
         }
 
         return $msgcount ? $msgcount : false;
     }
+
 }
index fe5afa8..add3fb0 100644 (file)
@@ -407,7 +407,7 @@ class IMP
             return $cache[$folder];
         }
 
-        $ns_info = $GLOBALS['imp_imap']->getNamespace($folder);
+        $ns_info = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getNamespace($folder);
         $delimiter = is_null($ns_info) ? '' : $ns_info['delimiter'];
 
         /* Substitute any translated prefix text. */
@@ -496,7 +496,8 @@ class IMP
                     }
                 }
 
-                if (!empty($mailbox) && !$GLOBALS['imp_imap']->isReadOnly($mailbox)) {
+                if (!empty($mailbox) &&
+                    !$GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->isReadOnly($mailbox)) {
                     $menu_trash_url = self::generateIMPUrl($menu_mailbox_url, $mailbox)->add(array('actionID' => 'empty_mailbox', 'mailbox_token' => Horde::getRequestToken('imp.mailbox')));
                     $menu->add($menu_trash_url, _("Empty _Trash"), 'empty_trash.png', null, null, "return window.confirm('" . addslashes(_("Are you sure you wish to empty your trash folder?")) . "');", '__noselection');
                 }
@@ -726,8 +727,9 @@ class IMP
      */
     static public function folderPref($folder, $append)
     {
-        $def_ns = $GLOBALS['imp_imap']->defaultNamespace();
-        $empty_ns = $GLOBALS['imp_imap']->getNamespace('');
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+        $def_ns = $imp_imap->defaultNamespace();
+        $empty_ns = $imp_imap->getNamespace('');
 
         if ($append) {
             /* Converting from preference value. */
@@ -735,11 +737,11 @@ class IMP
                 strpos($folder, $empty_ns['delimiter']) === 0) {
                 /* Prefixed with delimiter => from empty namespace. */
                 $folder = substr($folder, strlen($empty_ns['delimiter']));
-            } elseif (($ns = $GLOBALS['imp_imap']->getNamespace($folder, true)) == null) {
+            } elseif (($ns = $imp_imap->getNamespace($folder, true)) == null) {
                 /* No namespace prefix => from personal namespace. */
                 $folder = $def_ns['name'] . $folder;
             }
-        } elseif (($ns = $GLOBALS['imp_imap']->getNamespace($folder)) !== null) {
+        } elseif (($ns = $imp_imap->getNamespace($folder)) !== null) {
             /* Converting to preference value. */
             if ($ns['name'] == $def_ns['name']) {
                 /* From personal namespace => strip namespace. */
index 25ffb5e..64a320d 100644 (file)
@@ -18,7 +18,14 @@ class IMP_Imap
      *
      * @var Horde_Imap_Client
      */
-    protected $_ob = null;
+    public $ob = null;
+
+    /**
+     * Server key for this instance.
+     *
+     * @var string
+     */
+    protected $_serverkey = '';
 
     /**
      * Is connection read-only?
@@ -43,9 +50,15 @@ class IMP_Imap
 
     /**
      * Constructor.
+     *
+     * @param string $serverkey  Server key for this instance.
+     *
+     * @throws IMP_Exception
      */
-    public function __construct()
+    public function __construct($serverkey)
     {
+        $this->_serverkey = $serverkey;
+
         /* Register the logging callback. */
         Horde_Imap_Client_Exception::$logCallback = array($this, 'logException');
 
@@ -60,87 +73,33 @@ class IMP_Imap
      */
     public function shutdown()
     {
-        /* Only need to serialize object once a session. When we do
-         * serialize, make sure we login in order to ensure we have done the
-         * necessary initialization. */
-        if ($this->_ob &&
-            isset($_SESSION['imp']) &&
-            empty($_SESSION['imp']['imap_ob'])) {
-            $this->_ob->login();
-
-            /* First login may occur on a non-viewable page. However,
-             * any login alerts received should be displayed to the user at
-             * some point. We need to do an explicit grab of the alarms
-             * right now. */
-            foreach ($this->_ob->alerts() as $alert) {
-                $GLOBALS['notification']->push($alert, 'horde.warning');
-            }
-
-            $_SESSION['imp']['imap_ob'][$_SESSION['imp']['server_key']] = serialize($this->_ob);
+        /* Only need to serialize object once a session. */
+        if ($this->ob && isset($_SESSION['imp'])) {
+            $_SESSION['imp']['imap_ob'][$this->_serverkey] = serialize($this->ob);
         }
     }
 
     /**
-     * Loads the IMP server configuration from servers.php.
-     *
-     * @param string $server  Returns this labeled entry only.
-     *
-     * @return mixed  If $server is set, then return this entry, or return the
-     *                entire servers array. Returns false on error.
-     */
-    static public function loadServerConfig($server = null)
-    {
-        try {
-            $servers = Horde::loadConfiguration('servers.php', 'servers', 'imp');
-            if ($servers === null) {
-                $servers = false;
-            }
-        } catch (Horde_Exception $e) {
-            Horde::logMessage($e, 'ERR');
-            return false;
-        }
-
-        if (is_null($server)) {
-            /* Remove any prompt entries (underscores in front of key). */
-            foreach (array_keys($servers) as $key) {
-                if ($key[0] == '_') {
-                    unset($servers[$key]);
-                }
-            }
-            return $servers;
-        }
-
-        /* Check for the existence of the server in the config file. */
-        if (empty($servers[$server]) || !is_array($servers[$server])) {
-            $entry = sprintf('Invalid server key "%s" from client [%s]', $server, $_SERVER['REMOTE_ADDR']);
-            Horde::logMessage($entry, 'ERR');
-            return false;
-        }
-
-        return $servers[$server];
-    }
-
-    /**
      * Loads the Horde_Imap_Client object from serialized session data.
      *
      * @return boolean  True on success, false on error.
+     * @throws IMP_Exception
      */
     protected function _loadImapObject()
     {
-        if (!is_null($this->_ob)) {
+        if (!is_null($this->ob)) {
             return true;
         }
 
         if (empty($_SESSION['imp']) ||
-            empty($_SESSION['imp']['server_key']) ||
-            empty($_SESSION['imp']['imap_ob'][$_SESSION['imp']['server_key']])) {
+            empty($_SESSION['imp']['imap_ob'][$this->_serverkey])) {
             return false;
         }
 
         Horde_Imap_Client::$encryptKey = $GLOBALS['injector']->getInstance('Horde_Secret')->getKey('imp');
 
-        $this->_ob = @unserialize($_SESSION['imp']['imap_ob'][$_SESSION['imp']['server_key']]);
-        if (empty($this->_ob)) {
+        $this->ob = @unserialize($_SESSION['imp']['imap_ob'][$this->_serverkey]);
+        if (empty($this->ob)) {
             /* Throw fatal error here - should never reach here and if we
              * do, we are out of luck. */
             throw new IMP_Exception(_("Could not acquire mail server credentials from the session."));
@@ -157,16 +116,13 @@ class IMP_Imap
      * @param string $username  The username to authenticate with.
      * @param string $password  The password to authenticate with.
      * @param string $key       Create a new object using this server key.
-     * @param boolean $global   If true, treat the created object as the IMP
-     *                          global IMAP object.
      *
      * @return boolean  The object on success, false on error.
      */
-    public function createImapObject($username, $password, $key,
-                                     $global = true)
+    public function createImapObject($username, $password, $key)
     {
-        if ($global && !is_null($this->_ob)) {
-            return $GLOBALS['imp_imap'];
+        if (!is_null($this->ob)) {
+            return $this->ob;
         }
 
         if (($server = $this->loadServerConfig($key)) === false) {
@@ -203,10 +159,8 @@ class IMP_Imap
             return false;
         }
 
-        if ($global) {
-            $this->_ob = $ob;
-            $this->_postcreate($protocol);
-        }
+        $this->ob = $ob;
+        $this->_postcreate($protocol);
 
         return $ob;
     }
@@ -243,7 +197,7 @@ class IMP_Imap
     }
 
     /**
-     * Alter some IMP settings once we load/create the global object.
+     * Alter some IMP settings once we load/create the object.
      *
      * @param string $protocol  The protocol used to connect.
      */
@@ -288,7 +242,7 @@ class IMP_Imap
                 ($_SESSION['imp']['protocol'] == 'imap') &&
                 !$GLOBALS['injector']->getInstance('IMP_Search')->isSearchMbox($mailbox)) {
                 try {
-                    $status = $this->_ob->status($mailbox, Horde_Imap_Client::STATUS_UIDNOTSTICKY);
+                    $status = $this->ob->status($mailbox, Horde_Imap_Client::STATUS_UIDNOTSTICKY);
                     $res = $status['uidnotsticky'];
                 } catch (Horde_Imap_Client_Exception $e) {}
             }
@@ -316,7 +270,7 @@ class IMP_Imap
         }
 
         if (!isset($this->_uidvalid[$mailbox])) {
-            $status = $this->_ob->status($mailbox, Horde_Imap_Client::STATUS_UIDVALIDITY);
+            $status = $this->ob->status($mailbox, Horde_Imap_Client::STATUS_UIDVALIDITY);
             $ptr = &$_SESSION['imp']['cache'];
             $val = isset($ptr['uidvalid'][$mailbox])
                 ? $ptr['uidvalid'][$mailbox]
@@ -351,7 +305,7 @@ class IMP_Imap
     public function getNamespaceList()
     {
         try {
-            return $this->_ob->getNamespaces(!empty($_SESSION['imp']['imap']['namespace']) ? $_SESSION['imp']['imap']['namespace'] : array());
+            return $this->ob->getNamespaces(!empty($_SESSION['imp']['imap']['namespace']) ? $_SESSION['imp']['imap']['namespace'] : array());
         } catch (Horde_Imap_Client_Exception $e) {
             // @todo Error handling
             return array();
@@ -435,13 +389,77 @@ class IMP_Imap
     }
 
     /**
-     * Return the Horde_Imap_Client object.
+     * Return the Horde_Imap_Client_Utils object.
      *
-     * @return Horde_Imap_Client  The imap object.
+     * @return Horde_Imap_Client_Utils  The utility object.
      */
-    public function ob()
+    public function getUtils()
     {
-        return $this->_ob;
+        return $this->ob
+            ? $this->ob->utils
+            : $GLOBALS['injector']->createInstance('Horde_Imap_Client_Utils');
     }
 
+    /**
+     * All other calls to this class are routed to the underlying
+     * Horde_Imap_Client_Base object.
+     *
+     * @param string $method  Method name.
+     * @param array $params   Method Parameters.
+     *
+     * @return mixed  The return from the requested method.
+     * @throws IMP_Exception
+     */
+    public function __call($method, $params)
+    {
+        if (!$this->ob || !method_exists($this->ob, $method)) {
+            throw new IMP_Exception(sprintf(_("%s: Invalid method call '%s'."), __CLASS__, $method));
+        }
+
+        return call_user_func_array(array($this->ob, $method), $params);
+    }
+
+    /* Static methods. */
+
+    /**
+     * Loads the IMP server configuration from servers.php.
+     *
+     * @param string $server  Returns this labeled entry only.
+     *
+     * @return mixed  If $server is set return this entry; else, return the
+     *                entire servers array. Returns false on error.
+     */
+    static public function loadServerConfig($server = null)
+    {
+        try {
+            $servers = Horde::loadConfiguration('servers.php', 'servers', 'imp');
+            if ($servers === null) {
+                $servers = false;
+            }
+        } catch (Horde_Exception $e) {
+            Horde::logMessage($e, 'ERR');
+            return false;
+        }
+
+        if (is_null($server)) {
+            /* Remove any prompt entries (underscores in front of key). */
+            foreach (array_keys($servers) as $key) {
+                if ($key[0] == '_') {
+                    unset($servers[$key]);
+                }
+            }
+            return $servers;
+        }
+
+        /* Check for the existence of the server in the config file. */
+        if (empty($servers[$server]) || !is_array($servers[$server])) {
+            $entry = sprintf('Invalid server key "%s" from client [%s]', $server, $_SERVER['REMOTE_ADDR']);
+            Horde::logMessage($entry, 'ERR');
+            return false;
+        }
+
+        return $servers[$server];
+    }
+
+
 }
index a8df2ee..c675992 100644 (file)
@@ -43,11 +43,12 @@ class IMP_Imap_Acl
             throw new IMP_Exception(_("ACLs not configured for this server."));
         }
 
-        if (!$GLOBALS['imp_imap']->ob()->queryCapability('ACL')) {
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+        if (!$imp_imap->queryCapability('ACL')) {
             throw new IMP_Exception(_("IMAP server does not support ACLs."));
         }
 
-        $this->_protected = array($GLOBALS['imp_imap']->ob()->getParam('username'));
+        $this->_protected = array($imp_imap->getParam('username'));
 
         $this->_rightsList = array(
             'l' => array(
@@ -80,7 +81,7 @@ class IMP_Imap_Acl
             )
         );
 
-        if ($GLOBALS['imp_imap']->ob()->queryCapability('RIGHTS')) {
+        if ($imp_imap->queryCapability('RIGHTS')) {
             // RFC 4314 compliant rights
             $this->_rightsList = array_merge($this->_rightsList, array(
                 'k' => array(
@@ -126,7 +127,7 @@ class IMP_Imap_Acl
     public function getACL($mbox)
     {
         try {
-            return $GLOBALS['imp_imap']->ob()->getACL($mbox);
+            return $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getACL($mbox);
         } catch (Horde_Imap_Client_Exception $e) {
             throw new IMP_Exception(_("Could not retrieve ACL"));
         }
@@ -144,7 +145,7 @@ class IMP_Imap_Acl
     public function editACL($mbox, $user, $acl)
     {
         try {
-            $GLOBALS['imp_imap']->ob()->setACL($mbox, $user, array('remove' => empty($acl), 'rights' => implode('', $acl)));
+            $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->setACL($mbox, $user, array('remove' => empty($acl), 'rights' => implode('', $acl)));
         } catch (Horde_Imap_Client_Exception $e) {
             throw new IMP_Exception(sprintf(_("Couldn't give user \"%s\" the following rights for the folder \"%s\": %s"), $user, $mbox, implode('', $acl)));
         }
@@ -161,7 +162,7 @@ class IMP_Imap_Acl
     public function canEdit($mbox, $user)
     {
         try {
-            $rights = $GLOBALS['imp_imap']->ob()->listACLRights($mbox, $user);
+            $rights = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->listACLRights($mbox, $user);
             $rights = array_merge($rights['required'], $rights['optional']);
             foreach ($rights as $val) {
                 if (strpos($val, 'a') !== false) {
index 7053e64..428f225 100644 (file)
@@ -95,8 +95,9 @@ class IMP_Imap_Flags
             try {
                 /* Make sure we are in R/W mailbox mode (SELECT). No flags are
                  * allowed in EXAMINE mode. */
-                $GLOBALS['imp_imap']->ob()->openMailbox($options['mailbox'], Horde_Imap_Client::OPEN_READWRITE);
-                $status = $GLOBALS['imp_imap']->ob()->status($options['mailbox'], Horde_Imap_Client::STATUS_PERMFLAGS);
+                $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+                $imp_imap->openMailbox($options['mailbox'], Horde_Imap_Client::OPEN_READWRITE);
+                $status = $imp_imap->status($options['mailbox'], Horde_Imap_Client::STATUS_PERMFLAGS);
 
                 if (($pos = array_search('\\*', $status['permflags'])) !== false) {
                     if ($GLOBALS['prefs']->getValue('show_all_flags')) {
@@ -178,7 +179,7 @@ class IMP_Imap_Flags
 
         /* IMAP keywords must conform to RFC 3501 [9] (flag-keyword). Convert
          * whitespace to underscore. */
-        $key = $GLOBALS['imp_imap']->ob()->utils->stripNonAtomChars(Horde_String::convertCharset(strtr($label, ' ', '_'), Horde_Nls::getCharset(), 'UTF7-IMAP'));
+        $key = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->stripNonAtomChars(Horde_String::convertCharset(strtr($label, ' ', '_'), Horde_Nls::getCharset(), 'UTF7-IMAP'));
         if (!isset($this->_flags[$key])) {
             $entry = $this->_createEntry($label);
 
index 5ac8540..c0e1c16 100644 (file)
@@ -202,7 +202,7 @@ class IMP_Imap_Tree
     public function __construct()
     {
         if ($_SESSION['imp']['protocol'] == 'imap') {
-            $ns = $GLOBALS['imp_imap']->getNamespaceList();
+            $ns = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getNamespaceList();
             $ptr = reset($ns);
             $this->_delimiter = $ptr['delimiter'];
             $this->_namespaces = empty($GLOBALS['conf']['user']['allow_folders'])
@@ -305,11 +305,12 @@ class IMP_Imap_Tree
         }
 
         try {
-            $result = $GLOBALS['imp_imap']->ob()->listMailboxes($searches, $showunsub ? Horde_Imap_Client::MBOX_ALL : Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, array('attributes' => true, 'delimiter' => true, 'sort' => true));
+            $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+            $result = $imp_imap->listMailboxes($searches, $showunsub ? Horde_Imap_Client::MBOX_ALL : Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, array('attributes' => true, 'delimiter' => true, 'sort' => true));
 
             /* INBOX must always appear. */
             if (empty($result['INBOX'])) {
-                $result = array_merge($GLOBALS['imp_imap']->ob()->listMailboxes('INBOX', Horde_Imap_Client::MBOX_ALL, array('attributes' => true, 'delimiter' => true)), $result);
+                $result = array_merge($imp_imap->listMailboxes('INBOX', Horde_Imap_Client::MBOX_ALL, array('attributes' => true, 'delimiter' => true)), $result);
             }
         } catch (Horde_Imap_Client_Exception $e) {}
 
@@ -648,7 +649,7 @@ class IMP_Imap_Tree
 
         if (!empty($id)) {
             try {
-                $this->_insert($GLOBALS['imp_imap']->ob()->listMailboxes($id, Horde_Imap_Client::MBOX_ALL, array('attributes' => true, 'delimiter' => true, 'sort' => true)));
+                $this->_insert($GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->listMailboxes($id, Horde_Imap_Client::MBOX_ALL, array('attributes' => true, 'delimiter' => true, 'sort' => true)));
             } catch (Horde_Imap_Client_Exception $e) {}
         }
     }
@@ -1451,7 +1452,7 @@ class IMP_Imap_Tree
     {
         if (!in_array($mailbox, array(self::OTHER_KEY, self::SHARED_KEY, self::VFOLDER_KEY)) &&
             (strpos($mailbox, self::VFOLDER_KEY . $this->_delimiter) !== 0)) {
-            return $GLOBALS['imp_imap']->getNamespace($mailbox);
+            return $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getNamespace($mailbox);
         }
         return null;
     }
@@ -1888,7 +1889,7 @@ class IMP_Imap_Tree
                 /* If we need message information for this folder, update
                  * it now. */
                 try {
-                    if ($msgs_info = $GLOBALS['imp_imap']->ob()->status($mailbox['v'], Horde_Imap_Client::STATUS_RECENT | Horde_Imap_Client::STATUS_UNSEEN | Horde_Imap_Client::STATUS_MESSAGES)) {
+                    if ($msgs_info = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->status($mailbox['v'], Horde_Imap_Client::STATUS_RECENT | Horde_Imap_Client::STATUS_UNSEEN | Horde_Imap_Client::STATUS_MESSAGES)) {
                         $row['polled'] = true;
                         if (!empty($msgs_info['recent'])) {
                             $row['recent'] = $msgs_info['recent'];
@@ -2030,7 +2031,7 @@ class IMP_Imap_Tree
     public function createMailboxName($parent, $new)
     {
         $ns_info = empty($parent)
-            ? $GLOBALS['imp_imap']->defaultNamespace()
+            ? $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->defaultNamespace()
             : $this->_getNamespace($parent);
 
         if (is_null($ns_info)) {
diff --git a/imp/lib/Injector/Binder/Imap.php b/imp/lib/Injector/Binder/Imap.php
new file mode 100644 (file)
index 0000000..76aab34
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Binder for IMP_Imap::.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * 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  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+class IMP_Injector_Binder_Imap implements Horde_Injector_Binder
+{
+    /**
+     */
+    public function create(Horde_Injector $injector)
+    {
+        return new IMP_Injector_Factory_Imap($injector);
+    }
+
+    /**
+     */
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+
+}
diff --git a/imp/lib/Injector/Factory/Imap.php b/imp/lib/Injector/Factory/Imap.php
new file mode 100644 (file)
index 0000000..09ff5ca
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+/**
+ * A Horde_Injector:: based IMP_Imap:: factory.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  IMP
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @link     http://pear.horde.org/index.php?package=IMP
+ */
+
+/**
+ * A Horde_Injector:: based IMP_Imap:: factory.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @category Horde
+ * @package  IMP
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @link     http://pear.horde.org/index.php?package=IMP
+ */
+class IMP_Injector_Factory_Imap
+{
+    /**
+     * Instances.
+     *
+     * @var array
+     */
+    private $_instances = array();
+
+    /**
+     * The injector.
+     *
+     * @var Horde_Injector
+     */
+    private $_injector;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Injector $injector  The injector to use.
+     */
+    public function __construct(Horde_Injector $injector)
+    {
+        $this->_injector = $injector;
+    }
+
+    /**
+     * Return the IMP_Imap:: instance.
+     *
+     * @param string $id  The server ID.
+     *
+     * @return IMP_Imap  The singleton contents instance.
+     * @throws IMP_Exception
+     */
+    public function getOb($id = null)
+    {
+        if (is_null($id)) {
+            $id = isset($_SESSION['imp'])
+                ? $_SESSION['imp']['server_key']
+                : 'default';
+        }
+
+        if (!isset($this->_instances[$id])) {
+            $this->_instances[$id] = new IMP_Imap($id);
+        }
+
+        return $this->_instances[$id];
+    }
+
+}
index a6819d0..dda8d43 100644 (file)
@@ -201,17 +201,19 @@ class IMP_Mailbox
             $fetch_criteria[Horde_Imap_Client::FETCH_STRUCTURE] = array('parse' => true);
         }
 
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+
         if (empty($options['preview'])) {
             $cache = null;
             $options['preview'] = 0;
         } else {
-            $cache = $GLOBALS['imp_imap']->ob()->getCache();
+            $cache = $imp_imap->getCache();
         }
 
         /* Retrieve information from each mailbox. */
         foreach ($to_process as $mbox => $ids) {
             try {
-                $fetch_res = $GLOBALS['imp_imap']->ob()->fetch($mbox, $fetch_criteria, array('ids' => array_keys($ids)));
+                $fetch_res = $imp_imap->fetch($mbox, $fetch_criteria, array('ids' => array_keys($ids)));
 
                 if ($options['preview']) {
                     $preview_info = $tostore = array();
@@ -257,7 +259,7 @@ class IMP_Mailbox
                 $uids[$mbox] = array_keys($fetch_res);
 
                 if (!is_null($cache) && !empty($tostore)) {
-                    $status = $GLOBALS['imp_imap']->ob()->status($mbox, Horde_Imap_Client::STATUS_UIDVALIDITY);
+                    $status = $imp_imap->status($mbox, Horde_Imap_Client::STATUS_UIDVALIDITY);
                     $cache->set($mbox, $tostore, $status['uidvalidity']);
                 }
             } catch (Horde_Imap_Client_Exception $e) {}
@@ -378,12 +380,13 @@ class IMP_Mailbox
         }
 
         $criteria = new Horde_Imap_Client_Search_Query();
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
 
         if (IMP::hideDeletedMsgs($this->_mailbox)) {
             $criteria->flag('\\deleted', false);
         } elseif ($count) {
             try {
-                $status_res = $GLOBALS['imp_imap']->ob()->status($this->_mailbox, $type == 'recent' ? Horde_Imap_Client::STATUS_RECENT : Horde_Imap_Client::STATUS_UNSEEN);
+                $status_res = $imp_imap->status($this->_mailbox, $type == 'recent' ? Horde_Imap_Client::STATUS_RECENT : Horde_Imap_Client::STATUS_UNSEEN);
                 return $status_res[$type];
             } catch (Horde_Imap_Client_Exception $e) {
                 return 0;
@@ -397,7 +400,7 @@ class IMP_Mailbox
         }
 
         try {
-            $res = $GLOBALS['imp_imap']->ob()->search($this->_mailbox, $criteria, array('results' => array($results), 'sequence' => !$uid));
+            $res = $imp_imap->search($this->_mailbox, $criteria, array('results' => array($results), 'sequence' => !$uid));
             return $count ? $res['count'] : $res;
         } catch (Horde_Imap_Client_Exception $e) {
             return $count ? 0 : array();
@@ -542,7 +545,7 @@ class IMP_Mailbox
         $ret['anymsg'] = true;
         if (!$ret['msgcount'] && !$this->_searchmbox) {
             try {
-                $status = $GLOBALS['imp_imap']->ob()->status($this->_mailbox, Horde_Imap_Client::STATUS_MESSAGES);
+                $status = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->status($this->_mailbox, Horde_Imap_Client::STATUS_MESSAGES);
                 $ret['anymsg'] = (bool)$status['messages'];
             } catch (Horde_Imap_Client_Exception $e) {
                 $ret['anymsg'] = false;
@@ -583,7 +586,7 @@ class IMP_Mailbox
              * information is returned via a SELECT/EXAMINE call. */
             if ($sortpref['by'] == Horde_Imap_Client::SORT_SEQUENCE) {
                 try {
-                    $res = $GLOBALS['imp_imap']->ob()->status($this->_mailbox, Horde_Imap_Client::STATUS_FIRSTUNSEEN);
+                    $res = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->status($this->_mailbox, Horde_Imap_Client::STATUS_FIRSTUNSEEN);
                     if (!is_null($res['firstunseen'])) {
                         return $res['firstunseen'];
                     }
@@ -648,7 +651,7 @@ class IMP_Mailbox
     {
         if (is_null($this->_threadob)) {
             try {
-                $this->_threadob = $GLOBALS['imp_imap']->ob()->thread($this->_mailbox, array('criteria' => $_SESSION['imp']['imap']['thread']));
+                $this->_threadob = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->thread($this->_mailbox, array('criteria' => $_SESSION['imp']['imap']['thread']));
             } catch (Horde_Imap_Client_Exception $e) {
                 $GLOBALS['notification']->push($e);
                 return new Horde_Imap_Client_Thread(array(), 'uid');
@@ -794,7 +797,7 @@ class IMP_Mailbox
         if (!$this->_searchmbox) {
             $sortpref = IMP::getSort($this->_mailbox, true);
             try {
-                return $GLOBALS['imp_imap']->ob()->getCacheId($this->_mailbox, array($sortpref['by'], $sortpref['dir']));
+                return $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getCacheId($this->_mailbox, array($sortpref['by'], $sortpref['dir']));
             } catch (Horde_Imap_Client_Exception $e) {}
         }
 
index c934bd5..919ee0a 100644 (file)
@@ -92,22 +92,24 @@ class IMP_Message
             break;
         }
 
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+
         foreach ($msgList as $mbox => $msgIndices) {
             $error = null;
 
-            if ($GLOBALS['imp_imap']->isReadOnly($targetMbox)) {
+            if ($imp_imap->isReadOnly($targetMbox)) {
                 $error = _("The target directory is read-only.");
             }
 
             if (!$error &&
                 ($action == 'move') &&
-                $GLOBALS['imp_imap']->isReadOnly($mbox)) {
+                $imp_imap->isReadOnly($mbox)) {
                 $error = _("The source directory is read-only.");
             }
 
             if (!$error) {
                 try {
-                    $GLOBALS['imp_imap']->checkUidvalidity($mbox);
+                    $imp_imap->checkUidvalidity($mbox);
                 } catch (IMP_Exception $e) {
                     $error = $e->getMessage();
                 }
@@ -116,7 +118,7 @@ class IMP_Message
             /* Attempt to copy/move messages to new mailbox. */
             if (!$error) {
                 try {
-                    $GLOBALS['imp_imap']->ob()->copy($mbox, $targetMbox, array('ids' => $msgIndices, 'move' => $imap_move));
+                    $imp_imap->copy($mbox, $targetMbox, array('ids' => $msgIndices, 'move' => $imap_move));
 
                     $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($mbox);
                     if (($action == 'move') && $imp_mailbox->isBuilt()) {
@@ -184,16 +186,18 @@ class IMP_Message
             }
         }
 
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+
         foreach ($msgList as $mbox => $msgIndices) {
             $error = null;
 
-            if ($GLOBALS['imp_imap']->isReadOnly($mbox)) {
+            if ($imp_imap->isReadOnly($mbox)) {
                 $error = _("This folder is read-only.");
             }
 
             if (!$error) {
                 try {
-                    $GLOBALS['imp_imap']->checkUidvalidity($mbox);
+                    $imp_imap->checkUidvalidity($mbox);
                 } catch (IMP_Exception $e) {
                     $error = $e->getMessage();
                 }
@@ -211,7 +215,7 @@ class IMP_Message
             /* Trash is only valid for IMAP mailboxes. */
             if ($use_trash_folder && ($mbox != $trash)) {
                 try {
-                    $GLOBALS['imp_imap']->ob()->copy($mbox, $trash, array('ids' => $msgIndices, 'move' => true));
+                    $imp_imap->copy($mbox, $trash, array('ids' => $msgIndices, 'move' => true));
 
                     $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($mbox);
                     if ($imp_mailbox->isBuilt()) {
@@ -227,7 +231,7 @@ class IMP_Message
                 $fetch = null;
                 if ($maillog_update) {
                     try {
-                        $fetch = $GLOBALS['imp_imap']->ob()->fetch($mbox, array(Horde_Imap_Client::FETCH_ENVELOPE => true), array('ids' => $msgIndices));
+                        $fetch = $imp_imap->fetch($mbox, array(Horde_Imap_Client::FETCH_ENVELOPE => true), array('ids' => $msgIndices));
                     } catch (Horde_Imap_Client_Exception $e) {}
                 }
 
@@ -251,7 +255,7 @@ class IMP_Message
                 }
 
                 try {
-                    $GLOBALS['imp_imap']->ob()->store($mbox, array('add' => array('\\deleted'), 'ids' => $msgIndices));
+                    $imp_imap->store($mbox, array('add' => array('\\deleted'), 'ids' => $msgIndices));
                     if ($expunge_now) {
                         $this->expungeMailbox($indices_array);
                     }
@@ -460,14 +464,15 @@ class IMP_Message
         }
         $uid = reset($uid);
 
-        if ($GLOBALS['imp_imap']->isReadOnly($mbox)) {
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+
+        if ($imp_imap->isReadOnly($mbox)) {
             throw new IMP_Exception(_("Cannot strip the MIME part as the mailbox is read-only."));
         }
 
-        $uidvalidity = $GLOBALS['imp_imap']->checkUidvalidity($mbox);
+        $uidvalidity = $imp_imap->checkUidvalidity($mbox);
 
         $contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($mbox, $uid);
-        $imap_ob = $GLOBALS['imp_imap']->ob();
         $message = $contents->getMIMEMessage();
         $boundary = trim($message->getContentTypeParameter('boundary'), '"');
 
@@ -481,7 +486,7 @@ class IMP_Message
         $parts = array(
             array(
                 't' => 'url',
-                'v' => $imap_ob->utils->createUrl(array_merge($url_array, array('section' => 'HEADER')))
+                'v' => $imp_imap->getUtils()->createUrl(array_merge($url_array, array('section' => 'HEADER')))
             )
         );
 
@@ -516,11 +521,11 @@ class IMP_Message
             } else {
                 $parts[] = array(
                     't' => 'url',
-                    'v' => $imap_ob->utils->createUrl(array_merge($url_array, array('section' => $id . '.MIME')))
+                    'v' => $imp_imap->getUtils()->createUrl(array_merge($url_array, array('section' => $id . '.MIME')))
                 );
                 $parts[] = array(
                     't' => 'url',
-                    'v' => $imap_ob->utils->createUrl(array_merge($url_array, array('section' => $id)))
+                    'v' => $imp_imap->getUtils()->createUrl(array_merge($url_array, array('section' => $id)))
                 );
             }
         }
@@ -532,7 +537,7 @@ class IMP_Message
 
         /* Get the headers for the message. */
         try {
-            $res = $imap_ob->fetch($mbox, array(
+            $res = $imp_imap->fetch($mbox, array(
                 Horde_Imap_Client::FETCH_DATE => true,
                 Horde_Imap_Client::FETCH_FLAGS => true
             ), array('ids' => array($uid)));
@@ -545,7 +550,7 @@ class IMP_Message
                 unset($res['flags'][$pos]);
             }
 
-            $new_uid = $imap_ob->append($mbox, array(
+            $new_uid = $imp_imap->append($mbox, array(
                 array(
                     'data' => $parts,
                     'flags' => $res['flags'],
@@ -587,17 +592,18 @@ class IMP_Message
         $action_array = $action
             ? array('add' => $flags)
             : array('remove' => $flags);
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
 
         foreach ($msgList as $mbox => $msgIndices) {
             $error = null;
 
-            if ($GLOBALS['imp_imap']->isReadOnly($mbox)) {
+            if ($imp_imap->isReadOnly($mbox)) {
                 $error = _("This folder is read-only.");
             }
 
             if (!$error) {
                 try {
-                    $GLOBALS['imp_imap']->checkUidvalidity($mbox);
+                    $imp_imap->checkUidvalidity($mbox);
                 } catch (IMP_Exception $e) {
                     $error = $e->getMessage();
                 }
@@ -606,7 +612,7 @@ class IMP_Message
             if (!$error) {
                 /* Flag/unflag the messages now. */
                 try {
-                    $GLOBALS['imp_imap']->ob()->store($mbox, array_merge($action_array, array('ids' => $msgIndices)));
+                    $imp_imap->store($mbox, array_merge($action_array, array('ids' => $msgIndices)));
                 } catch (Horde_Imap_Client_Exception $e) {
                     $error = $e->getMessage();
                 }
@@ -641,10 +647,11 @@ class IMP_Message
         $action_array = $action
             ? array('add' => $flags)
             : array('remove' => $flags);
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
 
         foreach ($mboxes as $val) {
             try {
-                $GLOBALS['imp_imap']->ob()->store($val, $action_array);
+                $imp_imap->store($val, $action_array);
             } catch (Horde_Imap_Client_Exception $e) {
                 return false;
             }
@@ -678,11 +685,12 @@ class IMP_Message
             return $msg_list ? array() : null;
         }
 
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
         $imp_search = $GLOBALS['injector']->getInstance('IMP_Search');
         $process_list = $update_list = array();
 
         foreach (array_keys($mbox_list) as $key) {
-            if (!$GLOBALS['imp_imap']->isReadOnly($key)) {
+            if (!$imp_imap->isReadOnly($key)) {
                 if ($imp_search->isSearchMbox($key)) {
                     foreach ($imp_search->getSearchFolders($key) as $skey) {
                         $process_list[$skey] = $mbox_list[$key];
@@ -698,14 +706,14 @@ class IMP_Message
              * UIDVALIDITY. */
             if (is_array($val)) {
                 try {
-                    $GLOBALS['imp_imap']->checkUidvalidity($key);
+                    $imp_imap->checkUidvalidity($key);
                 } catch (IMP_Exception $e) {
                     continue;
                 }
             }
 
             try {
-                $update_list[$key] = $GLOBALS['imp_imap']->ob()->expunge($key, array('ids' => is_array($val) ? $val : array(), 'list' => $msg_list));
+                $update_list[$key] = $imp_imap->expunge($key, array('ids' => is_array($val) ? $val : array(), 'list' => $msg_list));
 
                 $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($key);
                 if ($imp_mailbox->isBuilt()) {
@@ -726,6 +734,7 @@ class IMP_Message
     {
         global $notification, $prefs;
 
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
         $imp_search = $GLOBALS['injector']->getInstance('IMP_Search');
         $trash_folder = ($prefs->getValue('use_trash'))
             ? IMP::folderPref($prefs->getValue('trash_folder'), true)
@@ -734,7 +743,7 @@ class IMP_Message
         foreach ($mbox_list as $mbox) {
             $display_mbox = IMP::displayFolder($mbox);
 
-            if ($GLOBALS['imp_imap']->isReadOnly($mbox)) {
+            if ($imp_imap->isReadOnly($mbox)) {
                 $notification->push(sprintf(_("Could not delete messages from %s. This mailbox is read-only."), $display_mbox), 'horde.error');
                 continue;
             }
@@ -748,7 +757,7 @@ class IMP_Message
             /* Make sure there is at least 1 message before attempting to
                delete. */
             try {
-                $status = $GLOBALS['imp_imap']->ob()->status($mbox, Horde_Imap_Client::STATUS_MESSAGES);
+                $status = $imp_imap->status($mbox, Horde_Imap_Client::STATUS_MESSAGES);
                 if (empty($status['messages'])) {
                     $notification->push(sprintf(_("The mailbox %s is already empty."), $display_mbox), 'horde.message');
                     continue;
@@ -758,7 +767,7 @@ class IMP_Message
                     $this->flagAllInMailbox(array('\\deleted'), array($mbox), true);
                     $this->expungeMailbox(array($mbox => 1));
                 } else {
-                    $ret = $GLOBALS['imp_imap']->ob()->search($mbox);
+                    $ret = $imp_imap->search($mbox);
                     $indices = array($mbox => $ret['match']);
                     $this->delete($indices);
                 }
@@ -780,7 +789,7 @@ class IMP_Message
     public function sizeMailbox($mbox, $formatted = true)
     {
         try {
-            $res = $GLOBALS['imp_imap']->ob()->fetch($mbox, array(Horde_Imap_Client::FETCH_SIZE => true), array('sequence' => true));
+            $res = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->fetch($mbox, array(Horde_Imap_Client::FETCH_SIZE => true), array('sequence' => true));
 
             $size = 0;
             reset($res);
index 565b257..7c97c6f 100644 (file)
@@ -23,7 +23,8 @@ extends Horde_Notification_Handler_Decorator_Base
     public function notify($options)
     {
         if (in_array('status', $options['listeners']) &&
-            ($ob = $GLOBALS['imp_imap']->ob())) {
+            ($ob = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()) &&
+            $ob->ob) {
             /* Display IMAP alerts. */
             foreach ($ob->alerts() as $alert) {
                 $GLOBALS['notification']->push($alert, 'horde.warning');
index 4b8c8e6..e7e75a3 100644 (file)
@@ -1212,10 +1212,10 @@ class IMP_Prefs_Ui
 
         $sent_mail_folder = $ui->vars->sent_mail_folder;
         if (empty($sent_mail_folder)) {
-            $sent_mail_new = $GLOBALS['imp_imap']->appendNamespace(Horde_String::convertCharset($ui->vars->sent_mail_folder_new, Horde_Nls::getCharset(), 'UTF7-IMAP'));
+            $sent_mail_new = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->appendNamespace(Horde_String::convertCharset($ui->vars->sent_mail_folder_new, Horde_Nls::getCharset(), 'UTF7-IMAP'));
         } elseif ($sent_mail_folder == '-1') {
             if ($sent_mail_default = $prefs->getValue('sent_mail_folder')) {
-                $sent_mail_folder = $GLOBALS['imp_imap']->appendNamespace($sent_mail_default);
+                $sent_mail_folder = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->appendNamespace($sent_mail_default);
             }
         }
 
@@ -1684,7 +1684,7 @@ class IMP_Prefs_Ui
             $prefs->setValue($pref, '');
         } else {
             if (!empty($new)) {
-                $folder = $GLOBALS['imp_imap']->appendNamespace($new);
+                $folder = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->appendNamespace($new);
                 if (!$GLOBALS['injector']->getInstance('IMP_Folder')->create($folder, $prefs->getValue('subscribe'))) {
                     $folder = null;
                 }
index 1fae102..1ebb8f0 100644 (file)
@@ -26,7 +26,7 @@ class IMP_Quota_Imap extends IMP_Quota
     public function getQuota()
     {
         try {
-            $quota = $GLOBALS['imp_imap']->ob()->getQuotaRoot($GLOBALS['injector']->getInstance('IMP_Search')->isSearchMbox($GLOBALS['imp_mbox']['mailbox']) ? 'INBOX' : $GLOBALS['imp_mbox']['mailbox']);
+            $quota = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getQuotaRoot($GLOBALS['injector']->getInstance('IMP_Search')->isSearchMbox($GLOBALS['imp_mbox']['mailbox']) ? 'INBOX' : $GLOBALS['imp_mbox']['mailbox']);
         } catch (Horde_Imap_Client_Exception $e) {
             throw new IMP_Exception(_("Unable to retrieve quota"));
         }
index 9235dca..28046e7 100644 (file)
@@ -52,7 +52,7 @@ class IMP_Quota_Maildir extends IMP_Quota
         $full = $this->_params['path'] . '/maildirsize';
 
         // Substitute the username in the string if needed.
-        $full = str_replace('~U', $GLOBALS['imp_imap']->ob()->getParam('username'), $full);
+        $full = str_replace('~U', $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getParam('username'), $full);
 
         // Read in the quota file and parse it, if possible.
         if (!is_file($full)) {
index 3538b0c..e1dcff3 100644 (file)
@@ -320,12 +320,14 @@ class IMP_Search
      */
     public function imapSearch($mailbox, $query, $opts = array())
     {
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+
         /* If doing a from/to search, use display sorting if possible.
          * Although there is a fallback to a PHP-based display sort, for
          * performance reasons only do a display sort if it is supported
          * on the server. */
         if (($_SESSION['imp']['protocol'] == 'imap') && isset($opts['sort'])) {
-            $sort_cap = $GLOBALS['imp_imap']->ob()->queryCapability('SORT');
+            $sort_cap = $imp_imap->queryCapability('SORT');
 
             if (is_array($sort_cap) && in_array('DISPLAY', $sort_cap)) {
                 $pos = array_search(Horde_Imap_Client::SORT_FROM, $opts['sort']);
@@ -343,13 +345,13 @@ class IMP_Search
         /* Make sure we search in the proper charset. */
         if ($query) {
             $query = clone $query;
-            $imap_charset = $GLOBALS['imp_imap']->ob()->validSearchCharset('UTF-8')
+            $imap_charset = $imp_imap->validSearchCharset('UTF-8')
                 ? 'UTF-8'
                 : 'US-ASCII';
             $query->charset($imap_charset, array('Horde_String', 'convertCharset'));
         }
 
-        return $GLOBALS['imp_imap']->ob()->search($mailbox, $query, $opts);
+        return $imp_imap->search($mailbox, $query, $opts);
     }
 
     /**
index 654c56b..eb21a44 100644 (file)
@@ -38,7 +38,7 @@ class IMP_Spam
 
         foreach ($msgList as $mbox => $msgIndices) {
             try {
-                $GLOBALS['imp_imap']->checkUidvalidity($mbox);
+                $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->checkUidvalidity($mbox);
             } catch (IMP_Exception $e) {
                 continue;
             }
index 2ddf975..ad108d0 100644 (file)
@@ -31,9 +31,11 @@ class IMP_Ui_Block
             $imp_filter->filter('INBOX');
         }
 
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+
         /* Get list of mailboxes to poll. */
         $poll = $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->getPollList(true);
-        $status = $GLOBALS['imp_imap']->ob()->statusMultiple($poll, Horde_Imap_Client::STATUS_UNSEEN | Horde_Imap_Client::STATUS_MESSAGES | Horde_Imap_Client::STATUS_RECENT);
+        $status = $imp_imap->statusMultiple($poll, Horde_Imap_Client::STATUS_UNSEEN | Horde_Imap_Client::STATUS_MESSAGES | Horde_Imap_Client::STATUS_RECENT);
 
         $anyUnseen = false;
         $html = $onclick = '';
@@ -85,7 +87,7 @@ class IMP_Ui_Block
             /* Open the mailbox R/W to ensure the 'recent' flags are cleared
              * from the current mailbox. */
             foreach ($newmsgs as $mbox => $nm) {
-                $GLOBALS['imp_imap']->ob()->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE);
+                $imp_imap->openMailbox($mbox, Horde_Imap_Client::OPEN_READWRITE);
             }
         } elseif (!empty($this->_params['show_unread'])) {
             if (count($folders) == 0) {
index 7e098f8..7af0f15 100644 (file)
@@ -68,9 +68,10 @@ class IMP_Ui_Message
      */
     public function MDNCheck($mailbox, $uid, $headers, $confirmed = false)
     {
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
         $pref_val = $GLOBALS['prefs']->getValue('disposition_send_mdn');
 
-        if (!$pref_val || $GLOBALS['imp_imap']->isReadOnly($mailbox)) {
+        if (!$pref_val || $imp_imap->isReadOnly($mailbox)) {
             return false;
         }
 
@@ -87,11 +88,11 @@ class IMP_Ui_Message
         /* See if we have already processed this message. */
         /* 1st test: $MDNSent keyword (RFC 3503 [3.1]). */
         try {
-            $status = $GLOBALS['imp_imap']->ob()->status($mailbox, Horde_Imap_Client::STATUS_PERMFLAGS);
+            $status = $imp_imap->status($mailbox, Horde_Imap_Client::STATUS_PERMFLAGS);
             if (in_array('\\*', $status['permflags']) ||
                 in_array('$mdnsent', $status['permflags'])) {
                 $mdn_flag = true;
-                $res = $GLOBALS['imp_imap']->ob()->fetch($mailbox, array(
+                $res = $imp_imap->fetch($mailbox, array(
                         Horde_Imap_Client::FETCH_FLAGS => true
                     ), array('ids' => array($uid)));
                 $mdn_sent = in_array('$mdnsent', $res[$uid]['flags']);
index 3817dc3..1f6965f 100644 (file)
@@ -131,9 +131,11 @@ class IMP_Views_ListMessages
             $md->flags = array_keys($GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getList(array('imap' => true, 'mailbox' => $is_search ? null : $mbox)));
         }
 
+        $imp_imap = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb();
+
         /* These entries may change during a session, so always need to
          * update them. */
-        $md->readonly = intval($GLOBALS['imp_imap']->isReadOnly($mbox));
+        $md->readonly = intval($imp_imap->isReadOnly($mbox));
 
         /* Check for mailbox existence now. If there are no messages, there
          * is a chance that the mailbox doesn't exist. If there is at least
@@ -155,8 +157,8 @@ class IMP_Views_ListMessages
             !empty($args['cache'])) {
             $uid_expire = false;
             try {
-                $status = $GLOBALS['imp_imap']->ob()->status($mbox, Horde_Imap_Client::STATUS_UIDVALIDITY);
-                $parsed = $GLOBALS['imp_imap']->ob()->parseCacheId($args['cacheid']);
+                $status = $imp_imap->status($mbox, Horde_Imap_Client::STATUS_UIDVALIDITY);
+                $parsed = $imp_imap->parseCacheId($args['cacheid']);
                 $uid_expire = ($parsed['uidvalidity'] != $status['uidvalidity']);
             } catch (Horde_Imap_Cache_Exception $e) {
                 $uid_expire = true;
@@ -178,7 +180,7 @@ class IMP_Views_ListMessages
         /* Get the cached list. */
         $cached = $changed = array();
         if (!empty($args['cache'])) {
-            $cached = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($args['cache']);
+            $cached = $imp_imap->getUtils()->fromSequenceString($args['cache']);
             if ($is_search) {
                 $cached = array_flip($cached);
             } else {
@@ -189,11 +191,11 @@ class IMP_Views_ListMessages
                  * update the browser cache (done below). */
                 if ($args['change'] && $args['cacheid']) {
                     if (!isset($parsed)) {
-                        $parsed = $GLOBALS['imp_imap']->ob()->parseCacheId($args['cacheid']);
+                        $parsed = $imp_imap->parseCacheId($args['cacheid']);
                     }
                     if (!empty($parsed['highestmodseq'])) {
                         try {
-                            $res = $GLOBALS['imp_imap']->ob()->fetch($mbox, array(Horde_Imap_Client::FETCH_UID => 1), array('changedsince' => $parsed['highestmodseq']));
+                            $res = $imp_imap->fetch($mbox, array(Horde_Imap_Client::FETCH_UID => 1), array('changedsince' => $parsed['highestmodseq']));
                             if (!empty($res)) {
                                 $changed = array_flip(array_keys($res));
                             }
@@ -298,7 +300,7 @@ class IMP_Views_ListMessages
         /* Get unseen/thread information. */
         if (!$is_search) {
             try {
-                if ($info = $GLOBALS['imp_imap']->ob()->status($mbox, Horde_Imap_Client::STATUS_UNSEEN)) {
+                if ($info = $imp_imap->status($mbox, Horde_Imap_Client::STATUS_UNSEEN)) {
                     $md->unseen = intval($info['unseen']);
                 }
             } catch (Horde_Imap_Client_Exception $e) {}
index edf008e..9539352 100644 (file)
@@ -106,7 +106,7 @@ class IMP_Views_ShowMessage
         /* Get envelope/header information. We don't use flags in this
          * view. */
         try {
-            $fetch_ret = $GLOBALS['imp_imap']->ob()->fetch($mailbox, array(
+            $fetch_ret = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->fetch($mailbox, array(
                 Horde_Imap_Client::FETCH_ENVELOPE => true,
                 Horde_Imap_Client::FETCH_HEADERTEXT => array(array('parse' => true, 'peek' => false))
             ), array('ids' => array($uid)));
index 4441d96..b64693b 100644 (file)
@@ -70,6 +70,7 @@ if (!is_array(($indices = Horde_Util::getFormData('indices')))) {
 
 $do_filter = false;
 $imp_flags = $injector->getInstance('IMP_Imap_Flags');
+$imp_imap = $injector->getInstance('IMP_Imap')->getOb();
 $open_compose_window = null;
 
 /* Run through the action handlers */
@@ -87,7 +88,7 @@ if ($actionID && ($actionID != 'message_missing')) {
  * the RECENT flag. */
 if (!$search_mbox) {
     try {
-        $imp_imap->ob()->openMailbox($imp_mbox['mailbox'], Horde_Imap_Client::OPEN_READWRITE);
+        $imp_imap->openMailbox($imp_mbox['mailbox'], Horde_Imap_Client::OPEN_READWRITE);
     } catch (Horde_Imap_Client_Exception $e) {
         $actionID = null;
     }
@@ -185,7 +186,7 @@ case 'empty_mailbox':
     break;
 
 case 'view_messages':
-    $redirect = IMP::generateIMPUrl('thread.php', $imp_mbox['mailbox'], null, null, false)->setRaw(true)->add(array('mode' => 'msgview', 'msglist' => $imp_imap->ob()->utils->toSequenceString(IMP::parseIndicesList($indices), array('mailbox' => true))));
+    $redirect = IMP::generateIMPUrl('thread.php', $imp_mbox['mailbox'], null, null, false)->setRaw(true)->add(array('mode' => 'msgview', 'msglist' => $imp_imap->getUtils()->toSequenceString(IMP::parseIndicesList($indices), array('mailbox' => true))));
     header('Location: ' . $redirect);
     exit;
 }
@@ -374,7 +375,7 @@ if ($open_compose_window === false) {
 if (!empty($newmsgs)) {
     /* Open the mailbox R/W so we ensure the 'recent' flags are cleared from
      * the current mailbox. */
-    $imp_imap->ob()->openMailbox($imp_mbox['mailbox'], Horde_Imap_Client::OPEN_READWRITE);
+    $imp_imap->openMailbox($imp_mbox['mailbox'], Horde_Imap_Client::OPEN_READWRITE);
 
     if (!Horde_Util::getFormData('no_newmail_popup')) {
         /* Newmail alerts. */
index 3c0bc45..7621a58 100644 (file)
@@ -101,10 +101,10 @@ $uid = $index_ob['uid'];
 try {
     /* Need to fetch flags before HEADERTEXT, because SEEN flag might be set
      * before we can grab it. */
-    $flags_ret = $imp_imap->ob()->fetch($mailbox_name, array(
+    $flags_ret = $injector->getInstance('IMP_Imap')->getOb()->fetch($mailbox_name, array(
         Horde_Imap_Client::FETCH_FLAGS => true,
     ), array('ids' => array($uid)));
-    $fetch_ret = $imp_imap->ob()->fetch($mailbox_name, array(
+    $fetch_ret = $injector->getInstance('IMP_Imap')->getOb()->fetch($mailbox_name, array(
         Horde_Imap_Client::FETCH_ENVELOPE => true,
         Horde_Imap_Client::FETCH_HEADERTEXT => array(array('parse' => true, 'peek' => $readonly))
     ), array('ids' => array($uid)));
index 59bcae1..6fba925 100644 (file)
@@ -57,7 +57,7 @@ if ($vars->actionID) {
 }
 
 /* Determine if mailbox is readonly. */
-$peek = $readonly = $imp_imap->isReadOnly($imp_mbox['mailbox']);
+$peek = $readonly = $injector->getInstance('IMP_Imap')->getOb()->isReadOnly($imp_mbox['mailbox']);
 if ($readonly &&
     in_array($vars->actionID, array('delete_message', 'undelete_message', 'move_message', 'flag_message', 'strip_attachment', 'strip_all'))) {
     $vars->actionID = null;
@@ -201,10 +201,10 @@ try {
 try {
     /* Need to fetch flags before HEADERTEXT, because SEEN flag might be set
      * before we can grab it. */
-    $flags_ret = $imp_imap->ob()->fetch($mailbox_name, array(
+    $flags_ret = $injector->getInstance('IMP_Imap')->getOb()->fetch($mailbox_name, array(
         Horde_Imap_Client::FETCH_FLAGS => true,
     ), array('ids' => array($uid)));
-    $fetch_ret = $imp_imap->ob()->fetch($mailbox_name, array(
+    $fetch_ret = $injector->getInstance('IMP_Imap')->getOb()->fetch($mailbox_name, array(
         Horde_Imap_Client::FETCH_ENVELOPE => true,
         Horde_Imap_Client::FETCH_HEADERTEXT => array(array('parse' => true, 'peek' => $peek))
     ), array('ids' => array($uid)));
index 14f928a..1a87893 100644 (file)
@@ -20,7 +20,8 @@ Horde_Nls::setTimeZone();
  */
 $mode = Horde_Util::getFormData('mode', 'thread');
 
-$imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox')->getOb($imp_mbox['mailbox'], $imp_mbox['thismailbox'], $imp_mbox['uid']);
+$imp_imap = $injector->getInstance('IMP_Imap')->getOb();
+$imp_mailbox = $injector->getInstance('IMP_Mailbox')->getOb($imp_mbox['mailbox'], $imp_mbox['thismailbox'], $imp_mbox['uid']);
 
 $error = false;
 if ($mode == 'thread') {
@@ -30,7 +31,7 @@ if ($mode == 'thread') {
     }
 } else {
     /* MSGVIEW MODE: Make sure we have a valid list of messages. */
-    $msglist = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString(Horde_Util::getFormData('msglist'));
+    $msglist = $imp_imap->getUtils()->fromSequenceString(Horde_Util::getFormData('msglist'));
     if (empty($msglist)) {
         $error = true;
     }
@@ -79,7 +80,7 @@ $charset = Horde_Nls::getCharset();
 $imp_ui = new IMP_Ui_Message();
 
 foreach ($loop_array as $mbox => $idxlist) {
-    $fetch_res = $GLOBALS['imp_imap']->ob()->fetch($mbox, array(
+    $fetch_res = $imp_imap->fetch($mbox, array(
         Horde_Imap_Client::FETCH_ENVELOPE => true
     ), array('ids' => $idxlist));