From cbd63bd1d69b52fe457dd69d67d826075fb5d471 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 11 Nov 2008 02:01:13 -0700 Subject: [PATCH] multipart/related now working (with HTML msgs) --- imp/lib/Mime/Viewer/html.php | 25 ++++--- imp/lib/Mime/Viewer/related.php | 140 +++++++++++++++++++++------------------- 2 files changed, 90 insertions(+), 75 deletions(-) diff --git a/imp/lib/Mime/Viewer/html.php b/imp/lib/Mime/Viewer/html.php index 831b48c53..0d665f146 100644 --- a/imp/lib/Mime/Viewer/html.php +++ b/imp/lib/Mime/Viewer/html.php @@ -134,14 +134,21 @@ class IMP_Horde_Mime_Viewer_html extends Horde_Mime_Viewer_html $data = preg_replace('/(style\s*=\s*)(["\'])?([^>"\']*)position\s*:\s*absolute([^>"\']*)\2/i', '$1"$3$4"', $data); } - /* Search for inlined images that we can display. */ - // TODO - if (false) { - $relatedPart = $this->_params['contents']->getMIMEPart($related); - foreach ($relatedPart->getCIDList() as $ref => $id) { - $id = trim($id, '<>'); - $cid_part = $this->_params['contents']->getDecodedMIMEPart($ref); - $data = str_replace("cid:$id", $this->_params['contents']->urlView($cid_part, 'view_attach'), $data); + /* Search for inlined links that we can display (multipart/related + * parts). */ + if (!empty($this->_params['related_id'])) { + $cid_replace = array(); + + foreach ($this->_params['related_cids'] as $mime_id => $cid) { + $cid = trim($cid, '<>'); + if ($cid) { + $cid_part = $this->_params['contents']->getMIMEPart($mime_id); + $cid_replace['cid:' . $cid] = $this->_params['contents']->urlView($cid_part, 'view_attach', array('params' => array('img_data' => 1))); + } + } + + if (!empty($cid_replace)) { + $data = str_replace(array_keys($cid_replace), array_values($cid_replace), $data); } } @@ -214,7 +221,7 @@ class IMP_Horde_Mime_Viewer_html extends Horde_Mime_Viewer_html /* If we are viewing inline, give option to view in separate window. */ if ($inline && $this->getConfigParam('external')) { $cleanhtml['status'][] = array( - 'data' => $this->_params['contents']->linkViewJS($this->mime_part, 'view_attach', _("Show this HTML in a new window?")), + 'data' => $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("Show this HTML in a new window?")), 'type' => 'info' ); } diff --git a/imp/lib/Mime/Viewer/related.php b/imp/lib/Mime/Viewer/related.php index 2879b6d13..c874e62f8 100644 --- a/imp/lib/Mime/Viewer/related.php +++ b/imp/lib/Mime/Viewer/related.php @@ -1,7 +1,7 @@ false, + 'full' => true, + 'info' => true, + 'inline' => true, + ); /** - * The mime type of the message part that has been chosen to be displayed. + * Return the full rendered version of the Horde_Mime_Part object. * - * @var string + * @return array See Horde_Mime_Viewer_Driver::render(). */ - protected $_viewerType = 'text/html'; - - /** - * Render out the currently set contents. - * - * @param array $params An array with a reference to a MIME_Contents - * object. - * - * @return string The rendered text in HTML. - */ - public function render($params) + protected function _render() { - $contents = &$params[0]; - - /* Look at the 'start' parameter to determine which part to start - with. If no 'start' parameter, use the first part. - RFC 2387 [3.1] */ - if ($this->mime_part->getContentTypeParameter('start') && - ($key = array_search($this->mime_part->getContentTypeParameter('start'), $this->mime_part->getCIDList()))) { - if (($pos = strrpos($key, '.'))) { - $id = substr($key, $pos + 1); - } else { - $id = $key; - } - } else { - $id = 1; - } - $start = $this->mime_part->getPart($this->mime_part->getRelativeMimeID($id)); - - /* Only display if the start part (normally text/html) can be displayed - inline -OR- we are viewing this part as an attachment. */ - if ($contents->canDisplayInline($start) || - $this->viewAsAttachment()) { - $text = $contents->renderMIMEPart($start); - $this->_viewerType = $contents->getMIMEViewerType($start); - $this->_charset = $start->getCharset(); - } else { - $text = ''; - } - - return $text; - } + return $this->_IMPrender(false); + } /** - * Render out attachment information. - * - * @param array $params An array with a reference to a MIME_Contents - * object. + * Return the rendered inline version of the Horde_Mime_Part object. * - * @return string The rendered text in HTML. + * @return array See Horde_Mime_Viewer_Driver::render(). */ - public function renderAttachmentInfo($params) + protected function _renderInline() { - $contents = &$params[0]; - - $msg = sprintf(_("Click %s to view this multipart/related part in a separate window."), $contents->linkViewJS($this->mime_part, 'view_attach', _("HERE"), _("View content in a separate window"))); - return $this->formatStatusMsg($msg, Horde::img('mime/html.png', _("HTML")), false); + $ret = $this->_IMPrender(true); + return empty($ret['ids']) ? $this->_renderInfo() : $ret; } /** - * Return the content-type. + * Return the rendered information about the Horde_Mime_Part object. * - * @return string The content-type of the message. + * @return array See Horde_Mime_Viewer_Driver::render(). */ - public function getType() + protected function _renderInfo() { - return $this->_viewerType . '; charset=' . $this->getCharset(); + return array( + 'status' => array( + 'text' => sprintf(_("Click %s to view this multipart/related part in a separate window."), $contents->linkViewJS($this->mime_part, 'view_attach', _("HERE"), _("View content in a separate window"))), + 'icon' => Horde::img('mime/html.png', _("HTML")) + ) + ); } /** - * Returns the character set used for the Viewer. + * Render out the currently set contents. * - * @return string The character set used by this Viewer. + * @param boolean $inline Are we viewing inline? + * + * @return array Two elements: html and status. */ - public function getCharset() + protected function _IMPrender($inline) { - return ($this->_charset === null) ? NLS::getCharset() : $this->_charset; + $can_display = !$inline; + $text = ''; + + $subparts = $this->_mimepart->contentTypeMap(); + unset($subparts[key($subparts)]); + + /* Look at the 'start' parameter to determine which part to start + * with. If no 'start' parameter, use the first part. RFC 2387 + * [3.1] */ + $id = $this->_mimepart->getContentTypeParameter('start'); + if (is_null($id)) { + reset($subparts); + $id = key($subparts); + } + + /* Only display if the start part (normally text/html) can be + * displayed inline -OR- we are viewing this part as an attachment. */ + if (!$can_display) { + $viewer = Horde_Mime_Viewer::factory($subparts[$id]); + if ($viewer->canRender('inline')) { + $mime_part = $this->_mimepart->getPart($id); + $can_display = ($mime_part->getDisposition() == 'inline'); + } + } + + if ($can_display) { + /* Build a list of parts -> CIDs. */ + $cids = array(); + foreach (array_keys($subparts) as $val) { + $part = $this->_mimepart->getPart($val); + $cids[$val] = $part->getContentId(); + } + + $ret = $this->_params['contents']->renderMIMEPart($id, $inline ? 'inline' : 'full', array('params' => array('related_id' => $id, 'related_cids' => $cids))); + $ret['ids'] = array_merge($ret['ids'], array_keys($subparts)); + unset($ret['summary_id']); + return $ret; + } + + return array(); } } -- 2.11.0