From: Michael M Slusarz Date: Tue, 27 Apr 2010 05:27:54 +0000 (-0600) Subject: Move imp_imap from global to an injectable X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f3cd88759a9b29b9400e650e1cdfa51a7fe92c17;p=horde.git Move imp_imap from global to an injectable --- diff --git a/imp/folders.php b/imp/folders.php index 6c21a912b..66614e13c 100644 --- a/imp/folders.php +++ b/imp/folders.php @@ -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); diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index 27a02fae4..27764dbee 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -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) { diff --git a/imp/lib/Api.php b/imp/lib/Api.php index 2b06a58ce..1d05a03dc 100644 --- a/imp/lib/Api.php +++ b/imp/lib/Api.php @@ -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; } /** diff --git a/imp/lib/Application.php b/imp/lib/Application.php index 54d53f004..a2352565d 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -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; diff --git a/imp/lib/Auth.php b/imp/lib/Auth.php index 5b4b721ab..bccea811d 100644 --- a/imp/lib/Auth.php +++ b/imp/lib/Auth.php @@ -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'; } diff --git a/imp/lib/Block/Newmail.php b/imp/lib/Block/Newmail.php index 3738a8a6f..0352bd12a 100644 --- a/imp/lib/Block/Newmail.php +++ b/imp/lib/Block/Newmail.php @@ -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); diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 33c075493..ca22d989e 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -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( diff --git a/imp/lib/Contents.php b/imp/lib/Contents.php index b48064555..f928ae2e4 100644 --- a/imp/lib/Contents.php +++ b/imp/lib/Contents.php @@ -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]; diff --git a/imp/lib/Filter.php b/imp/lib/Filter.php index ce15e8bca..585decee7 100644 --- a/imp/lib/Filter.php +++ b/imp/lib/Filter.php @@ -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); diff --git a/imp/lib/Folder.php b/imp/lib/Folder.php index a3bc4907e..8346875ae 100644 --- a/imp/lib/Folder.php +++ b/imp/lib/Folder.php @@ -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; } + } diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index fe5afa844..add3fb0bd 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -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. */ diff --git a/imp/lib/Imap.php b/imp/lib/Imap.php index 25ffb5e00..64a320d8e 100644 --- a/imp/lib/Imap.php +++ b/imp/lib/Imap.php @@ -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]; + } + + } diff --git a/imp/lib/Imap/Acl.php b/imp/lib/Imap/Acl.php index a8df2ee50..c67599224 100644 --- a/imp/lib/Imap/Acl.php +++ b/imp/lib/Imap/Acl.php @@ -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) { diff --git a/imp/lib/Imap/Flags.php b/imp/lib/Imap/Flags.php index 7053e6404..428f22535 100644 --- a/imp/lib/Imap/Flags.php +++ b/imp/lib/Imap/Flags.php @@ -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); diff --git a/imp/lib/Imap/Tree.php b/imp/lib/Imap/Tree.php index 5ac85407c..c0e1c16fb 100644 --- a/imp/lib/Imap/Tree.php +++ b/imp/lib/Imap/Tree.php @@ -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 index 000000000..76aab34f4 --- /dev/null +++ b/imp/lib/Injector/Binder/Imap.php @@ -0,0 +1,29 @@ + + * @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 index 000000000..09ff5ca31 --- /dev/null +++ b/imp/lib/Injector/Factory/Imap.php @@ -0,0 +1,77 @@ + + * @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 + * @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]; + } + +} diff --git a/imp/lib/Mailbox.php b/imp/lib/Mailbox.php index a6819d098..dda8d4383 100644 --- a/imp/lib/Mailbox.php +++ b/imp/lib/Mailbox.php @@ -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) {} } diff --git a/imp/lib/Message.php b/imp/lib/Message.php index c934bd5f6..919ee0a7f 100644 --- a/imp/lib/Message.php +++ b/imp/lib/Message.php @@ -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); diff --git a/imp/lib/Notification/Handler/Decorator/Imap.php b/imp/lib/Notification/Handler/Decorator/Imap.php index 565b2576d..7c97c6f3e 100644 --- a/imp/lib/Notification/Handler/Decorator/Imap.php +++ b/imp/lib/Notification/Handler/Decorator/Imap.php @@ -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'); diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index 4b8c8e6b6..e7e75a3ab 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -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; } diff --git a/imp/lib/Quota/Imap.php b/imp/lib/Quota/Imap.php index 1fae10280..1ebb8f04b 100644 --- a/imp/lib/Quota/Imap.php +++ b/imp/lib/Quota/Imap.php @@ -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")); } diff --git a/imp/lib/Quota/Maildir.php b/imp/lib/Quota/Maildir.php index 9235dcad1..28046e763 100644 --- a/imp/lib/Quota/Maildir.php +++ b/imp/lib/Quota/Maildir.php @@ -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)) { diff --git a/imp/lib/Search.php b/imp/lib/Search.php index 3538b0ca2..e1dcff33e 100644 --- a/imp/lib/Search.php +++ b/imp/lib/Search.php @@ -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); } /** diff --git a/imp/lib/Spam.php b/imp/lib/Spam.php index 654c56bad..eb21a44c3 100644 --- a/imp/lib/Spam.php +++ b/imp/lib/Spam.php @@ -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; } diff --git a/imp/lib/Ui/Block.php b/imp/lib/Ui/Block.php index 2ddf975a8..ad108d0a8 100644 --- a/imp/lib/Ui/Block.php +++ b/imp/lib/Ui/Block.php @@ -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) { diff --git a/imp/lib/Ui/Message.php b/imp/lib/Ui/Message.php index 7e098f8a4..7af0f1579 100644 --- a/imp/lib/Ui/Message.php +++ b/imp/lib/Ui/Message.php @@ -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']); diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index 3817dc30a..1f6965f91 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -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) {} diff --git a/imp/lib/Views/ShowMessage.php b/imp/lib/Views/ShowMessage.php index edf008e91..9539352d3 100644 --- a/imp/lib/Views/ShowMessage.php +++ b/imp/lib/Views/ShowMessage.php @@ -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))); diff --git a/imp/mailbox.php b/imp/mailbox.php index 4441d96bd..b64693b96 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -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. */ diff --git a/imp/message-mimp.php b/imp/message-mimp.php index 3c0bc4532..7621a58c8 100644 --- a/imp/message-mimp.php +++ b/imp/message-mimp.php @@ -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))); diff --git a/imp/message.php b/imp/message.php index 59bcae1ca..6fba92502 100644 --- a/imp/message.php +++ b/imp/message.php @@ -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))); diff --git a/imp/thread.php b/imp/thread.php index 14f928a8c..1a878937f 100644 --- a/imp/thread.php +++ b/imp/thread.php @@ -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));