Convert some singletons to injector usage
authorMichael M Slusarz <slusarz@curecanti.org>
Sun, 31 Jan 2010 02:58:26 +0000 (19:58 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Sun, 31 Jan 2010 05:05:06 +0000 (22:05 -0700)
43 files changed:
imp/acl.php
imp/compose.php
imp/folders-mimp.php
imp/folders.php
imp/lib/Accounts.php
imp/lib/Ajax/Application.php
imp/lib/Api.php
imp/lib/Application.php
imp/lib/Block/tree_folders.php
imp/lib/Compose.php
imp/lib/Filter.php
imp/lib/Folder.php
imp/lib/IMP.php
imp/lib/Imap/Acl.php
imp/lib/Imap/Flags.php
imp/lib/Imap/Tree.php
imp/lib/Injector/Binder/Imaptree.php [new file with mode: 0644]
imp/lib/LoginTasks/SystemTask/GarbageCollection.php
imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php
imp/lib/LoginTasks/Task/PurgeSentmail.php
imp/lib/LoginTasks/Task/PurgeSpam.php
imp/lib/LoginTasks/Task/PurgeTrash.php
imp/lib/LoginTasks/Task/RenameSentmailMonthly.php
imp/lib/Message.php
imp/lib/Search.php
imp/lib/Spam.php
imp/lib/Ui/Block.php
imp/lib/Ui/Folder.php
imp/lib/Ui/Message.php
imp/lib/Ui/Search.php
imp/lib/Views/Compose.php
imp/lib/Views/ListMessages.php
imp/mailbox-mimp.php
imp/mailbox.php
imp/message-mimp.php
imp/message.php
imp/rss.php
imp/search.php
imp/templates/index/index-dimp.inc
imp/templates/javascript_defs_dimp.php
imp/templates/prefs/accountsmanagement.inc
imp/templates/prefs/flagmanagement.inc
imp/thread.php

index c2eaa82..d4caf71 100644 (file)
@@ -24,7 +24,7 @@ if ($prefs->isLocked('acl') || empty($_SESSION['imp']['acl'])) {
 }
 
 try {
-    $ACLDriver = IMP_Imap_Acl::singleton();
+    $ACLDriver = $injector->getInstance('IMP_Imap_Acl');
 } catch (Horde_Exception $e) {
     $notification->push(_("This server does not support sharing folders."), 'horde.error');
     header('Location: ' . $prefs_url);
@@ -116,7 +116,7 @@ case 'imp_acl_set':
     break;
 }
 
-$imp_folder = IMP_Folder::singleton();
+$imp_folder = $injector->getInstance('IMP_Folder');
 $rights = $ACLDriver->getRights();
 
 if (empty($folder)) {
index 6baf986..caede20 100644 (file)
@@ -964,7 +964,7 @@ if ($redirect) {
 
             /* Check to make sure the sent-mail folder is created - it needs
              * to exist to show up in drop-down list. */
-            $imp_folder = IMP_Folder::singleton();
+            $imp_folder = $injector->getInstance('IMP_Folder');
             if (!$imp_folder->exists($sent_mail_folder)) {
                 $imp_folder->create($sent_mail_folder, true);
             }
index 62d1db5..af5c3c4 100644 (file)
@@ -31,7 +31,7 @@ $subscribe = $prefs->getValue('subscribe');
 $showAll = (!$subscribe || $_SESSION['imp']['showunsub']);
 
 /* Initialize the IMP_Imap_Tree object. */
-$imptree = IMP_Imap_Tree::singleton();
+$imptree = $injector->getInstance('IMP_Imap_Tree');
 $mask = IMP_Imap_Tree::NEXT_SHOWCLOSED;
 
 /* Toggle subscribed view, if necessary. */
index 4cc17cd..652bbce 100644 (file)
@@ -40,10 +40,10 @@ Horde::addInlineScript(array(
 ));
 
 /* Initialize the IMP_Folder object. */
-$imp_folder = IMP_Folder::singleton();
+$imp_folder = $injector->getInstance('IMP_Folder');
 
 /* Initialize the IMP_Imap_Tree object. */
-$imaptree = IMP_Imap_Tree::singleton();
+$imaptree = $injector->getInstance('IMP_Imap_Tree');
 
 /* $folder_list is already encoded in UTF7-IMAP. */
 $folder_list = Horde_Util::getFormData('folder_list', array());
@@ -87,8 +87,7 @@ case 'rebuild_tree':
 
 case 'expunge_folder':
     if (!empty($folder_list)) {
-        $imp_message = IMP_Message::singleton();
-        $imp_message->expungeMailbox(array_flip($folder_list));
+        $injector->getInstance('IMP_Message')->expungeMailbox(array_flip($folder_list));
     }
     break;
 
@@ -228,16 +227,14 @@ case 'nopoll_folder':
 
 case 'folders_empty_mailbox':
     if (!empty($folder_list)) {
-        $imp_message = IMP_Message::singleton();
-        $imp_message->emptyMailbox($folder_list);
+        $injector->getInstance('IMP_Message')->emptyMailbox($folder_list);
     }
     break;
 
 case 'mark_folder_seen':
 case 'mark_folder_unseen':
     if (!empty($folder_list)) {
-        $imp_message = IMP_Message::singleton();
-        $imp_message->flagAllInMailbox(array('seen'), $folder_list, ($actionID == 'mark_folder_seen'));
+        $injector->getInstance('IMP_Message')->flagAllInMailbox(array('seen'), $folder_list, ($actionID == 'mark_folder_seen'));
     }
     break;
 
@@ -305,7 +302,7 @@ case 'mbox_size':
         $loop = array();
         $rowct = $sum = 0;
 
-        $imp_message = IMP_Message::singleton();
+        $imp_message = $injector->getInstance('IMP_Message');
 
         foreach ($folder_list as $val) {
             $size = $imp_message->sizeMailbox($val, false);
index eeeca1f..22f2292 100644 (file)
 class IMP_Accounts
 {
     /**
-     * Singleton instance.
-     *
-     * @var IMP_Accounts
-     */
-    static protected $_instance;
-
-    /**
      * The cached list of accounts.
      *
      * @var array
@@ -28,21 +21,6 @@ class IMP_Accounts
     protected $_accounts = null;
 
     /**
-     * Attempts to return a reference to a concrete object instance.
-     * It will only create a new instance if no instance currently exists.
-     *
-     * @return IMP_Accounts  The created concrete instance.
-     */
-    static public function singleton()
-    {
-        if (!isset(self::$_instance)) {
-            self::$_instance = new self();
-        }
-
-        return self::$_instance;
-    }
-
-    /**
      * Save the accounts list to the prefs backend.
      */
     protected function _save()
index bfbbd8d..461cde7 100644 (file)
@@ -71,15 +71,14 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $imptree = IMP_Imap_Tree::singleton();
+        $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
         $imptree->eltDiffStart();
 
-        $imp_folder = IMP_Folder::singleton();
-
         $new = Horde_String::convertCharset($vars->mbox, Horde_Nls::getCharset(), 'UTF7-IMAP');
         try {
             $new = $imptree->createMailboxName($vars->parent, $new);
-            if ($result = $imp_folder->create($new, $GLOBALS['prefs']->getValue('subscribe'))) {
+
+            if ($result =$GLOBALS['injector']->getInstance('IMP_Folder')->create($new, $GLOBALS['prefs']->getValue('subscribe'))) {
                 $result = new stdClass;
                 $result->mailbox = $this->_getMailboxResponse($imptree);
             }
@@ -115,7 +114,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $imptree = IMP_Imap_Tree::singleton();
+        $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
         $imptree->eltDiffStart();
 
         if ($GLOBALS['imp_search']->isEditableVFolder($vars->mbox)) {
@@ -123,8 +122,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             $GLOBALS['imp_search']->deleteSearchQuery($vars->mbox);
             $result = true;
         } else {
-            $imp_folder = IMP_Folder::singleton();
-            $result = $imp_folder->delete(array($vars->mbox));
+            $result = $GLOBALS['injector']->getInstance('IMP_Folder')->delete(array($vars->mbox));
         }
 
         if ($result) {
@@ -161,18 +159,16 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $imptree = IMP_Imap_Tree::singleton();
+        $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
         $imptree->eltDiffStart();
 
-        $imp_folder = IMP_Folder::singleton();
         $result = false;
 
         try {
             $new = Horde_String::convertCharset($imptree->createMailboxName($vars->new_parent, $vars->new_name), Horde_Nls::getCharset(), 'UTF7-IMAP');
 
             if (($vars->old_name != $new) &&
-                $imp_folder->rename($vars->old_name, $new)) {
-
+                $GLOBALS['injector']->getInstance('IMP_Folder')->rename($vars->old_name, $new)) {
                 $result = new stdClass;
                 $result->mailbox = $this->_getMailboxResponse($imptree);
             }
@@ -203,8 +199,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $imp_message = IMP_Message::singleton();
-        $imp_message->emptyMailbox(array($vars->mbox));
+        $GLOBALS['injector']->getInstance('IMP_Message')->emptyMailbox(array($vars->mbox));
 
         $result = new stdClass;
         $result->mbox = $vars->mbox;
@@ -239,8 +234,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $imp_message = IMP_Message::singleton();
-        $result = $imp_message->flagAllInMailbox($flags, array($vars->mbox), $vars->set);
+        $result = $GLOBALS['injector']->getInstance('IMP_Message')->flagAllInMailbox($flags, array($vars->mbox), $vars->set);
 
         if ($result) {
             $result = new stdClass;
@@ -286,7 +280,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      */
     public function ListMailboxes($vars)
     {
-        $imptree = IMP_Imap_Tree::singleton();
+        $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
         $mask = IMP_Imap_Tree::FLIST_CONTAINER | IMP_Imap_Tree::FLIST_VFOLDER | IMP_Imap_Tree::FLIST_ELT;
         if ($vars->unsub) {
             $mask |= IMP_Imap_Tree::FLIST_UNSUB;
@@ -359,12 +353,11 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
     public function Poll($vars)
     {
         $changed = false;
-        $imptree = IMP_Imap_Tree::singleton();
 
         $result = new stdClass;
         $result->poll = array();
 
-        foreach ($GLOBALS['imp_imap']->ob()->statusMultiple($imptree->getPollList(), Horde_Imap_Client::STATUS_UNSEEN) as $key => $val) {
+        foreach ($GLOBALS['imp_imap']->ob()->statusMultiple($GLOBALS['injector']->getInstance('IMP_Imap_Tree')->getPollList(), Horde_Imap_Client::STATUS_UNSEEN) as $key => $val) {
             $result->poll[$key] = intval($val['unseen']);
         }
 
@@ -409,7 +402,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
 
         $display_folder = IMP::displayFolder($vars->mbox);
 
-        $imptree = IMP_Imap_Tree::singleton();
+        $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
 
         $result = new stdClass;
         $result->add = intval($vars->add);
@@ -448,7 +441,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $imp_folder = IMP_Folder::singleton();
+        $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
         return $vars->sub
             ? $imp_folder->subscribe(array($vars->mbox))
             : $imp_folder->unsubscribe(array($vars->mbox));
@@ -537,8 +530,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $imp_message = IMP_Message::singleton();
-        $result = $imp_message->copy($vars->mboxto, 'move', $indices);
+        $result = $GLOBALS['injector']->getInstance('IMP_Message')->copy($vars->mboxto, 'move', $indices);
 
         if ($result) {
             $result = $this->_generateDeleteResult($vars, $indices, $change);
@@ -587,9 +579,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $imp_message = IMP_Message::singleton();
-
-        if ($result = $imp_message->copy($vars->mboxto, 'copy', $indices)) {
+        if ($result = $GLOBALS['injector']->getInstance('IMP_Message')->copy($vars->mboxto, 'copy', $indices)) {
             if ($poll = $this->_getPollInformation($vars->mboxto)) {
                 $result->poll = array_merge(isset($result->poll) ? $result->poll : array(), $poll);
             }
@@ -626,7 +616,6 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         }
 
         $flags = Horde_Serialize::unserialize($vars->flags, Horde_Serialize::JSON);
-        $imp_message = IMP_Message::singleton();
         $result = false;
         $set = $notset = array();
 
@@ -639,11 +628,11 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         }
 
         if (!empty($set)) {
-            $result = $imp_message->flag($set, $indices, true);
+            $result = $GLOBALS['injector']->getInstance('IMP_Message')->flag($set, $indices, true);
         }
 
         if (!empty($notset)) {
-            $result = $imp_message->flag($notset, $indices, false);
+            $result = $GLOBALS['injector']->getInstance('IMP_Message')->flag($notset, $indices, false);
         }
 
         return $result
@@ -673,10 +662,9 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
-        $imp_message = IMP_Message::singleton();
         $change = $this->_changed($vars, true);
 
-        if ($imp_message->delete($indices)) {
+        if ($GLOBALS['injector']->getInstance('IMP_Message')->delete($indices)) {
             return $this->_generateDeleteResult($vars, $indices, $change, !$GLOBALS['prefs']->getValue('hide_deleted') && !$GLOBALS['prefs']->getValue('use_trash'));
         }
 
@@ -1031,9 +1019,8 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         $imp_compose->destroy(false);
 
         if ($draft_uid = $imp_compose->getMetadata('draft_uid')) {
-            $imp_message = IMP_Message::singleton();
             $idx_array = array($draft_uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true));
-            $imp_message->delete($idx_array, array('nuke' => true));
+            $GLOBALS['injector']->getInstance('IMP_Message')->delete($idx_array, array('nuke' => true));
         }
 
         return true;
@@ -1168,8 +1155,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             $change = ($sort['by'] == Horde_Imap_Client::SORT_THREAD);
         }
 
-        $imp_message = IMP_Message::singleton();
-        $expunged = $imp_message->expungeMailbox(array($vars->view => 1), array('list' => true));
+        $expunged = $GLOBALS['injector']->getInstance('IMP_Message')->expungeMailbox(array($vars->view => 1), array('list' => true));
 
         if (empty($expunged[$mbox])) {
             return false;
@@ -1446,7 +1432,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
 
         /* Use IMP_Tree to determine whether the sent mail folder was
          * created. */
-        $imptree = IMP_Imap_Tree::singleton();
+        $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
         $imptree->eltDiffStart();
 
         $options = array(
@@ -1768,7 +1754,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      */
     protected function _getPollInformation($mbox)
     {
-        $imptree = IMP_Imap_Tree::singleton();
+        $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
         $elt = $imptree->get($mbox);
         if (!$imptree->isPolled($elt)) {
             return array();
index 6ee4bfb..9d0ec8e 100644 (file)
@@ -69,8 +69,7 @@ class IMP_Api extends Horde_Registry_Api
      */
     public function folderlist()
     {
-        $imp_folder = IMP_Folder::singleton();
-        return $imp_folder->flist();
+        return $GLOBALS['injector']->getInstance('IMP_Folder')->flist();
     }
 
     /**
@@ -83,9 +82,8 @@ class IMP_Api extends Horde_Registry_Api
      */
     public function createFolder($folder)
     {
-        $imp_folder = IMP_Folder::singleton();
         $fname = $GLOBALS['imp_imap']->appendNamespace($folder);
-        return $imp_folder->create($fname, $GLOBALS['prefs']->getValue('subscribe'))
+        return $GLOBALS['injector']->getInstance('IMP_Folder')->create($fname, $GLOBALS['prefs']->getValue('subscribe'))
             ? $fname
             : false;
     }
@@ -101,8 +99,7 @@ class IMP_Api extends Horde_Registry_Api
      */
     public function deleteMessages($mailbox, $indices)
     {
-        $imp_message = IMP_Message::singleton();
-        return $imp_message->delete(array($mailbox => $indices), array('nuke' => true));
+        return $GLOBALS['injector']->getInstance('IMP_Message')->delete(array($mailbox => $indices), array('nuke' => true));
     }
 
     /**
@@ -116,8 +113,7 @@ class IMP_Api extends Horde_Registry_Api
      */
     public function copyMessages($mailbox, $indices, $target)
     {
-        $imp_message = IMP_Message::singleton();
-        return $imp_message->copy($target, 'copy', array($mailbox => $indices), true);
+        return $GLOBALS['injector']->getInstance('IMP_Message')->copy($target, 'copy', array($mailbox => $indices), true);
     }
 
     /**
@@ -131,8 +127,7 @@ class IMP_Api extends Horde_Registry_Api
      */
     public function moveMessages($mailbox, $indices, $target)
     {
-        $imp_message = IMP_Message::singleton();
-        return $imp_message->copy($target, 'move', array($mailbox => $indices), true);
+        return $GLOBALS['injector']->getInstance('IMP_Message')->copy($target, 'move', array($mailbox => $indices), true);
     }
 
     /**
@@ -147,8 +142,7 @@ class IMP_Api extends Horde_Registry_Api
      */
     public function flagMessages($mailbox, $indices, $flags, $set)
     {
-        $imp_message = IMP_Message::singleton();
-        return $imp_message->flag($flags, array($mailbox => $indices), $set);
+        return $GLOBALS['injector']->getInstance('IMP_Message')->flag($flags, array($mailbox => $indices), $set);
     }
 
     /**
@@ -237,8 +231,7 @@ class IMP_Api extends Horde_Registry_Api
             $opts['mailbox'] = $mailbox;
         }
 
-        $imp_flags = IMP_Imap_Flags::singleton();
-        return $imp_flags->getList($opts);
+        return $GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getList($opts);
     }
 
 }
index 8f0a456..4a6c426 100644 (file)
@@ -101,6 +101,8 @@ class IMP_Application extends Horde_Registry_Application
             Horde_Nls::setTimeZone();
         }
 
+        $GLOBALS['injector']->addBinder('IMP_Imap_Tree', new IMP_Injector_Binder_Imaptree());
+
         // Initialize global $imp_imap object.
         $GLOBALS['imp_imap'] = new IMP_Imap();
 
@@ -195,12 +197,9 @@ class IMP_Application extends Horde_Registry_Application
             }
         }
 
-        if (($permission == 'max_folders') && empty($opts['value'])) {
-            $folder = IMP_Folder::singleton();
-            $allowed = $allowed > count($folder->flist_IMP(array(), false));
-        }
-
-        return $allowed;
+        return (($permission == 'max_folders') && empty($opts['value']))
+            ? $allowed > count($GLOBALS['injector']->getInstance('IMP_Folder')->flist_IMP(array(), false))
+            : $allowed;
     }
 
     /* Horde_Auth_Application methods. */
@@ -667,7 +666,7 @@ class IMP_Application extends Horde_Registry_Application
         }
 
         if (!empty($sent_mail_folder)) {
-            $imp_folder = IMP_Folder::singleton();
+            $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
             if (!$imp_folder->exists($sent_mail_folder)) {
                 $imp_folder->create($sent_mail_folder, $GLOBALS['prefs']->getValue('subscribe'));
             }
@@ -694,8 +693,7 @@ class IMP_Application extends Horde_Registry_Application
             } else {
                 if (empty($folder) && !empty($new)) {
                     $folder = $GLOBALS['imp_imap']->appendNamespace($new);
-                    $imp_folder = IMP_Folder::singleton();
-                    if (!$imp_folder->create($folder, $GLOBALS['prefs']->getValue('subscribe'))) {
+                    if (!$GLOBALS['injector']->getInstance('IMP_Folder')->create($folder, $GLOBALS['prefs']->getValue('subscribe'))) {
                         $folder = null;
                     }
                 }
@@ -788,7 +786,7 @@ class IMP_Application extends Horde_Registry_Application
      */
     protected function _prefsFlagManagement()
     {
-        $imp_flags = IMP_Imap_Flags::singleton();
+        $imp_flags = $GLOBALS['injector']->getInstance('IMP_Imap_Flags');
         $action = Horde_Util::getFormData('flag_action');
         $data = Horde_Util::getFormData('flag_data');
 
@@ -858,7 +856,7 @@ class IMP_Application extends Horde_Registry_Application
                         $label = $vars->accounts_server . ':' . $port . ' [' . $vars->accounts_type . ']';
                     }
 
-                    $imp_accounts = IMP_Accounts::singleton();
+                    $imp_accounts = $GLOBALS['injector']->getInstance('IMP_Accounts');
                     $imp_accounts->addAccount(array(
                         'label' => $label,
                         'port' => $port,
@@ -874,7 +872,7 @@ class IMP_Application extends Horde_Registry_Application
             break;
 
         case 'delete':
-            $imp_accounts = IMP_Accounts::singleton();
+            $imp_accounts = $GLOBALS['injector']->getInstance('IMP_Accounts');
             $tmp = $imp_accounts->getAccount($vars->accounts_data);
             if ($imp_accounts->deleteAccount($vars->accounts_data)) {
                 $GLOBALS['notification']->push(sprintf(_("Account \"%s\" deleted."), $tmp['server']), 'horde.success');
@@ -1026,10 +1024,8 @@ class IMP_Application extends Horde_Registry_Application
      */
     protected function _mailboxesChanged()
     {
-        $imp_folder = IMP_Folder::singleton();
-        $imp_folder->clearFlistCache();
-        $imaptree = IMP_Imap_Tree::singleton();
-        $imaptree->init();
+        $GLOBALS['injector']->getInstance('IMP_Folder')->clearFlistCache();
+        $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->init();
     }
 
 }
index edd2ac2..3826843 100644 (file)
@@ -47,7 +47,7 @@ class Horde_Block_imp_tree_folders extends Horde_Block
         $name_url = Horde::applicationUrl('mailbox.php')->add('no_newmail_popup', 1);
 
         /* Initialize the IMP_Tree object. */
-        $imaptree = IMP_Imap_Tree::singleton();
+        $imaptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
         $mask = IMP_Imap_Tree::NEXT_SHOWCLOSED;
         if ($GLOBALS['prefs']->getValue('subscribe')) {
             $mask |= IMP_Imap_Tree::NEXT_SHOWSUB;
index 975f7e8..388188c 100644 (file)
@@ -158,8 +158,7 @@ class IMP_Compose
               !$this->getMetadata('resume')) ||
              ($success && $GLOBALS['prefs']->getValue('auto_delete_drafts'))) &&
             ($uid = $this->getMetadata('draft_uid'))) {
-            $imp_message = IMP_Message::singleton();
-            $imp_message->delete(array($uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true)), array('nuke' => true));
+            $GLOBALS['injector']->getInstance('IMP_Message')->delete(array($uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true)), array('nuke' => true));
         }
 
         $this->deleteAllAttachments();
@@ -291,7 +290,7 @@ class IMP_Compose
             throw new IMP_Compose_Exception(_("Saving the draft failed. No draft folder specified."));
         }
 
-        $imp_folder = IMP_Folder::singleton();
+        $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
 
         /* Check for access to drafts folder. */
         if (!$imp_folder->exists($drafts_mbox) &&
@@ -594,7 +593,7 @@ class IMP_Compose
                 IMP_Maillog::log($this->_metadata['reply_type'], $this->_metadata['in_reply_to'], $recipients);
             }
 
-            $imp_message = IMP_Message::singleton();
+            $imp_message = $GLOBALS['injector']->getInstance('IMP_Message');
             $reply_uid = array($this->_metadata['uid'] . IMP::IDX_SEP . $this->_metadata['mailbox']);
 
             switch ($this->_metadata['reply_type']) {
@@ -651,7 +650,7 @@ class IMP_Compose
             /* Generate the message string. */
             $fcc = $mime_message->toString(array('defserver' => $_SESSION['imp']['maildomain'], 'headers' => $headers, 'stream' => true));
 
-            $imp_folder = IMP_Folder::singleton();
+            $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
 
             if (!$imp_folder->exists($opts['sent_folder'])) {
                 $imp_folder->create($opts['sent_folder'], $prefs->getValue('subscribe'));
index ef6538d..6eab2e3 100644 (file)
@@ -57,20 +57,18 @@ class IMP_Filter
      */
     public function blacklistMessage($indices, $show_link = true)
     {
-        if ($this->_processBWlist($indices, _("your blacklist"), 'blacklistFrom', 'showBlacklist', $show_link)) {
-            $imp_message = IMP_Message::singleton();
+        if (!$this->_processBWlist($indices, _("your blacklist"), 'blacklistFrom', 'showBlacklist', $show_link) ||
+            !($msg_count = $GLOBALS['injector']->getInstance('IMP_Message')->delete($indices))) {
+            return false;
+        }
 
-            if (($msg_count = $imp_message->delete($indices))) {
-                if ($msg_count == 1) {
-                    $GLOBALS['notification']->push(_("The message has been deleted."), 'horde.message');
-                } else {
-                    $GLOBALS['notification']->push(_("The messages have been deleted."), 'horde.message');
-                }
-                return true;
-            }
+        if ($msg_count == 1) {
+            $GLOBALS['notification']->push(_("The message has been deleted."), 'horde.message');
+        } else {
+            $GLOBALS['notification']->push(_("The messages have been deleted."), 'horde.message');
         }
 
-        return false;
+        return true;
     }
 
     /**
index 21571cf..8d08361 100644 (file)
 class IMP_Folder
 {
     /**
-     * Singleton instance.
-     *
-     * @var IMP_Folder
-     */
-    static protected $_instance = null;
-
-    /**
      * Keep around identical lists so that we don't hit the server more that
      * once in the same page for the same thing.
      *
@@ -40,25 +33,9 @@ class IMP_Folder
     protected $_cacheid = null;
 
     /**
-     * Returns a reference to the global IMP_Folder object, only creating it
-     * if it doesn't already exist. This ensures that only one IMP_Folder
-     * instance is instantiated for any given session.
-     *
-     * @return IMP_Folder  The IMP_Folder instance.
-     */
-    static public function singleton()
-    {
-        if (is_null(self::$_instance)) {
-            self::$_instance = new self();
-        }
-
-        return self::$_instance;
-    }
-
-    /**
      * Constructor.
      */
-    protected function __construct()
+    public function __construct()
     {
         if (!empty($GLOBALS['conf']['server']['cache_folders'])) {
             $this->_cacheid = 'imp_folder_cache|' . Horde_Auth::getAuth();
@@ -121,7 +98,7 @@ class IMP_Folder
             return $this->_listCache[$sig];
         }
 
-        $imaptree = IMP_Imap_Tree::singleton();
+        $imaptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
 
         $list_mask = IMP_Imap_Tree::FLIST_CONTAINER | IMP_Imap_Tree::FLIST_OB;
         if (!$sub) {
@@ -198,10 +175,7 @@ class IMP_Folder
         }
 
         if (!empty($deleted)) {
-            /* Update the IMAP_Tree cache. */
-            $imaptree = IMP_Imap_Tree::singleton();
-            $imaptree->delete($deleted);
-
+            $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->delete($deleted);
             $this->_onDelete($deleted);
         }
 
@@ -284,9 +258,8 @@ class IMP_Folder
         /* Reset the folder cache. */
         $this->clearFlistCache();
 
-        /* Update the IMAP_Tree object. */
-        $imaptree = IMP_Imap_Tree::singleton();
-        $imaptree->insert($folder);
+        /* Update the mailbox tree. */
+        $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->insert($folder);
 
         /* Recreate Virtual Folders. */
         $GLOBALS['imp_search']->initialize(true);
@@ -303,7 +276,7 @@ class IMP_Folder
      */
     public function exists($folder)
     {
-        $imaptree = IMP_Imap_Tree::singleton();
+        $imaptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
         $elt = $imaptree->get($folder);
         if ($elt) {
             return !$imaptree->isContainer($elt);
@@ -344,7 +317,7 @@ class IMP_Folder
         $deleted = array($old);
         $inserted = array($new);
 
-        $imaptree = IMP_Imap_Tree::singleton();
+        $imaptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
 
         /* Get list of any folders that are underneath this one. */
         $all_folders = array_merge(array($old), $imaptree->folderList(IMP_Imap_Tree::FLIST_UNSUB, $old));
@@ -405,9 +378,7 @@ class IMP_Folder
         }
 
         if (!empty($subscribed)) {
-            /* Initialize the IMAP_Tree object. */
-            $imaptree = IMP_Imap_Tree::singleton();
-            $imaptree->subscribe($subscribed);
+            $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->subscribe($subscribed);
 
             /* Reset the folder cache. */
             $this->clearFlistCache();
@@ -451,9 +422,7 @@ class IMP_Folder
         }
 
         if (!empty($unsubscribed)) {
-            /* Initialize the IMAP_Tree object. */
-            $imaptree = IMP_Imap_Tree::singleton();
-            $imaptree->unsubscribe($unsubscribed);
+            $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->unsubscribe($unsubscribed);
 
             /* Reset the folder cache. */
             $this->clearFlistCache();
index 1207b3e..48ef92e 100644 (file)
@@ -148,14 +148,12 @@ class IMP
      */
     static public function flistSelect($options = array())
     {
-        $imp_folder = IMP_Folder::singleton();
-
         /* Don't filter here - since we are going to parse through every
          * member of the folder list below anyway, we can filter at that time.
          * This allows us the have a single cached value for the folder list
          * rather than a cached value for each different mailbox we may
          * visit. */
-        $mailboxes = $imp_folder->flist();
+        $mailboxes = $GLOBALS['injector']->getInstance('IMP_Folder')->flist();
         $text = '';
 
         if (!empty($options['heading']) &&
index 8d9c88f..aff704f 100644 (file)
 class IMP_Imap_Acl
 {
     /**
-     * Singleton instance.
-     *
-     * @var IMP_Imap_Acl
-     */
-    static protected $_instance = null;
-
-    /**
      * Hash containing the list of possible rights and a human readable
      * description of each.
      *
@@ -36,27 +29,11 @@ class IMP_Imap_Acl
     protected $_protected;
 
     /**
-     * Attempts to return a reference to a concrete object instance.
-     * It will only create a new instance if no instance currently exists.
-     *
-     * @return IMP_Imap_Acl  The created concrete instance.
-     * @throws Horde_Exception
-     */
-    static public function singleton()
-    {
-        if (!self::$_instance) {
-            self::$_instance = new self();
-        }
-
-        return self::$_instance;
-    }
-
-    /**
      * Constructor.
      *
      * @throws Horde_Exception
      */
-    protected function __construct()
+    public function __construct()
     {
         if ($_SESSION['imp']['protocol'] != 'imap') {
             throw new Horde_Exception(_("ACL requires an IMAP server."));
index 47ba846..eeedf95 100644 (file)
@@ -17,13 +17,6 @@ class IMP_Imap_Flags
     const PREFIX = 'impflag';
 
     /**
-     * Singleton instance.
-     *
-     * @var IMP_Imap_Flags
-     */
-    static protected $_instance;
-
-    /**
      * The cached list of flags.
      *
      * @var array
@@ -31,21 +24,6 @@ class IMP_Imap_Flags
     protected $_flags = null;
 
     /**
-     * Attempts to return a reference to a concrete object instance.
-     * It will only create a new instance if no instance currently exists.
-     *
-     * @return IMP_Imap_Flags  The created concrete instance.
-     */
-    static public function singleton()
-    {
-        if (!isset(self::$_instance)) {
-            self::$_instance = new self();
-        }
-
-        return self::$_instance;
-    }
-
-    /**
      * Save the flag list to the prefs backend.
      */
     protected function _save()
index d1bf571..cdec50b 100644 (file)
@@ -64,11 +64,11 @@ class IMP_Imap_Tree
     const OTHER_KEY = 'other\0';
 
     /**
-     * Singleton instance
+     * The cache ID value.
      *
-     * @var IMP_Imap_Tree
+     * @var string
      */
-    static protected $_instance;
+    public $cacheId;
 
     /**
      * Array containing the mailbox tree.
@@ -204,33 +204,9 @@ class IMP_Imap_Tree
     protected $_eltCache;
 
     /**
-     * Attempts to return a reference to a concrete IMP_Imap_Tree instance.
-     *
-     * If an IMP_Imap_Tree object is currently stored in the cache, re-create
-     * that object.  Else, create a new instance.  Ensures that only one
-     * instance is available at any time.
-     *
-     * @return IMP_Imap_Tree  The object or null.
-     */
-    static public function singleton()
-    {
-        if (!isset(self::$_instance)) {
-            if (!empty($_SESSION['imp']['cache']['tree'])) {
-                self::$_instance = @unserialize($GLOBALS['injector']->getInstance('Horde_Cache')->get($_SESSION['imp']['cache']['tree'], 86400));
-            }
-
-            if (empty(self::$_instance)) {
-                self::$_instance = new self();
-            }
-        }
-
-        return self::$_instance;
-    }
-
-    /**
      * Constructor.
      */
-    protected function __construct()
+    public function __construct()
     {
         if ($_SESSION['imp']['protocol'] == 'imap') {
             $ns = $GLOBALS['imp_imap']->getNamespaceList();
@@ -241,10 +217,6 @@ class IMP_Imap_Tree
                 : $ns;
         }
 
-        if ($imp_cache = $GLOBALS['injector']->getInstance('Horde_Cache')) {
-            $_SESSION['imp']['cache']['tree'] = uniqid(mt_rand() . Horde_Auth::getAuth());
-        }
-
         $this->init();
         $this->__wakeup();
     }
@@ -273,9 +245,8 @@ class IMP_Imap_Tree
     {
         /* We only need to store the object if using Horde_Cache and the tree
          * has changed. */
-        if (!empty($this->_changed) &&
-            isset($_SESSION['imp']['cache']['tree'])) {
-            $GLOBALS['injector']->getInstance('Horde_Cache')->set($_SESSION['imp']['cache']['tree'], serialize($this), 86400);
+        if (!empty($this->_changed) && $this->cacheId) {
+            $GLOBALS['injector']->getInstance('Horde_Cache')->set($this->cacheId, serialize($this), 86400);
         }
     }
 
@@ -1206,8 +1177,8 @@ class IMP_Imap_Tree
         }
 
         $changed = false;
+        $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
 
-        $imp_folder = IMP_Folder::singleton();
         $this->getPollList();
         foreach ($id as $val) {
             if (!$this->isSubscribed($this->_tree[$val])) {
diff --git a/imp/lib/Injector/Binder/Imaptree.php b/imp/lib/Injector/Binder/Imaptree.php
new file mode 100644 (file)
index 0000000..e974f8b
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Binder for IMP_Imap_Tree::.
+ *
+ * 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_Imaptree implements Horde_Injector_Binder
+{
+    /**
+     * If an IMP_Imap_Tree object is currently stored in the cache, re-create
+     * that object.  Else, create a new instance.
+     */
+    public function create(Horde_Injector $injector)
+    {
+        $cache = $injector->getInstance('Horde_Cache');
+
+        if (empty($_SESSION['imp']['cache']['tree'])) {
+            $_SESSION['imp']['cache']['tree'] = uniqid(mt_rand() . Horde_Auth::getAuth());
+        } elseif ($instance = @unserialize($cache->get($_SESSION['imp']['cache']['tree'], 86400))) {
+            return $instance;
+        }
+
+        $instance = new IMP_Imap_Tree();
+        $instance->cacheId = $_SESSION['imp']['cache']['tree'];
+
+        return $instance;
+    }
+
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+
+}
index b70d929..f9093c0 100644 (file)
@@ -25,8 +25,7 @@ class IMP_LoginTasks_SystemTask_GarbageCollection extends Horde_LoginTasks_Syste
     public function execute()
     {
         /* Purge non-existent nav_poll entries. */
-        $imaptree = IMP_Imap_Tree::singleton();
-        $imaptree->getPollList(true, true);
+        $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->getPollList(true, true);
 
         /* Do garbage collection on sentmail entries. */
         $sentmail = IMP_Sentmail::factory();
index 8928283..ffe4163 100644 (file)
@@ -35,7 +35,7 @@ class IMP_LoginTasks_Task_DeleteSentmailMonthly extends Horde_LoginTasks_Task
            old sent-mail folders. Then sort this array according to
            the date. */
         $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
-        $imp_folder = IMP_Folder::singleton();
+        $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
         $sent_mail_folders = $identity->getAllSentmailFolders();
 
         $folder_array = array();
index 137c163..37f0fc9 100644 (file)
@@ -35,8 +35,8 @@ class IMP_LoginTasks_Task_PurgeSentmail extends Horde_LoginTasks_Task
      */
     public function execute()
     {
-        $imp_folder = IMP_Folder::singleton();
-        $imp_message = IMP_Message::singleton();
+        $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
+        $imp_message = $GLOBALS['injector']->getInstance('IMP_Message');
 
         $mbox_list = $this->_getFolders();
 
index eea026c..5dfe8dd 100644 (file)
@@ -41,8 +41,7 @@ class IMP_LoginTasks_Task_PurgeSpam extends Horde_LoginTasks_Task
         }
 
         /* Make sure the Spam folder exists. */
-        $imp_folder = IMP_Folder::singleton();
-        if (!$imp_folder->exists($spam_folder)) {
+        if (!$GLOBALS['injector']->getInstance('IMP_Folder')->exists($spam_folder)) {
             return false;
         }
 
@@ -60,8 +59,7 @@ class IMP_LoginTasks_Task_PurgeSpam extends Horde_LoginTasks_Task
         }
 
         /* Go through the message list and delete the messages. */
-        $imp_message = IMP_Message::singleton();
-        if ($imp_message->delete(array($spam_folder => $msg_ids), array('nuke' => true))) {
+        if ($GLOBALS['injector']->getInstance('IMP_Message')->delete(array($spam_folder => $msg_ids), array('nuke' => true))) {
             $msgcount = count($msg_ids);
             $GLOBALS['notification']->push(sprintf(ngettext("Purging %d message from Spam folder.", "Purging %d messages from Spam folder.", $msgcount), $msgcount), 'horde.message');
         }
index cda5c37..10b2fbf 100644 (file)
@@ -41,8 +41,7 @@ class IMP_LoginTasks_Task_PurgeTrash extends Horde_LoginTasks_Task
         }
 
         /* Make sure the Trash folder exists. */
-        $imp_folder = IMP_Folder::singleton();
-        if (!$imp_folder->exists($trash_folder)) {
+        if (!$GLOBALS['injector']->getInstance('IMP_Folder')->exists($trash_folder)) {
             return false;
         }
 
@@ -60,8 +59,7 @@ class IMP_LoginTasks_Task_PurgeTrash extends Horde_LoginTasks_Task
         }
 
         /* Go through the message list and delete the messages. */
-        $imp_message = IMP_Message::singleton();
-        if ($imp_message->delete(array($trash_folder => $msg_ids), array('nuke' => true))) {
+        if ($GLOBALS['injector']->getInstance('IMP_Message')->delete(array($trash_folder => $msg_ids), array('nuke' => true))) {
             $msgcount = count($msg_ids);
             $GLOBALS['notification']->push(sprintf(ngettext("Purging %d message from Trash folder.", "Purging %d messages from Trash folder.", $msgcount), $msgcount), 'horde.message');
         }
index 2bd6265..e9cd6e5 100644 (file)
@@ -34,7 +34,7 @@ class IMP_LoginTasks_Task_RenameSentmailMonthly extends Horde_LoginTasks_Task
         $success = true;
 
         $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
-        $imp_folder = IMP_Folder::singleton();
+        $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
 
         foreach ($identity->getAllSentmailfolders() as $sent_folder) {
             /* Display a message to the user and rename the folder.
index f54ebde..6f54f63 100644 (file)
 class IMP_Message
 {
     /**
-     * The singleton IMP_Message instance
-     *
-     * @var IMP_Message
-     */
-    protected static $_instance = null;
-
-    /**
      * Using POP to access mailboxes?
      *
      * @var boolean
@@ -33,25 +26,9 @@ class IMP_Message
     protected $_usepop = false;
 
     /**
-     * Returns a reference to the global IMP_Message object, only creating it
-     * if it doesn't already exist. This ensures that only one IMP_Message
-     * instance is instantiated for any given session.
-     *
-     * @return IMP_Message  The IMP_Message instance.
-     */
-    public static function singleton()
-    {
-        if (!self::$_instance) {
-            self::$_instance = new self();
-        }
-
-        return self::$_instance;
-    }
-
-    /**
      * Constructor.
      */
-    protected function __construct()
+    public function __construct()
     {
         if ($_SESSION['imp']['protocol'] == 'pop') {
             $this->_usepop = true;
@@ -92,7 +69,7 @@ class IMP_Message
         }
 
         if ($new) {
-            $imp_folder = IMP_Folder::singleton();
+            $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
             if (!$imp_folder->exists($targetMbox) &&
                 !$imp_folder->create($targetMbox, $prefs->getValue('subscribe'))) {
                 return false;
@@ -197,7 +174,7 @@ class IMP_Message
         /* Check for Trash folder. */
         $use_trash_folder = !$this->_usepop && empty($options['nuke']) && !$use_vtrash && $use_trash;
         if ($use_trash_folder) {
-            $imp_folder = IMP_Folder::singleton();
+            $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
 
             if (!$imp_folder->exists($trash) &&
                 !$imp_folder->create($trash, $prefs->getValue('subscribe'))) {
index 0c624ff..628d225 100644 (file)
@@ -118,7 +118,7 @@ class IMP_Search
     public function initialize($no_vf = false)
     {
         if (!$no_vf) {
-            $imaptree = IMP_Imap_Tree::singleton();
+            $imaptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
             foreach ($this->_getVFolderList() as $key => $val) {
                 if (!empty($val['v']) &&
                     !$this->isEditableVFolder($key)) {
@@ -227,10 +227,8 @@ class IMP_Search
      */
     public function flagFields()
     {
-        $imp_flags = IMP_Imap_Flags::singleton();
-        $flist = $imp_flags->getFlagList(null);
-
         $flags = array();
+        $flist = $GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getFlagList(null);
 
         for ($i = 0, $cnt = count($flist['set']); $i < $cnt; ++$i) {
             $flags[$flist['set'][$i]['f']] = $flist['set'][$i]['l'];
@@ -396,8 +394,7 @@ class IMP_Search
             $this->_saveVFolderList($vfolders);
 
             if (!$no_delete) {
-                $imaptree = IMP_Imap_Tree::singleton();
-                $imaptree->delete($id);
+                $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->delete($id);
             }
         }
     }
@@ -497,8 +494,7 @@ class IMP_Search
             $this->_saveVFolderList($vfolders);
         }
 
-        $imaptree = IMP_Imap_Tree::singleton();
-        $imaptree->insertVFolders(array($id => $label));
+        $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->insertVFolders(array($id => $label));
 
         return $id;
     }
@@ -519,8 +515,7 @@ class IMP_Search
         }
 
         /* Create Virtual Trash with new folder list. */
-        $imp_folder = IMP_Folder::singleton();
-        $fl = $imp_folder->flist();
+        $fl = $GLOBALS['injector']->getInstance('IMP_Folder')->flist();
         $flist = array('INBOX');
         foreach ($fl as $mbox) {
             if (!empty($mbox['val'])) {
@@ -574,8 +569,7 @@ class IMP_Search
         }
 
         /* Create Virtual INBOX with nav_poll list. */
-        $imaptree = IMP_Imap_Tree::singleton();
-        $flist = $imaptree->getPollList();
+        $flist = $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->getPollList();
 
         $query = new Horde_Imap_Client_Search_Query();
         $query->flag('\\seen', false);
index 701056d..cbea196 100644 (file)
@@ -180,7 +180,7 @@ class IMP_Spam
         switch ($action) {
         case 'spam':
             if ($result = $GLOBALS['prefs']->getValue('delete_spam_after_report')) {
-                $imp_message = IMP_Message::singleton();
+                $imp_message = $GLOBALS['injector']->getInstance('IMP_Message');
                 switch ($result) {
                 case 1:
                     $msg_count = $imp_message->delete($indices);
@@ -212,7 +212,7 @@ class IMP_Spam
 
         case 'notspam':
             if ($result = $GLOBALS['prefs']->getValue('move_ham_after_report')) {
-                $imp_message = IMP_Message::singleton();
+                $imp_message = $GLOBALS['injector']->getInstance('IMP_Message');
                 if (!$imp_message->copy('INBOX', 'move', $indices)) {
                     $result = 0;
                 }
index c6bf4c0..6651988 100644 (file)
@@ -32,8 +32,7 @@ class IMP_Ui_Block
         }
 
         /* Get list of mailboxes to poll. */
-        $imptree = IMP_Imap_Tree::singleton();
-        $poll = $imptree->getPollList(true);
+        $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);
 
         $anyUnseen = false;
index eec6742..4ffff82 100644 (file)
@@ -58,12 +58,11 @@ class IMP_Ui_Folder
         $dir2 = $elt['user_icon']
             ? Horde::img($elt['icon'], $elt['alt'], null, $elt['icondir'])
             : '<span class="foldersImg ' . $elt['class'] . '"></span>';
-        $imaptree = IMP_Imap_Tree::singleton();
 
         if ($elt['children'] && isset($options['expand_url'])) {
             $dir = $options['expand_url']->copy()->add('folder', $elt['value']);
 
-            if ($imaptree->isOpen($elt['base_elt'])) {
+            if ($GLOBALS['injector']->getInstance('IMP_Imap_Tree')->isOpen($elt['base_elt'])) {
                 if (!is_null($dir)) {
                     $dir->add('actionID', 'collapse_folder');
                     $alt = _("Collapse Folder");
index a48eb3f..3006815 100644 (file)
@@ -119,8 +119,7 @@ class IMP_Ui_Message
             $success = true;
 
             if ($mdn_flag) {
-                $imp_message = IMP_Message::singleton();
-                $imp_message->flag(array('$MDNSent'), $uid . IMP::IDX_SEP . $mailbox, true);
+                $GLOBALS['injector']->getInstance('IMP_Message')->flag(array('$MDNSent'), $uid . IMP::IDX_SEP . $mailbox, true);
             }
         } catch (Horde_Mime_Exception $e) {
             $success = false;
index 254703d..af44491 100644 (file)
@@ -27,7 +27,7 @@ class IMP_Ui_Search
         $search_array = array();
         $search_fields = $GLOBALS['imp_search']->searchFields();
         $flag_fields = $GLOBALS['imp_search']->flagFields();
-        $imp_flags = IMP_Imap_Flags::singleton();
+        $imp_flags = $GLOBALS['injector']->getInstance('IMP_Imap_Flags');
         $or_search = false;
 
         foreach ($search as $rule) {
index b367173..91fa395 100644 (file)
@@ -94,7 +94,7 @@ class IMP_Views_Compose
         /* Create list for sent-mail selection. */
         if (!empty($GLOBALS['conf']['user']['select_sentmail_folder']) &&
             !$GLOBALS['prefs']->isLocked('sent_mail_folder')) {
-            $imp_folder = IMP_Folder::singleton();
+            $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
 
             /* Check to make sure the sent-mail folders are created - they
              * need to exist to show up in drop-down list. */
index ef15ea8..2783d63 100644 (file)
@@ -133,8 +133,7 @@ class IMP_Views_ListMessages
          * is a chance that the mailbox doesn't exist. If there is at least
          * 1 message, we don't need this check. */
         if (empty($msgcount) && !$is_search) {
-            $imp_folder = IMP_Folder::singleton();
-            if (!$imp_folder->exists($mbox)) {
+            if (!$GLOBALS['injector']->getInstance('IMP_Folder')->exists($mbox)) {
                 $GLOBALS['notification']->push(sprintf(_("Mailbox %s does not exist."), IMP::getLabel($mbox)), 'horde.error');
             }
 
@@ -374,8 +373,7 @@ class IMP_Views_ListMessages
                 }
             }
 
-            $imp_flags = IMP_Imap_Flags::singleton();
-            $flag_parse = $imp_flags->parse(array(
+            $flag_parse = $GLOBALS['injector']->getInstance('IMP_Imap_Flags')->parse(array(
                 'atc' => isset($ob['structure']) ? $ob['structure'] : null,
                 'flags' => $ob['flags'],
                 'personal' => Horde_Mime_Address::getAddressesFromObject($ob['envelope']['to']),
index b14cd71..924716f 100644 (file)
@@ -44,8 +44,7 @@ case 'm':
 // 'e' = expunge mailbox
 case 'e':
     if (!$readonly) {
-        $imp_message = IMP_Message::singleton();
-        $imp_message->expungeMailbox(array($imp_mbox['mailbox'] => 1));
+        $injector->getInstance('IMP_Message')->expungeMailbox(array($imp_mbox['mailbox'] => 1));
     }
     break;
 
@@ -138,8 +137,7 @@ while (list(,$ob) = each($mbox_info['overview'])) {
     }
 
     /* Get flag information. */
-    $imp_flags = IMP_Imap_Flags::singleton();
-    $flag_parse = $imp_flags->parse(array(
+    $flag_parse = $injector->getInstance('IMP_Imap_Flags')->parse(array(
         'flags' => $ob['flags'],
         'personal' => Horde_Mime_Address::getAddressesFromObject($ob['envelope']['to']),
         'priority' => $ob['headers']
index 8272ba3..53273bc 100644 (file)
@@ -73,7 +73,7 @@ if (!is_array(($indices = Horde_Util::getFormData('indices')))) {
 }
 
 $do_filter = false;
-$imp_flags = IMP_Imap_Flags::singleton();
+$imp_flags = $injector->getInstance('IMP_Imap_Flags');
 $open_compose_window = null;
 
 /* Run through the action handlers */
@@ -140,29 +140,26 @@ case 'fwd_digest':
 
 case 'delete_messages':
     if (!empty($indices)) {
-        $imp_message = IMP_Message::singleton();
-        $imp_message->delete($indices);
+        $injector->getInstance('IMP_Message')->delete($indices);
     }
     break;
 
 case 'undelete_messages':
     if (!empty($indices)) {
-        $imp_message = IMP_Message::singleton();
-        $imp_message->undelete($indices);
+        $injector->getInstance('IMP_Message')->undelete($indices);
     }
     break;
 
 case 'move_messages':
 case 'copy_messages':
     if (!empty($indices) && !empty($targetMbox)) {
-        $imp_message = IMP_Message::singleton();
         if (!empty($newMbox) && ($newMbox == 1)) {
             $targetMbox = IMP::folderPref($targetMbox, true);
             $newMbox = true;
         } else {
             $newMbox = false;
         }
-        $imp_message->copy($targetMbox, ($actionID == 'move_messages') ? 'move' : 'copy', $indices, $newMbox);
+        $injector->getInstance('IMP_Message')->copy($targetMbox, ($actionID == 'move_messages') ? 'move' : 'copy', $indices, $newMbox);
     }
     break;
 
@@ -170,8 +167,7 @@ case 'flag_messages':
     $flag = Horde_Util::getPost('flag');
     if ($flag && !empty($indices)) {
         $flag = $imp_flags->parseFormId($flag);
-        $imp_message = IMP_Message::singleton();
-        $imp_message->flag(array($flag['flag']), $indices, $flag['set']);
+        $injector->getInstance('IMP_Message')->flag(array($flag['flag']), $indices, $flag['set']);
     }
     break;
 
@@ -181,8 +177,7 @@ case 'hide_deleted':
     break;
 
 case 'expunge_mailbox':
-    $imp_message = IMP_Message::singleton();
-    $imp_message->expungeMailbox(array($imp_mbox['mailbox'] => 1));
+    $injector->getInstance('IMP_Message')->expungeMailbox(array($imp_mbox['mailbox'] => 1));
     break;
 
 case 'filter':
@@ -190,8 +185,7 @@ case 'filter':
     break;
 
 case 'empty_mailbox':
-    $imp_message = IMP_Message::singleton();
-    $imp_message->emptyMailbox(array($imp_mbox['mailbox']));
+    $injector->getInstance('IMP_Message')->emptyMailbox(array($imp_mbox['mailbox']));
     break;
 
 case 'view_messages':
index 1ac7677..66bac71 100644 (file)
@@ -28,7 +28,7 @@ if (!$imp_mailbox->isValidIndex(false)) {
     exit;
 }
 
-$imp_message = IMP_Message::singleton();
+$imp_message = $injector->getInstance('IMP_Message');
 $imp_hdr_ui = new IMP_Ui_Headers();
 $imp_ui = new IMP_Ui_Message();
 
@@ -220,8 +220,7 @@ if (!empty($msgAddresses)) {
     }
 }
 
-$imp_flags = IMP_Imap_Flags::singleton();
-$flag_parse = $imp_flags->parse(array(
+$flag_parse = $injector->getInstance('IMP_Imap_Flags')->parse(array(
     'flags' => $flags,
     'personal' => $match_identity
 ));
index b2af2ee..9aea21d 100644 (file)
@@ -38,7 +38,7 @@ if (!$imp_mailbox->isValidIndex(false)) {
 }
 
 /* Initialize IMP_Message object. */
-$imp_message = IMP_Message::singleton();
+$imp_message = $injector->getInstance('IMP_Message');
 
 /* Initialize the user's identities. */
 $user_identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
@@ -67,7 +67,7 @@ $mailbox_name = $index_array['mailbox'];
 $uid = $index_array['uid'];
 $indices_array = array($mailbox_name => array($uid));
 
-$imp_flags = IMP_Imap_Flags::singleton();
+$imp_flags = $injector->getInstance('IMP_Imap_Flags');
 $imp_hdr_ui = new IMP_Ui_Headers();
 $imp_ui = new IMP_Ui_Message();
 
index dcadcd6..71a69d6 100644 (file)
@@ -35,8 +35,7 @@ if (!empty($request)) {
         $mailbox = $imp_imap->appendNamespace(preg_replace('/\//', $ns_info['delimiter'], trim($request_parts[0], '/')));
 
         /* Make sure mailbox exists or else exit immediately. */
-        $imp_folder = IMP_Folder::singleton();
-        if (!$imp_folder->exists($mailbox)) {
+        if (!$injector->getInstance('IMP_Folder')->exists($mailbox)) {
             exit;
         }
     }
index c44acb7..8c4ef4d 100644 (file)
@@ -86,7 +86,7 @@ if (!empty($criteria)) {
 }
 
 /* Generate master folder list. */
-$imp_imap_tree = IMP_Imap_Tree::singleton();
+$imp_imap_tree = $injector->getInstance('IMP_Imap_Tree');
 $mask = IMP_Imap_Tree::NEXT_SHOWCLOSED;
 $subscribe = $prefs->getValue('subscribe');
 if ($subscribe || !Horde_Util::getFormData('show_unsub')) {
index 33fadda..9da8d6b 100644 (file)
@@ -18,8 +18,7 @@ $has_whitelist = $registry->hasMethod('mail/whitelistFrom');
 $show_quota = (isset($_SESSION['imp']['quota']) && is_array($_SESSION['imp']['quota']));
 
 // Get the list of available IMAP flags
-$imp_flags = IMP_Imap_Flags::singleton();
-$flag_list = $imp_flags->getList(array('imap' => true));
+$flag_list = $injector->getInstance('IMP_Imap_Flags')->getList(array('imap' => true));
 
 function _simpleButton($id, $text, $image, $nodisplay = false)
 {
index 3ef1440..970c793 100644 (file)
@@ -27,8 +27,7 @@ foreach ($dimp_block_list as $block) {
 }
 
 /* Generate flag array. */
-$imp_flags = IMP_Imap_Flags::singleton();
-foreach ($imp_flags->getList(array('fgcolor' => true)) as $val) {
+foreach ($GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getList(array('fgcolor' => true)) as $val) {
     $flags[$val['flag']] = array_filter(array(
         'b' => isset($val['b']) ? $val['b'] : null,
         'c' => $val['c'],
index b24817a..05eb85c 100644 (file)
@@ -50,8 +50,7 @@
 <input id="cancel_button" type="button" class="button" value="<?php echo _("Cancel") ?>" />
 <?php else: ?>
 <?php
-$imp_accounts = IMP_Accounts::singleton();
-$accounts_list = $imp_accounts->getList();
+$accounts_list = $GLOBALS['injector']->getInstance('IMP_Accounts')->getList();
 $delete_img = Horde::img('delete.png');
 ?>
 
index e70da8d..4c9518b 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /* Get the list of flags. */
-$imp_flags = IMP_Imap_Flags::singleton();
-$flaglist = $imp_flags->getList(array('div' => true, 'fgcolor' => true));
+$flaglist = $GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getList(array('div' => true, 'fgcolor' => true));
 
 /* Get the graphics. */
 $picker_img = Horde::img('colorpicker.png', _("Color Picker"), '', $registry->getImageDir('horde'));
index 1a49e88..bb5520d 100644 (file)
@@ -136,8 +136,7 @@ foreach ($loop_array as $mbox => $idxlist) {
 }
 
 /* Flag messages as seen. */
-$imp_message = IMP_Message::singleton();
-$imp_message->flag(array('\\seen'), $loop_array);
+$injector->getInstance('IMP_Message')->flag(array('\\seen'), $loop_array);
 
 $template = $injector->createInstance('Horde_Template');
 $template->setOption('gettext', true);