<?php
/**
- * The IMP_Horde_Mime_Viewer_partial class allows multipart/partial messages
+ * The IMP_Horde_Mime_Viewer_partial class allows message/partial messages
* to be displayed (RFC 2046 [5.2.2]).
*
* Copyright 2003-2008 The Horde Project (http://www.horde.org/)
class IMP_Horde_Mime_Viewer_partial extends Horde_Mime_Viewer_Driver
{
/**
- * Render out the currently set contents.
+ * Can this driver render various views?
*
- * @param array $params An array with a reference to a MIME_Contents
- * object.
+ * @var boolean
+ */
+ protected $_capability = array(
+ 'embedded' => true,
+ 'full' => false,
+ 'info' => false,
+ 'inline' => false,
+ );
+
+ /**
+ * If this MIME part can contain embedded MIME parts, and those embedded
+ * MIME parts exist, return an altered version of the Horde_Mime_Part that
+ * contains the embedded MIME part information.
*
- * @return string The rendered text in HTML.
+ * @return mixed A Horde_Mime_Part with the embedded MIME part information
+ * or null if no embedded MIME parts exist.
*/
- public function render($params)
+ protected function _getEmbeddedMimeParts()
{
- $contents = &$params[0];
+ $id = $this->_mimepart->getContentTypeParameter('id');
+ $number = $this->_mimepart->getContentTypeParameter('number');
+ $total = $this->_mimepart->getContentTypeParameter('total');
- $base_ob = &$contents->getBaseObjectPtr();
- $curr_index = $base_ob->getMessageIndex();
- $id = $this->mime_part->getContentTypeParameter('id');
- $parts = array();
+ if (is_null($id) || is_null($number) || is_null($total)) {
+ return null;
+ }
+
+ $mbox = $this->_params['contents']->getMailbox();
/* Perform the search to find the other parts of the message. */
$query = new Horde_Imap_Client_Search_Query();
- $query->header('Content-Type', $id);
-
- $indices = $GLOBALS['imp_search']->runSearchQuery($query, $GLOBALS['imp_mbox']['thismailbox']);
+ $query->headerText('Content-Type', $id);
+ $indices = $GLOBALS['imp_search']->runSearchQuery($query, $mbox);
/* If not able to find the other parts of the message, print error. */
- if (count($indices) != $this->mime_part->getContentTypeParameter('total')) {
- return $this->formatStatusMsg(sprintf(_("Cannot display - found only %s of %s parts of this message in the current mailbox."), count($indices), $this->mime_part->getContentTypeParameter('total')));
+ if (count($indices) != $total) {
+ $mime_part = new Horde_Mime_Part();
+ $mime_part->setType('text/plain');
+ $mime_part->setCharset(NLS::getCharset());
+ $mime_part->setContents(sprintf(_("[Cannot display message - found only %s of %s parts of this message in the current mailbox.]"), count($indices), $total));
+ return $mime_part;
}
/* Get the contents of each of the parts. */
+ $parts = array();
foreach ($indices as $val) {
/* No need to fetch the current part again. */
- if ($val == $curr_index) {
- $parts[$this->mime_part->getContentTypeParameter('number')] = $this->mime_part->getContents();
+ if ($val == $number) {
+ $parts[$number] = $this->_mimepart->getContents();
} else {
- $imp_contents = &IMP_Contents::singleton($val . IMP::IDX_SEP . $GLOBALS['imp_mbox']['thismailbox']);
- $part = &$imp_contents->getMIMEPart(0);
- $parts[$part->getContentTypeParameter('number')] = $imp_contents->getBody();
+ $ic = &IMP_Contents::singleton($val . IMP::IDX_SEP . $mbox);
+ $parts[$ic->getMIMEMessage()->getContentTypeParameter('number')] = $ic->getBody();
}
}
/* Sort the parts in numerical order. */
ksort($parts, SORT_NUMERIC);
- /* Combine the parts and render the underlying data. */
- $mime_message = &MIME_Message::parseMessage(implode('', $parts));
- $mc = new MIME_Contents($mime_message, array('download' => 'download_attach', 'view' => 'view_attach'), array(&$contents));
- $mc->buildMessage();
-
- return '<table>' . $mc->getMessage(true) . '</table>';
- }
-
- /**
- * Return the content-type of the rendered output.
- *
- * @return string The content-type of the output.
- */
- public function getType()
- {
- return 'text/html; charset=' . NLS::getCharset();
+ /* Combine the parts. */
+ $mime_message = Horde_Mime_Message::parseMessage(implode('', $parts));
+ return ($mime_message === false) ? null : $mime_message;
}
}