From 470aa2b470d6ab16f3a1801466c474b56a3e038d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 2 Aug 2010 11:28:51 -0600 Subject: [PATCH] Fix display of multipart/related images. Also optimize the code - no need to create MIME Part objects for each link, only do replacement in IMG tags. --- imp/lib/Contents.php | 3 ++- imp/lib/Mime/Viewer/Html.php | 63 ++++++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/imp/lib/Contents.php b/imp/lib/Contents.php index 52972f50a..bc9f016f7 100644 --- a/imp/lib/Contents.php +++ b/imp/lib/Contents.php @@ -713,7 +713,8 @@ class IMP_Contents * * @return string The URL to view.php. */ - public function urlView($mime_part, $actionID, $options = array()) + public function urlView($mime_part = null, $actionID = 'view_attach', + $options = array()) { $params = $this->_urlViewParams($mime_part, $actionID, isset($options['params']) ? $options['params'] : array()); diff --git a/imp/lib/Mime/Viewer/Html.php b/imp/lib/Mime/Viewer/Html.php index 484cb8a9a..dfe2a0d7c 100644 --- a/imp/lib/Mime/Viewer/Html.php +++ b/imp/lib/Mime/Viewer/Html.php @@ -142,6 +142,7 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html } else { $this->_imptmp = array( 'blockimg' => null, + 'cid' => null, 'img' => ($inline && $GLOBALS['prefs']->getValue('html_image_replacement') && !$this->_inAddressBook()), 'imgblock' => false, 'inline' => $inline, @@ -152,6 +153,22 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html if ($this->_imptmp['img']) { $this->_imptmp['blockimg'] = Horde::url(Horde_Themes::img('spacer_red.png'), true, -1); } + + /* Search for inlined images that we can display + * (multipart/related parts). */ + if (isset($this->_params['related_id'])) { + $cid_replace = array(); + + foreach ($this->_params['related_cids'] as $mime_id => $cid) { + if ($cid = trim($cid, '<>')) { + $cid_replace['cid:' . $cid] = $mime_id; + } + } + + if (!empty($cid_replace)) { + $this->_imptmp['cid'] = $cid_replace; + } + } } /* Sanitize the HTML. */ @@ -194,24 +211,6 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html ); } - /* Search for inlined links that we can display (multipart/related - * parts). */ - if (isset($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('related_data' => 1))); - } - } - - if (!empty($cid_replace)) { - $data = str_replace(array_keys($cid_replace), array_values($cid_replace), $data); - } - } - $filters = array(); if ($GLOBALS['prefs']->getValue('emoticons')) { $filters['emoticons'] = array( @@ -278,7 +277,9 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html } if ($node instanceof DOMElement) { - switch (strtolower($node->tagName)) { + $tag = strtolower($node->tagName); + + switch ($tag) { case 'a': case 'area': /* Convert links to open in new windows. Ignore @@ -297,10 +298,26 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html case 'img': case 'input': - if ($this->_imptmp['img'] && $node->hasAttribute('src')) { - $node->setAttribute('htmlimgblocked', $node->getAttribute('src')); - $node->setAttribute('src', $this->_imptmp['blockimg']); - $this->_imptmp['imgblock'] = true; + if ($this->_imptmp && $node->hasAttribute('src')) { + $val = $node->getAttribute('src'); + + /* Multipart/related. */ + if (($tag == 'img') && + $this->_imptmp['cid'] && + isset($this->_imptmp['cid'][$val])) { + $val = $this->_params['contents']->urlView(null, 'view_attach', array('params' => array( + 'id' => $this->_imptmp['cid'][$val], + 'related_data' => 1 + ))); + $node->setAttribute('src', $val); + } + + /* Block images.*/ + if ($this->_imptmp['img']) { + $node->setAttribute('htmlimgblocked', $val); + $node->setAttribute('src', $this->_imptmp['blockimg']); + $this->_imptmp['imgblock'] = true; + } } break; -- 2.11.0