*/
IMP.unblockImages = function(e)
{
- var elt = e.element().up('TABLE.mimeStatusMessage');
+ var elt = e.element().up('TABLE.mimeStatusMessage'),
+ iframe = elt.up().next('.htmlMsgData'),
+ s = new Selector('[htmlimgblocked]');
- elt.up().next('.htmlMessage').writeAttribute('src', e.element().readAttribute('href'));
+ // Need to use non-prototypejs methods to work with data inside of
+ // the IFRAME. Prototypejs's Selector works, but only if we use
+ // the pure javascript method.
+ if (s.mode != 'normal') {
+ delete Selector._cache['[htmlimgblocked]'];
+ s.mode = 'normal';
+ s.compileMatcher();
+ }
+
+ s.findElements(iframe.contentWindow.document).each(function(b) {
+ var src = decodeURIComponent(b.getAttribute('htmlimgblocked'));
+ if (b.getAttribute('src')) {
+ b.setAttribute('src', src);
+ } else if (b.getAttribute('background')) {
+ b.setAttribute('background', src);
+ } else if (b.style.backgroundImage) {
+ b.style.setProperty('background-image', 'url(' + src + ')', '');
+ }
+ });
+
+ // Delete this entry, because in the rare case that another selector
+ // on the page uses the same expression, it will break the next time
+ // it is used.
+ delete Selector._cache['[htmlimgblocked]'];
Effect.Fade(elt, {
afterFinish: function() { elt.remove(); },
e.stop();
};
+ IMP.iframeInject = function(id, data)
+ {
+ id = $(id);
+ var d = id.contentWindow.document;
+
+ d.open();
+ d.write(data);
+ d.close();
+
+ this.iframeResize(id);
+ };
+
+ IMP.iframeResize = function(id)
+ {
+ id = $(id);
+ id.setStyle({ height: id.contentWindow.document.height + 'px' });
+ };
+
// If menu is present, attach event handlers to folder switcher.
var tmp = $('openfoldericon');
if (tmp) {
\s*
# opening quotes, parenthesis; match 4
("|\')?
- # the image url
- (?(2)
+ # the image url; match 5
+ ((?(2)
# matched a "style" attribute
(?(4)[^"\')>]*|[^\s)>]*)
# did not match a "style" attribute
|(?(4)[^"\'>]*|[^\s>]*)
- )
+ ))
# closing quotes
(?(4)\\4)
# matched a "style" attribute?
(?(2)
# closing parenthesis
\s*\)
- # remainder of the "style" attribute; match 5
+ # remainder of the "style" attribute; match 6
((?(3)[^"\'>]*|[^\s>]*))
)
/isx';
/**
* Return the rendered inline version of the Horde_Mime_Part object.
*
- * URL parameters used by this function:
- * <pre>
- * 'html_iframe_data' - (boolean) If true, output the iframe content only.
- * 'html_view_images' - (boolean) If true, force display of images.
- * </pre>
- *
* @return array See Horde_Mime_Viewer_Driver::render().
*/
protected function _renderInline()
{
- if (Horde_Util::getFormData('html_iframe_data')) {
- $html = $this->_IMPrender(true);
- } else {
- $data = '';
- $view_part = isset($this->_params['related_id'])
- ? $this->_params['contents']->getMIMEPart($this->_params['related_id'])
- : $this->_mimepart;
-
- $src = $this->_params['contents']->urlView($view_part, 'view_attach', array('params' => array('html_iframe_data' => 1, 'mode' => IMP_Contents::RENDER_INLINE)));
-
- /* Check for phishing exploits. */
- $contents = $this->_mimepart->getContents();
- $this->_phishingCheck($contents, true);
- $status = array($this->_phishingStatus());
-
- /* Only display images if specifically allowed by user. */
- if ($GLOBALS['prefs']->getValue('html_image_replacement') &&
- preg_match($this->_img_regex, $contents)) {
- // Unblock javascript code in js/imp.js
- $data = Horde_Util::bufferOutput(array('Horde', 'addScriptFile'), 'imp.js', 'imp', true);
-
- $status[] = array(
- 'icon' => Horde::img('mime/image.png'),
- 'text' => array(
- _("Images have been blocked to protect your privacy."),
- Horde::link(Horde_Util::addParameter($src, 'html_view_images', 1), '', 'unblockImageLink') . _("Show Images?") . '</a>'
- )
- );
- }
-
- $html = array(
- // TODO: Why do we need extra 10 pixels, at least on FF 3.1?
- 'data' => '<IFRAME class="htmlMessage" src="' . $src . '" onload="this.setStyle({ height: this.contentWindow.document.height + 10 + \'px\' })" frameborder="0"></iframe>' . $data,
- 'status' => $status,
- 'type' => 'text/html; charset=' . Horde_Nls::getCharset()
+ /* Non-javascript browsers can't handle IFRAME resizing, so it isn't
+ * possible to view inline. */
+ if (!$GLOBALS['browser']->hasFeature('javascript')) {
+ return array(
+ $this->_mimepart->getMimeId() => array(
+ 'data' => '',
+ 'status' => array(
+ array(
+ 'icon' => Horde::img('mime/html.png'),
+ 'text' => array(
+ _("This message part contains HTML data, but this data can not be displayed inline."),
+ $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("View HTML data in new window.")),
+ )
+ )
+ ),
+ 'type' => 'text/html; charset=' . Horde_Nls::getCharset()
+ )
);
}
+ $data = $this->_IMPrender(true);
+ $uid = 'htmldata_' . uniqid(mt_rand());
+
+ $data['js'] = array('IMP.iframeInject("' . $uid . '", ' . Horde_Serialize::serialize($data['data'], Horde_Serialize::JSON, $this->_mimepart->getCharset()) . ')');
+ $data['data'] = '<IFRAME class="htmlMsgData" id="' . $uid . '" src="javascript:false" frameborder="0"></IFRAME>' .
+ Horde_Util::bufferOutput(array('Horde', 'addScriptFile'), 'imp.js', 'imp', true);
+ $data['type'] = 'text/html; charset=' . Horde_Nls::getCharset();
+
return array(
- $this->_mimepart->getMimeId() => $html
+ $this->_mimepart->getMimeId() => $data
);
}
return array();
}
- $status = array(
- _("This message part contains HTML data, but inline HTML display is disabled."),
- $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("View HTML data in new window.")),
- $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("Convert HTML data to plain text and view in new window."), array('params' => array('convert_text' => 1)))
- );
-
return array(
$this->_mimepart->getMimeId() => array(
'data' => '',
'status' => array(
array(
'icon' => Horde::img('mime/html.png', _("HTML data")),
- 'text' => $status
+ 'text' => array(
+ _("This message part contains HTML data, but inline HTML display is disabled."),
+ $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("View HTML data in new window.")),
+ $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', _("Convert HTML data to plain text and view in new window."), array('params' => array('convert_text' => 1)))
+ )
)
),
'type' => 'text/html; charset=' . Horde_Nls::getCharset()
protected function _IMPrender($inline)
{
$data = $this->_mimepart->getContents();
- $charset = Horde_Nls::getCharset();
/* Sanitize the HTML. */
$data = $this->_cleanHTML($data, array('phishing' => $inline));
+ $status = array($this->_phishingStatus());
/* We are done processing if in mimp mode, or we are converting to
* text. */
return array(
'data' => IMP::filterText($data),
'status' => array(),
- 'type' => 'text/plain; charset=' . $charset
+ 'type' => 'text/plain; charset=' . Horde_Nls::getCharset()
);
}
/* Image filtering. */
if ($inline &&
- !Horde_Util::getFormData('html_view_images') &&
$GLOBALS['prefs']->getValue('html_image_replacement') &&
preg_match($this->_img_regex, $this->_mimepart->getContents()) &&
(!$GLOBALS['prefs']->getValue('html_image_addrbook') ||
!$this->_inAddressBook())) {
$data = preg_replace_callback($this->_img_regex, array($this, '_blockImages'), $data);
+
+ $status[] = array(
+ 'icon' => Horde::img('mime/image.png'),
+ 'text' => array(
+ _("Images have been blocked to protect your privacy."),
+ Horde::link('#', '', 'unblockImageLink') . _("Show Images?") . '</a>'
+ )
+ );
}
if ($GLOBALS['prefs']->getValue('emoticons')) {
return array(
'data' => $data,
- 'status' => array(),
+ 'status' => $status,
'type' => $this->_mimepart->getType(true)
);
}
protected function _blockImages($matches)
{
if (is_null($this->_blockimg)) {
- $this->_blockimg = Horde::url($GLOBALS['registry']->getImageDir('imp', false) . '/spacer_red.png', false, -1);
+ $this->_blockimg = Horde::url($GLOBALS['registry']->getImageDir('imp', false) . '/spacer_red.png', true, -1);
}
return empty($matches[2])
- ? $matches[1] . '"' . $this->_blockimg . '"'
- : $matches[1] . "'" . $this->_blockimg . '\')' . $matches[5] . '"';
+ ? $matches[1] . '"' . $this->_blockimg . '" htmlimgblocked="' . rawurlencode(str_replace('&', '&', trim($matches[5], '\'" '))) . '"'
+ : $matches[1] . "'" . $this->_blockimg . '\')' . $matches[6] . '" htmlimgblocked="' . rawurlencode(str_replace('&', '&', trim($matches[5], '\'" ')));
}
/**