Skip to content

Commit

Permalink
Don't use eval() to load HTML data
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Aug 26, 2014
1 parent 72e5499 commit 375e019
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 26 deletions.
2 changes: 2 additions & 0 deletions imp/js/dimpbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,8 @@ var DimpBase = {
$('previewPane').scrollTop = 0;
pm.show();

DimpCore.msgMetadata(r.md);

if (r.js) {
eval(r.js.join(';'));
}
Expand Down
11 changes: 11 additions & 0 deletions imp/js/dimpcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ var DimpCore = {
}, this);
},

msgMetadata: function(md)
{
$H(md).each(function(pair) {
switch (pair.key) {
case 'html':
IMP_JS.iframeInject(pair.value[0], pair.value[1]);
break;
}
});
},

/* Add message log info to message view. */
updateMsgLog: function(log)
{
Expand Down
7 changes: 6 additions & 1 deletion imp/js/message-dimp.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

var DimpMessage = {

// Variables defaulting to empty/false: buid, mbox
// buid,
// mbox,
// msg_md

quickreply: function(type)
{
Expand Down Expand Up @@ -295,6 +297,9 @@ var DimpMessage = {
}
}

DimpCore.msgMetadata(this.msg_md);
delete this.msg_md;

$('dimpLoading').hide();
$('msgData').show();

Expand Down
11 changes: 11 additions & 0 deletions imp/js/smartmobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,17 @@ var ImpMobile = {

$.fn[cache.readonly ? 'hide' : 'show'].call($('#imp-message-delete'));

if (data.md) {
$.each(data.md, function(k, md) {
switch (k) {
case 'html':
IMP_JS.iframeInject(md[0], md[1]);
$("#imp-message-body a[href='#unblock-image']").button();
break;
}
});
}

if (data.js) {
$.each(data.js, function(k, js) {
$.globalEval(js);
Expand Down
16 changes: 5 additions & 11 deletions imp/lib/Ajax/Application/ShowMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function __construct(IMP_Indices $indices, $peek = false)
* - js: Javascript code to run on display
* - list_info (FULL): List information.
* - localdate (PREVIEW): The date formatted to the user's timezone
* - md: Metadata
* - msgtext: The text of the message
* - onepart: True if message only contains one part.
* - replyTo (FULL): The Reply-to addresses
Expand All @@ -130,10 +131,7 @@ public function showMessage($args)
global $injector, $page_output, $prefs, $registry, $session;

$preview = !empty($args['preview']);

$result = array(
'js' => array()
);
$result = array();

$mime_headers = $this->_peek
? $this->_contents->getHeader()
Expand Down Expand Up @@ -301,7 +299,7 @@ public function showMessage($args)
));
$session->start();

$result['js'] = array_merge($result['js'], $inlineout['js_onload']);
$result['md'] = $inlineout['metadata'];
$result['msgtext'] .= $inlineout['msgtext'];
if ($inlineout['one_part']) {
$result['onepart'] = true;
Expand Down Expand Up @@ -361,7 +359,7 @@ public function showMessage($args)
Horde::startBuffer();
$page_output->outputInlineScript(true);
if ($js_inline = Horde::endBuffer()) {
$result['js'][] = $js_inline;
$result['js'] = $js_inline;
}

$result['save_as'] = strval($result['save_as']->setRaw(true));
Expand All @@ -372,10 +370,6 @@ public function showMessage($args)
}
}

if (empty($result['js'])) {
unset($result['js']);
}

/* Add changed flag information. */
if (!$this->_peek && $mbox->is_imap) {
$status = $mbox->imp_imap->status($mbox, Horde_Imap_Client::STATUS_PERMFLAGS);
Expand All @@ -384,7 +378,7 @@ public function showMessage($args)
}
}

return $result;
return array_filter($result);
}

/**
Expand Down
1 change: 0 additions & 1 deletion imp/lib/Basic/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,6 @@ protected function _init()

/* Output message page now. */
$page_output->addInlineJsVars($js_vars, array('top' => true));
$page_output->addInlineScript($inlineout['js_onload'], true);
$page_output->addScriptFile('scriptaculous/effects.js', 'horde');
$page_output->addScriptFile('hordecore.js', 'horde');
$page_output->addScriptFile('message.js');
Expand Down
10 changes: 5 additions & 5 deletions imp/lib/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -1406,15 +1406,15 @@ public function getPartName(Horde_Mime_Part $part, $use_descrip = false)
* @return array An array with the following keys:
* - atc_parts: (array) The list of attachment MIME IDs.
* - display_ids: (array) The list of display MIME IDs.
* - js_onload: (array) A list of javascript code to run onload.
* - metadata: (array) A list of metadata.
* - msgtext: (string) The rendered HTML code.
* - one_part: (boolean) If true, the message only consists of one part.
*/
public function getInlineOutput(array $options = array())
{
global $prefs, $registry;

$atc_parts = $display_ids = $msgtext = $js_onload = $wrap_ids = array();
$atc_parts = $display_ids = $metadata = $msgtext = $wrap_ids = array();
$parts_list = $this->getContentTypeMap();
$text_out = '';
$view = $registry->getView();
Expand Down Expand Up @@ -1512,8 +1512,8 @@ public function getInlineOutput(array $options = array())
'wrap' => empty($info['wrap']) ? null : $info['wrap']
);

if (isset($info['js'])) {
$js_onload = array_merge($js_onload, $info['js']);
if (isset($info['metadata'])) {
$metadata = array_merge($metadata, $info['metadata']);
}

if ($no_inline_all) {
Expand Down Expand Up @@ -1555,7 +1555,7 @@ public function getInlineOutput(array $options = array())
return array(
'atc_parts' => $atc_parts,
'display_ids' => array_keys($display_ids),
'js_onload' => $js_onload,
'metadata' => $metadata,
'msgtext' => $text_out,
'one_part' => (count($parts_list) == 1)
);
Expand Down
3 changes: 3 additions & 0 deletions imp/lib/Dynamic/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ protected function _init()
}
$js_vars['DimpMessage.buid'] = $buid;
$js_vars['DimpMessage.mbox'] = $this->indices->mailbox->form_to;
if (isset($msg_res['md'])) {
$js_vars['DimpMessage.msg_md'] = $msg_res['md'];
}
$js_vars['DimpMessage.tasks'] = $injector->getInstance('Horde_Core_Factory_Ajax')->create('imp', $this->vars)->getTasks();

$page_output->addInlineJsVars($js_vars);
Expand Down
9 changes: 1 addition & 8 deletions imp/lib/Mime/Viewer/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,7 @@ protected function _renderInline()

$page_output->addScriptPackage('IMP_Script_Package_Imp');

$data['js'] = array(
'IMP_JS.iframeInject("' . $uid . '", ' . json_encode($data['data']) . ')'
);

if ($view == $registry::VIEW_SMARTMOBILE) {
$data['js'][] = '$("#imp-message-body a[href=\'#unblock-image\']").button()';
}

$data['metadata'] = array('html' => array($uid, $data['data']));
$data['data'] = '<div>' . _("Loading...") . '</div><iframe class="htmlMsgData" id="' . $uid . '" src="javascript:false" frameborder="0" style="display:none;height:auto;"></iframe>';
$data['type'] = 'text/html; charset=UTF-8';
break;
Expand Down

0 comments on commit 375e019

Please sign in to comment.