From 2effd3ce519011db72737c32c437f9c6364a23f0 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 1 Jul 2010 12:19:43 -0600 Subject: [PATCH] Bug #8836: Rework DNS Prefetch disable META tags must be in HEAD tag to be correct HTML/XHTML. So we need to disable prefetching for the entire page - but only on pages where we are working with mail data. --- framework/Core/lib/Horde.php | 9 +++++++++ framework/Mime/lib/Horde/Mime/Viewer/Enriched.php | 4 +--- framework/Mime/lib/Horde/Mime/Viewer/Html.php | 5 +++-- framework/Text_Filter/lib/Horde/Text/Filter/Xss.php | 11 +++-------- imp/index-dimp.php | 1 + imp/lib/Mime/Viewer/Html.php | 5 ++++- imp/lib/Mime/Viewer/Plain.php | 4 ---- imp/lib/Ui/Message.php | 6 +----- imp/message-dimp.php | 2 ++ imp/message-mimp.php | 2 ++ imp/message.php | 3 +++ imp/thread.php | 1 + 12 files changed, 30 insertions(+), 23 deletions(-) diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 0f70ffcbc..aa2d3269c 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -2036,6 +2036,15 @@ HTML; } /** + * Adds a META tag to disable DNS prefetching. + * See Horde Bug #8836. + */ + static public function noDnsPrefetch() + { + self::addMetaTag('x-dns-prefetch-control', 'off'); + } + + /** * Output META tags to page. */ static public function outputMetaTags() diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Enriched.php b/framework/Mime/lib/Horde/Mime/Viewer/Enriched.php index 5f79c9bc5..f730fb214 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/Enriched.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/Enriched.php @@ -173,9 +173,7 @@ class Horde_Mime_Viewer_Enriched extends Horde_Mime_Viewer_Driver // Make URLs clickable. $text = Horde_Text_Filter::filter($text, 'linkurls', array( - 'callback' => 'Horde::externalUrl', - // See Ticket #8836 - 'noprefetch' => ($inline && $GLOBALS['browser']->isBrowser('mozilla') && !$GLOBALS['browser']->usingSSLConnection()) + 'callback' => 'Horde::externalUrl' )); /* Wordwrap -- note this could impact on our above RFC compliance *IF* diff --git a/framework/Mime/lib/Horde/Mime/Viewer/Html.php b/framework/Mime/lib/Horde/Mime/Viewer/Html.php index bb6a790bf..eb479e546 100644 --- a/framework/Mime/lib/Horde/Mime/Viewer/Html.php +++ b/framework/Mime/lib/Horde/Mime/Viewer/Html.php @@ -91,6 +91,8 @@ class Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Driver * DEFAULT: The base part charset. * 'inline' => (boolean) Are we viewing inline? * DEFAULT: false + * 'noprefetch' => (boolean) Disable DNS prefetching? + * DEFAULT: false * 'phishing' => (boolean) Do phishing highlighting even if not viewing * inline. * DEFAULT: false. @@ -141,8 +143,7 @@ class Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Driver ), array( 'body_only' => !empty($options['inline']), - // See Ticket #8836 - 'noprefetch' => (!empty($options['inline']) && $browser->isBrowser('mozilla') && !$browser->usingSSLConnection()), + 'noprefetch' => !empty($options['noprefetch']), 'strip_styles' => $strip_styles, 'strip_style_attributes' => $strip_style_attributes ) diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/Xss.php b/framework/Text_Filter/lib/Horde/Text/Filter/Xss.php index 7c71ad1ad..f9bfcc9ec 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/Xss.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/Xss.php @@ -305,18 +305,13 @@ class Horde_Text_Filter_Xss extends Horde_Text_Filter_Base } if ($this->_params['noprefetch']) { - if (preg_match('/]*>/si', $text, $matches, PREG_OFFSET_CAPTURE)) { - preg_match('/<\/html>/si', $text, $matches2, PREG_OFFSET_CAPTURE); + if (preg_match('/]*>/si', $text, $matches, PREG_OFFSET_CAPTURE)) { $end = $matches[0][1] + strlen($matches[0][0]); $text = substr($text, 0, $end) . '' . - substr($text, $end, $matches2[0][1] - $end) . - '' . - substr($text, $matches2[0][1]); + substr($text, $end); } else { - $text = '' . - $text . - ''; + $text = '' . $text; } } diff --git a/imp/index-dimp.php b/imp/index-dimp.php index 3ad9fe60a..a16fd2ed9 100644 --- a/imp/index-dimp.php +++ b/imp/index-dimp.php @@ -48,6 +48,7 @@ if (!empty($site_menu)) { } Horde::addInlineScript($js_code, 'load'); +Horde::noDnsPrefetch(); IMP_Dimp::header('', $scripts); /* Get application folders list. */ diff --git a/imp/lib/Mime/Viewer/Html.php b/imp/lib/Mime/Viewer/Html.php index f88599f1e..3de7192cb 100644 --- a/imp/lib/Mime/Viewer/Html.php +++ b/imp/lib/Mime/Viewer/Html.php @@ -183,7 +183,10 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html $data = $this->_mimepart->getContents(); /* Sanitize the HTML. */ - $data = $this->_cleanHTML($data, array('phishing' => $inline)); + $data = $this->_cleanHTML($data, array( + 'noprefetch' => ($inline && ($_SESSION['imp']['view'] != 'mimp')), + 'phishing' => $inline + )); $status = array($this->_phishingStatus()); /* We are done processing if in mimp mode, or we are converting to diff --git a/imp/lib/Mime/Viewer/Plain.php b/imp/lib/Mime/Viewer/Plain.php index 2f0b8639f..f9be002f1 100644 --- a/imp/lib/Mime/Viewer/Plain.php +++ b/imp/lib/Mime/Viewer/Plain.php @@ -112,8 +112,6 @@ class IMP_Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Plain $filters = array( 'text2html' => array( 'charset' => $charset, - // See Ticket #8836 - 'noprefetch' => ($GLOBALS['browser']->isBrowser('mozilla') && !$GLOBALS['browser']->usingSSLConnection()), 'parselevel' => $inline ? Horde_Text_Filter_Text2html::MICRO : Horde_Text_Filter_Text2html::MICRO_LINKURL ), 'tabs2spaces' => array(), @@ -350,8 +348,6 @@ class IMP_Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Plain $filters = array( 'text2html' => array( 'charset' => Horde_Nls::getCharset(), - // See Ticket #8836 - 'noprefetch' => ($GLOBALS['browser']->isBrowser('mozilla') && !$GLOBALS['browser']->usingSSLConnection()), 'parselevel' => Horde_Text_Filter_Text2html::MICRO ), 'tabs2spaces' => array(), diff --git a/imp/lib/Ui/Message.php b/imp/lib/Ui/Message.php index 097731b99..112f75e42 100644 --- a/imp/lib/Ui/Message.php +++ b/imp/lib/Ui/Message.php @@ -237,9 +237,7 @@ class IMP_Ui_Message break; } elseif (empty($data['email'])) { if ($url = Horde_Text_Filter::filter($match, 'linkurls', array( - 'callback' => 'Horde::externalUrl', - // See Ticket #8836 - 'noprefetch' => ($GLOBALS['browser']->isBrowser('mozilla') && !$GLOBALS['browser']->usingSSLConnection()) + 'callback' => 'Horde::externalUrl' ))) { if (!empty($opts['raw'])) { return $match; @@ -627,8 +625,6 @@ class IMP_Ui_Message public function getDisplaySubject($subject) { return Horde_Text_Filter::filter(preg_replace("/\b\s+\b/", ' ', IMP::filterText($subject)), 'text2html', array( - // See Ticket #8836 - 'noprefetch' => ($GLOBALS['browser']->isBrowser('mozilla') && !$GLOBALS['browser']->usingSSLConnection()), 'parselevel' => Horde_Text_Filter_Text2html::MICRO )); } diff --git a/imp/message-dimp.php b/imp/message-dimp.php index c09f88eaf..d485764dd 100644 --- a/imp/message-dimp.php +++ b/imp/message-dimp.php @@ -111,6 +111,8 @@ if (isset($show_msg_result['js'])) { Horde::addInlineScript($js_out); Horde::addInlineScript(array_filter($js_onload), 'load'); +Horde::noDnsPrefetch(); + IMP::status(); IMP_Dimp::header($show_msg_result['title'], $scripts); echo "\n"; diff --git a/imp/message-mimp.php b/imp/message-mimp.php index cb1d995b5..4c1e59ae2 100644 --- a/imp/message-mimp.php +++ b/imp/message-mimp.php @@ -356,6 +356,8 @@ $t->set('atc', $atc); $title = $display_headers['subject']; $t->set('title', ($status ? $status . ' ' : '') . sprintf(_("(Message %d of %d)"), $msgindex, $msgcount)); +Horde::noDnsPrefetch(); + require IMP_TEMPLATES . '/common-header.inc'; IMP::status(); echo $t->fetch(IMP_TEMPLATES . '/mimp/message/message.html'); diff --git a/imp/message.php b/imp/message.php index ea45717c8..72677b782 100644 --- a/imp/message.php +++ b/imp/message.php @@ -665,7 +665,10 @@ Horde::addScriptFile('effects.js', 'horde'); Horde::addScriptFile('imp.js', 'imp'); Horde::addScriptFile('message.js', 'imp'); IMP::prepareMenu(); +Horde::noDnsPrefetch(); + require IMP_TEMPLATES . '/common-header.inc'; + if (!empty($conf['maillog']['use_maillog'])) { IMP_Maillog::displayLog($envelope['message-id']); } diff --git a/imp/thread.php b/imp/thread.php index 2f893e6a1..b87ab4462 100644 --- a/imp/thread.php +++ b/imp/thread.php @@ -161,6 +161,7 @@ $template->set('tree', $tree); /* Output page. */ $title = ($mode == 'thread') ? _("Thread View") : _("Multiple Message View"); Horde::addScriptFile('stripe.js', 'horde'); +Horde::noDnsPrefetch(); IMP::prepareMenu(); require IMP_TEMPLATES . '/common-header.inc'; IMP::menu(); -- 2.11.0