}
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);
break;
}
-$imp_folder = IMP_Folder::singleton();
+$imp_folder = $injector->getInstance('IMP_Folder');
$rights = $ACLDriver->getRights();
if (empty($folder)) {
/* 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);
}
$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. */
));
/* 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());
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;
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;
$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);
class IMP_Accounts
{
/**
- * Singleton instance.
- *
- * @var IMP_Accounts
- */
- static protected $_instance;
-
- /**
* The cached list of accounts.
*
* @var array
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()
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);
}
return false;
}
- $imptree = IMP_Imap_Tree::singleton();
+ $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
$imptree->eltDiffStart();
if ($GLOBALS['imp_search']->isEditableVFolder($vars->mbox)) {
$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) {
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);
}
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;
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;
*/
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;
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']);
}
$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);
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));
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);
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);
}
}
$flags = Horde_Serialize::unserialize($vars->flags, Horde_Serialize::JSON);
- $imp_message = IMP_Message::singleton();
$result = false;
$set = $notset = array();
}
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
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'));
}
$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;
$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;
/* 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(
*/
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();
*/
public function folderlist()
{
- $imp_folder = IMP_Folder::singleton();
- return $imp_folder->flist();
+ return $GLOBALS['injector']->getInstance('IMP_Folder')->flist();
}
/**
*/
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;
}
*/
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));
}
/**
*/
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);
}
/**
*/
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);
}
/**
*/
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);
}
/**
$opts['mailbox'] = $mailbox;
}
- $imp_flags = IMP_Imap_Flags::singleton();
- return $imp_flags->getList($opts);
+ return $GLOBALS['injector']->getInstance('IMP_Imap_Flags')->getList($opts);
}
}
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();
}
}
- 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. */
}
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'));
}
} 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;
}
}
*/
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');
$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,
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');
*/
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();
}
}
$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;
!$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();
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) &&
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']) {
/* 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'));
*/
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;
}
/**
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.
*
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();
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) {
}
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);
}
/* 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);
*/
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);
$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));
}
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();
}
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();
*/
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']) &&
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.
*
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."));
const PREFIX = 'impflag';
/**
- * Singleton instance.
- *
- * @var IMP_Imap_Flags
- */
- static protected $_instance;
-
- /**
* The cached list of flags.
*
* @var array
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()
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.
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();
: $ns;
}
- if ($imp_cache = $GLOBALS['injector']->getInstance('Horde_Cache')) {
- $_SESSION['imp']['cache']['tree'] = uniqid(mt_rand() . Horde_Auth::getAuth());
- }
-
$this->init();
$this->__wakeup();
}
{
/* 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);
}
}
}
$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])) {
--- /dev/null
+<?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;
+ }
+
+}
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();
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();
*/
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();
}
/* 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;
}
}
/* 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');
}
}
/* 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;
}
}
/* 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');
}
$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.
class IMP_Message
{
/**
- * The singleton IMP_Message instance
- *
- * @var IMP_Message
- */
- protected static $_instance = null;
-
- /**
* Using POP to access mailboxes?
*
* @var boolean
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;
}
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;
/* 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'))) {
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)) {
*/
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'];
$this->_saveVFolderList($vfolders);
if (!$no_delete) {
- $imaptree = IMP_Imap_Tree::singleton();
- $imaptree->delete($id);
+ $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->delete($id);
}
}
}
$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;
}
}
/* 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'])) {
}
/* 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);
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);
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;
}
}
/* 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;
$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");
$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;
$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) {
/* 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. */
* 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');
}
}
}
- $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']),
// '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;
}
/* 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']
}
$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 */
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;
$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;
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':
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':
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();
}
}
-$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
));
}
/* 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'));
$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();
$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;
}
}
}
/* 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')) {
$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)
{
}
/* 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'],
<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');
?>
<?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'));
}
/* 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);