}
try {
- $imp_contents = IMP_Contents::singleton($vars->uid . IMP::IDX_SEP . $vars->folder);
+ $imp_contents = $injector->getInstance('IMP_Contents')->getOb($vars->folder, $vars->uid);
} catch (Horde_Exception $e) {
$notification->push(_("Requested message not found."), 'horde.error');
$vars->uid = $vars->folder = null;
case 'resume':
try {
- $result = $imp_compose->resumeDraft($vars->uid . IMP::IDX_SEP . $vars->folder);
+ $result = $imp_compose->resumeDraft($vars->folder, $vars->uid);
if ($result['mode'] == 'html') {
$show_editor = true;
// 'd' = draft
case 'd':
try {
- $result = $imp_compose->resumeDraft($imp_mbox['uid'] . IMP::IDX_SEP . $imp_mbox['thismailbox']);
+ $result = $imp_compose->resumeDraft($imp_mbox['thismailbox'], $imp_mbox['uid']);
$msg = $result['msg'];
$header = array_merge($header, $result['header']);
case 'draft':
try {
- $result = $imp_compose->resumeDraft($uid . IMP::IDX_SEP . $thismailbox);
+ $result = $imp_compose->resumeDraft($thismailbox, $uid);
if (!is_null($rtemode)) {
$rtemode = ($result['mode'] == 'html');
if (!($imp_contents = $imp_compose->getContentsOb())) {
$indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($this->_vars->uid);
$i = each($indices);
- $imp_contents = IMP_Contents::singleton(reset($i['value']) . IMP::IDX_SEP . $i['key']);
+ $imp_contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($i['key'], reset($i['value']));
}
return array($imp_compose, $imp_contents);
{
/* Add IMP-specific binders. */
$binders = array(
+ 'IMP_Contents' => new IMP_Injector_Binder_Contents(),
'IMP_Crypt_Pgp' => new IMP_Injector_Binder_Pgp(),
'IMP_Crypt_Smime' => new IMP_Injector_Binder_Smime(),
'IMP_Folder' => new IMP_Injector_Binder_Folder(),
/**
* Resumes a previously saved draft message.
*
- * @param string $uid The IMAP message mailbox/index. The uid should
- * be in IMP::parseIndicesList() format #1.
+ * @param string $mailbox Draft mailbox.
+ * @param integer $uid Message UID.
*
* @return mixed An array with the following keys:
* <pre>
* </pre>
* @throws IMP_Compose_Exception
*/
- public function resumeDraft($uid)
+ public function resumeDraft($mailbox, $uid)
{
try {
- $contents = IMP_Contents::singleton($uid);
- } catch (Horde_Exception $e) {
+ $contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($mailbox, $uid);
+ } catch (IMP_Exception $e) {
throw new IMP_Compose_Exception($e);
}
// even though the server is the same. UIDVALIDITY should
// catch any true server/backend changes.
($GLOBALS['imp_imap']->checkUidvalidity($imap_url['mailbox']) == $imap_url['uidvalidity']) &&
- IMP_Contents::singleton($imap_url['uid'] . IMP::IDX_SEP . $imap_url['mailbox'])) {
+ $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($imap_url['uid'] . IMP::IDX_SEP . $imap_url['mailbox'])) {
$this->_metadata['mailbox'] = $imap_url['mailbox'];
$this->_metadata['reply_type'] = $reply_type;
$this->_metadata['uid'] = $imap_url['uid'];
}
- } catch (Horde_Exception $e) {}
+ } catch (Exception $e) {}
}
- $this->_metadata['draft_uid_resume'] = $uid;
+ $this->_metadata['draft_uid_resume'] = $uid . IMP::IDX_SEP . $mailbox;
$this->_modified = true;
return array(
foreach ($msgList as $mbox => $indicesList) {
foreach ($indicesList as $idx) {
++$attached;
- $contents = IMP_Contents::singleton($idx . IMP::IDX_SEP . $mbox);
+ $contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($mbox, $idx);
$headerob = $contents->getHeaderOb();
$part = new Horde_Mime_Part();
public function getContentsOb()
{
return $this->getMetadata('reply_type')
- ? IMP_Contents::singleton($this->getMetadata('uid') . IMP::IDX_SEP . $this->getMetadata('mailbox'))
+ ? $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($this->getMetadata('mailbox'), $this->getMetadata('uid'))
: null;
}
public $lastBodyPartDecode = null;
/**
- * Singleton instances
- *
- * @var array
- */
- static protected $_instances = array();
-
- /**
- * Internal counter for ensuring Horde_Mime_Part objects passed to
- * singleton() are given unique objects.
- *
- * @var integer
- */
- static protected $_mimepartid = 1;
-
- /**
* The IMAP UID of the message.
*
* @var integer
protected $_embedded = array();
/**
- * Attempts to return a reference to a concrete IMP_Contents instance.
- * If an IMP_Contents object is currently stored in the local cache,
- * recreate that object. Else, create a new instance.
- * Ensures that only one IMP_Contents instance for any given message is
- * available at any one time.
- *
- * @param mixed $in Either a UID string (UID . IMP::IDX_SEP . Mailbox) or
- * a Horde_Mime_Part object.
- *
- * @return IMP_Contents The IMP_Contents object.
- * @throws Horde_Exception
- */
- static public function singleton($in)
- {
- $sig = ($in instanceof Horde_Mime_Part)
- ? 'horde_mime_part_' . self::$_mimepartid++
- : $in;
-
- if (empty(self::$_instances[$sig])) {
- self::$_instances[$sig] = new self($in);
- }
-
- return self::$_instances[$sig];
- }
-
- /**
* Constructor.
*
* @param mixed $in Either a UID string (UID . IMP::IDX_SEP . Mailbox) or
* a Horde_Mime_Part object.
- * @throws Horde_Exception
+ * @throws IMP_Exception
*/
- protected function __construct($in)
+ public function __construct($in)
{
if ($in instanceof Horde_Mime_Part) {
$this->_message = $in;
Horde_Imap_Client::FETCH_STRUCTURE => array('parse' => true)
), array('ids' => array($this->_uid)));
} catch (Horde_Imap_Client_Exception $e) {
- throw new Horde_Exception('Error displaying message.');
+ throw new IMP_Exception('Error displaying message.');
}
if (!isset($ret[$this->_uid]['structure'])) {
- throw new Horde_Exception('Error displaying message.');
+ throw new IMP_Exception('Error displaying message.');
}
$this->_message = $ret[$this->_uid]['structure'];
if (($mask && self::SUMMARY_IMAGE_SAVE) &&
$GLOBALS['registry']->hasMethod('images/selectGalleries') &&
($mime_part->getPrimaryType() == 'image')) {
- $part['img_save'] = Horde::link('#', _("Save Image in Gallery"), 'saveImgAtc', null, Horde::popupJs(Horde::applicationUrl('saveimage.php'), array('params' => array('uid' => ($this->_uid . IMP::IDX_SEP . $this->_mailbox), 'id' => $id), 'height' => 200, 'width' => 450)) . 'return false;') . '</a>';
+ $part['img_save'] = Horde::link('#', _("Save Image in Gallery"), 'saveImgAtc', null, Horde::popupJs(Horde::applicationUrl('saveimage.php'), array('params' => array('mbox' => $this->_mailbox, 'uid' => $this->_uid, 'id' => $id), 'height' => 200, 'width' => 450)) . 'return false;') . '</a>';
}
/* Add print link? */
$GLOBALS['imp_imap']->checkUidvalidity($mbox);
foreach ($msgIndices as $idx) {
- $contents = IMP_Contents::singleton($idx . IMP::IDX_SEP . $mbox);
+ $contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($mbox, $idx);
$hdr = $contents->getHeaderOb();
$addr[] = Horde_Mime_Address::bareAddress($hdr->getValue('from'));
}
--- /dev/null
+<?php
+/**
+ * Binder for IMP_Contents::.
+ *
+ * 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_Contents implements Horde_Injector_Binder
+{
+ /**
+ */
+ public function create(Horde_Injector $injector)
+ {
+ return new IMP_Injector_Factory_Contents($injector);
+ }
+
+ /**
+ */
+ public function equals(Horde_Injector_Binder $binder)
+ {
+ return false;
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * A Horde_Injector:: based IMP_Contents:: factory.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package IMP
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/gpl.html GPL
+ * @link http://pear.horde.org/index.php?package=IMP
+ */
+
+/**
+ * A Horde_Injector:: based IMP_Contents:: factory.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @category Horde
+ * @package IMP
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/gpl.html GPL
+ * @link http://pear.horde.org/index.php?package=IMP
+ */
+class IMP_Injector_Factory_Contents
+{
+ /**
+ * Instances.
+ *
+ * @var array
+ */
+ private $_instances = array();
+
+ /**
+ * The injector.
+ *
+ * @var Horde_Injector
+ */
+ private $_injector;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Injector $injector The injector to use.
+ */
+ public function __construct(Horde_Injector $injector)
+ {
+ $this->_injector = $injector;
+ }
+
+ /**
+ * Return the Horde_Editor:: instance.
+ *
+ * @param string $mailbox The mailbox name.
+ * @param integer $uid The message UID.
+ *
+ * @return IMP_Contents The singleton contents instance.
+ * @throws IMP_Exception
+ */
+ public function getOb($mailbox, $uid)
+ {
+ $uid = $uid . IMP::IDX_SEP . $mailbox;
+ if (!isset($this->_instances[$uid])) {
+ $this->_instances[$uid] = new IMP_Contents($uid);
+ }
+ return $this->_instances[$uid];
+ }
+
+}
!in_array('\\seen', $v['flags'])))) {
if (empty($preview_info[$k])) {
try {
- $imp_contents = IMP_Contents::singleton($k . IMP::IDX_SEP . $mbox);
+ $imp_contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($mbox, $k);
$prev = $imp_contents->generatePreview();
$preview_info[$k] = array('IMPpreview' => $prev['text'], 'IMPpreviewc' => $prev['cut']);
if (!is_null($cache)) {
$tostore[$k] = $preview_info[$k];
}
- } catch (Horde_Exception $e) {
+ } catch (Exception $e) {
$preview_info[$k] = array('IMPpreview' => '', 'IMPpreviewc' => false);
}
}
foreach ($msgList as $folder => $msgIndices) {
foreach ($msgIndices as $index) {
/* Fetch the message contents. */
- $imp_contents = IMP_Contents::singleton($index . IMP::IDX_SEP . $folder);
+ $imp_contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($folder, $index);
/* Fetch the message headers. */
$imp_headers = $imp_contents->getHeaderOb();
$GLOBALS['imp_imap']->checkUidvalidity($mbox);
/* Get a local copy of the message. */
- $contents = IMP_Contents::singleton($index . IMP::IDX_SEP . $mbox);
+ $contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($mbox, $index);
/* Loop through all to-be-stripped mime parts. */
if (is_null($partid)) {
if ($val == $number) {
$parts[$number] = $this->_mimepart->getContents();
} else {
- $ic = IMP_Contents::singleton($val . IMP::IDX_SEP . $mbox);
+ $ic = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($mbox, $val);
$parts[$ic->getMIMEMessage()->getContentTypeParameter('number')] = $ic->getBody();
}
}
foreach ($msgList as $mbox => $msgIndices) {
try {
$GLOBALS['imp_imap']->checkUidvalidity($mbox);
- } catch (Horde_Exception $e) {
+ } catch (IMP_Exception $e) {
continue;
}
/* Fetch the raw message contents (headers and complete
* body). */
try {
- $imp_contents = IMP_Contents::singleton($idx . IMP::IDX_SEP . $mbox);
- } catch (Horde_Exception $e) {
+ $imp_contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($mbox, $idx);
+ } catch (IMP_Exception $e) {
continue;
}
{
if (!empty($uid)) {
try {
- return IMP_Contents::singleton($uid . IMP::IDX_SEP . $mailbox);
- } catch (Horde_Exception $e) {
+ return $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($mailbox, $uid);
+ } catch (IMP_Exception $e) {
$GLOBALS['notification']->push(_("Could not retrieve the message from the mail server."), 'horde.error');
}
}
/* Parse MIME info and create the body of the message. */
try {
- $imp_contents = IMP_Contents::singleton($uid . IMP::IDX_SEP . $mailbox);
- } catch (Horde_Exception $e) {
+ $imp_contents = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($mailbox, $uid);
+ } catch (IMP_Exception $e) {
$result['error'] = $error_msg;
$result['errortype'] = 'horde.error';
return $result;
/* Parse the message. */
try {
- $imp_contents = IMP_Contents::singleton($uid . IMP::IDX_SEP . $mailbox_name);
-} catch (Horde_Exception $e) {
+ $imp_contents = $injector->getInstance('IMP_Contents')->getOb($mailbox_name, $uid);
+} catch (IMP_Exception $e) {
header('Location: ' . IMP::generateIMPUrl('mailbox-mimp.php', $mailbox_name)->setRaw(true)->add('a', 'm'));
exit;
}
/* Parse the message. */
try {
- $imp_contents = IMP_Contents::singleton($uid . IMP::IDX_SEP . $mailbox_name);
-} catch (Horde_Exception $e) {
+ $imp_contents = $injector->getInstance('IMP_Contents')->getOb($mailbox_name, $uid);
+} catch (IMP_Exception $e) {
$imp_mailbox->removeMsgs(true);
_returnToMailbox(null, 'message_missing');
require IMP_BASE . '/mailbox.php';
case 'save_attachment_public_key':
/* Retrieve the key from the message. */
- $contents = IMP_Contents::singleton($vars->uid . IMP::IDX_SEP . $vars->mailbox);
+ $contents = $injector->getInstance('IMP_Contents')->getOb($vars->mailbox, $vars->uid);
$mime_part = $contents->getMIMEPart($vars->mime_id);
if (empty($mime_part)) {
throw new IMP_Exception('Cannot retrieve public key from message.');
require_once dirname(__FILE__) . '/lib/Application.php';
Horde_Registry::appInit('imp');
-$id = Horde_Util::getFormData('id');
-$uid = Horde_Util::getFormData('uid');
+$vars = Horde_Variables::getDefaultVariables();
/* Run through the action handlers. */
-switch (Horde_Util::getFormData('actionID')) {
+switch ($vars->actionID) {
case 'save_image':
- $contents = IMP_Contents::singleton($uid);
- $mime_part = $contents->getMIMEPart($id);
+ $contents = $injector->getInstance('IMP_Contents')->getOb($vars->mbox, $vars->uid);
+ $mime_part = $contents->getMIMEPart($vars->id);
$image_data = array(
'data' => $mime_part->getContents(),
'description' => $mime_part->getDescription(true),
'type' => $mime_part->getType()
);
try {
- $registry->call('images/saveImage', array(null, Horde_Util::getFormData('gallery'), $image_data));
+ $registry->call('images/saveImage', array(null, $vars->gallery, $image_data));
} catch (Horde_Exception $e) {
$notification->push($e);
break;
$t = $injector->createInstance('Horde_Template');
$t->setOption('gettext', true);
$t->set('action', Horde::applicationUrl('saveimage.php'));
-$t->set('id', htmlspecialchars($id));
-$t->set('uid', htmlspecialchars($uid));
+$t->set('id', htmlspecialchars($vars->id));
+$t->set('uid', htmlspecialchars($vars->uid));
$t->set('image_img', Horde::img('mime/image.png', _("Image")));
/* Build the list of galleries. */
case 'save_attachment_public_key':
/* Retrieve the key from the message. */
- $contents = IMP_Contents::singleton($vars->uid . IMP::IDX_SEP . $vars->mailbox);
+ $contents = $injector->getInstance('IMP_Contents')->getOb($vars->mailbox, $vars->uid);
$mime_part = $contents->getMIMEPart($vars->mime_id);
if (empty($mime_part)) {
throw new IMP_Exception('Cannot retrieve public key from message.');
/* Get the body of the message. */
$curr_msg = $curr_tree = array();
- $contents = IMP_Contents::singleton($idx . IMP::IDX_SEP . $mbox);
+ $contents = $injector->getInstance('IMP_Contents')->getOb($mbox, $idx);
$mime_id = $contents->findBody();
if ($contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE)) {
$ret = $contents->renderMIMEPart($mime_id, IMP_Contents::RENDER_INLINE);
/* Create a dummy IMP_Contents() object so we can use the view code below.
* Then use the 'view_attach' handler to output. */
- $contents = IMP_Contents::singleton($mime);
+ $contents = new IMP_Contents($mime);
} else {
if (!$vars->uid || !$vars->mailbox) {
exit;
}
- $contents = IMP_Contents::singleton($vars->uid . IMP::IDX_SEP . $vars->mailbox);
+ $contents = $injector->getInstance('IMP_Contents')->getOb($vars->mailbox, $vars->uid);
}
/* Run through action handlers */