Bug #8836: Rework DNS Prefetch disable
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 1 Jul 2010 18:19:43 +0000 (12:19 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 1 Jul 2010 18:34:26 +0000 (12:34 -0600)
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.

12 files changed:
framework/Core/lib/Horde.php
framework/Mime/lib/Horde/Mime/Viewer/Enriched.php
framework/Mime/lib/Horde/Mime/Viewer/Html.php
framework/Text_Filter/lib/Horde/Text/Filter/Xss.php
imp/index-dimp.php
imp/lib/Mime/Viewer/Html.php
imp/lib/Mime/Viewer/Plain.php
imp/lib/Ui/Message.php
imp/message-dimp.php
imp/message-mimp.php
imp/message.php
imp/thread.php

index 0f70ffc..aa2d326 100644 (file)
@@ -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()
index 5f79c9b..f730fb2 100644 (file)
@@ -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*
index bb6a790..eb479e5 100644 (file)
@@ -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
             )
index 7c71ad1..f9bfcc9 100644 (file)
@@ -305,18 +305,13 @@ class Horde_Text_Filter_Xss extends Horde_Text_Filter_Base
         }
 
         if ($this->_params['noprefetch']) {
-            if (preg_match('/<html[^>]*>/si', $text, $matches, PREG_OFFSET_CAPTURE)) {
-                preg_match('/<\/html>/si', $text, $matches2, PREG_OFFSET_CAPTURE);
+            if (preg_match('/<head[^>]*>/si', $text, $matches, PREG_OFFSET_CAPTURE)) {
                 $end = $matches[0][1] + strlen($matches[0][0]);
                 $text = substr($text, 0, $end) .
                     '<meta http-equiv="x-dns-prefetch-control" value="off" />' .
-                    substr($text, $end, $matches2[0][1] - $end) .
-                    '<meta http-equiv="x-dns-prefetch-control" value="on" />' .
-                    substr($text, $matches2[0][1]);
+                    substr($text, $end);
             } else {
-                $text = '<meta http-equiv="x-dns-prefetch-control" value="off" />' .
-                    $text .
-                    '<meta http-equiv="x-dns-prefetch-control" value="on" />';
+                $text = '<meta http-equiv="x-dns-prefetch-control" value="off" />' . $text;
             }
         }
 
index 3ad9fe6..a16fd2e 100644 (file)
@@ -48,6 +48,7 @@ if (!empty($site_menu)) {
 }
 
 Horde::addInlineScript($js_code, 'load');
+Horde::noDnsPrefetch();
 IMP_Dimp::header('', $scripts);
 
 /* Get application folders list. */
index f88599f..3de7192 100644 (file)
@@ -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
index 2f0b863..f9be002 100644 (file)
@@ -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(),
index 097731b..112f75e 100644 (file)
@@ -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
         ));
     }
index c09f88e..d485764 100644 (file)
@@ -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 "<body>\n";
index cb1d995..4c1e59a 100644 (file)
@@ -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');
index ea45717..72677b7 100644 (file)
@@ -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']);
 }
index 2f893e6..b87ab44 100644 (file)
@@ -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();