Skip to content

Commit

Permalink
[mms] Potentially save a call to the contacts backend when viewing HT…
Browse files Browse the repository at this point in the history
…ML messages if no image data is present in the message.
  • Loading branch information
slusarz committed Mar 31, 2014
1 parent 3745b59 commit 2cd7377
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
2 changes: 2 additions & 0 deletions imp/docs/CHANGES
Expand Up @@ -2,6 +2,8 @@
v6.2.0-git
----------

[mms] Potentially save a call to the contacts backend when viewing HTML
messages if no image data is present in the message.
[mms] Improved styling of dynamic mailbox page, to fix issues when resizing the
browser font size (Bug #13071).
[mms] Don't send as multipart/alternative if plaintext part is empty.
Expand Down
59 changes: 41 additions & 18 deletions imp/lib/Mime/Viewer/Html.php
Expand Up @@ -151,24 +151,14 @@ protected function _IMPrender($inline)
$this->_imptmp = array();
if ($inline && !$convert_text) {
$this->_imptmp += array(
'blockimg' => null,
'cid' => null,
'cid_used' => array(),
'cssblock' => false,
'cssbroken' => false,
'img' => false,
'imgblock' => false,
'inline' => $inline,
'style' => array()
);

if ($inline) {
/* Image filtering. */
if (!$injector->getInstance('IMP_Images')->showInlineImage($contents)) {
$this->_imptmp['blockimg'] = strval(Horde_Themes::img('spacer_red.png'));
$this->_imptmp['img'] = true;
}
}
}

/* Search for inlined data that we can display (multipart/related
Expand Down Expand Up @@ -353,15 +343,15 @@ protected function _node($doc, $node)
}

/* Block images.*/
if (!empty($this->_imptmp['img'])) {
if ($this->_imgBlock()) {
if (Horde_Url_Data::isData($val)) {
$url = new Horde_Url_Data($val);
} else {
$url = new Horde_Url($val);
$url->setScheme();
}
$node->setAttribute('htmlimgblocked', $url);
$node->setAttribute('src', $this->_imptmp['blockimg']);
$node->setAttribute('src', $this->_imgBlockImg());
$this->_imptmp['imgblock'] = true;
}
}
Expand All @@ -381,7 +371,7 @@ protected function _node($doc, $node)

if ($id = $this->_cidSearch($tmp, false)) {
$this->_imptmp['style'][] = $this->getConfigParam('imp_contents')->getMIMEPart($id)->getContents();
} elseif (!empty($this->_imptmp['img'])) {
} elseif ($this->_imgBlock()) {
$node->setAttribute('htmlcssblocked', $node->getAttribute('href'));
$node->removeAttribute('href');
$this->_imptmp['cssblock'] = true;
Expand Down Expand Up @@ -437,9 +427,9 @@ protected function _node($doc, $node)
}

/* Block images.*/
if (!empty($this->_imptmp['img'])) {
if ($this->_imgBlock()) {
$node->setAttribute('htmlimgblocked', $val);
$node->setAttribute('background', $this->_imptmp['blockimg']);
$node->setAttribute('background', $this->_imgBlockImg());
$this->_imptmp['imgblock'] = true;
}
}
Expand All @@ -463,8 +453,7 @@ protected function _node($doc, $node)
if (strpos($node->getAttribute('style'), 'content:') !== false) {
// TODO: Figure out way to unblock?
$node->removeAttribute('style');
} elseif (!empty($this->_imptmp['img']) ||
!empty($this->_imptmp['cid'])) {
} elseif (!empty($this->_imptmp['cid']) || $this->_imgBlock()) {
$this->_imptmp['node'] = $node;
$style = preg_replace_callback(self::CSS_BG_PREG, array($this, '_styleCallback'), $node->getAttribute('style'), -1, $matches);
if ($matches) {
Expand Down Expand Up @@ -584,7 +573,7 @@ protected function _styleCallback($matches)
} else {
$this->_imptmp['node']->setAttribute('htmlimgblocked', $matches[2]);
$this->_imptmp['imgblock'] = true;
$replace = $this->_imptmp['blockimg'];
$replace = $this->_imgBlockImg();
}
return $matches[1] . $replace . $matches[3];
}
Expand Down Expand Up @@ -612,4 +601,38 @@ protected function _cidSearch($cid, $save = true)
return $id;
}

/**
* Are we blocking images?
*
* @return boolean True if blocking images.
*/
protected function _imgBlock()
{
global $injector;

/* Done on demand, since we potentially save a contacts API call if
* not needed/used in a message. */
if (!isset($this->_imptmp['img'])) {
$this->_imptmp['img'] =
($this->_imptmp['inline'] &&
!$injector->getInstance('IMP_Images')->showInlineImage($this->getConfigParam('imp_contents')));
}

return $this->_imptmp['img'];
}

/**
* The HTML image source to use for blocked images.
*
* @return string The HTML image source.
*/
protected function _imgBlockImg()
{
if (!isset($this->_imptmp['blockimg'])) {
$this->_imptmp['blockimg'] = strval(Horde_Themes::img('spacer_red.png'));
}

return $this->_imptmp['blockimg'];
}

}
1 change: 1 addition & 0 deletions imp/package.xml
Expand Up @@ -33,6 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [mms] Potentially save a call to the contacts backend when viewing HTML messages if no image data is present in the message.
* [mms] Improved styling of dynamic mailbox page, to fix issues when resizing the browser font size (Bug #13071).
* [mms] Don&apos;t send as multipart/alternative if plaintext part is empty.
* [mms] Add smiley data to message when added via the HTML editor (Request #13051).
Expand Down

0 comments on commit 2cd7377

Please sign in to comment.