Move tidy filtering to Horde_Text_Filter::
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 6 Jul 2009 20:04:17 +0000 (14:04 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 6 Jul 2009 20:04:17 +0000 (14:04 -0600)
imp/config/mime_drivers.php.dist
imp/docs/INSTALL
imp/lib/Compose.php
imp/lib/IMP.php
imp/lib/Mime/Viewer/Html.php
imp/test.php

index 7c73103..621c4c7 100644 (file)
@@ -93,9 +93,6 @@ $mime_drivers['imp']['html'] = array(
      * bytes).  If exceeded, the user will only be able to download the part.
      * Set to 0 to disable this check. */
     'limit_inline_size' => 1048576,
-    /* Run 'tidy' on all HTML output? This requires at least version 2.0 of the
-     * PECL 'tidy' extension to be installed on your system. */
-    'tidy' => false,
     /* Check for phishing exploits? */
     'phishing_check' => true
 );
index 5ca7d1b..39466e2 100644 (file)
@@ -110,14 +110,6 @@ To function properly, IMP **requires** the following:
       See http://www.php.net/openssl for information on compiling OpenSSL
       into PHP.
 
-   b. tidy ``--with-tidy``
-
-      The tidy PHP extension is required if you want IMP to sanitize the
-      output of HTML messages before displaying to the user and if you want
-      to clean and repair outgoing HTML messages composed via the HTML
-      composition mode.  See ``imp/config/mime_drivers.php.dist`` for
-      further instructions on how to enable this feature.
-
 3. The following PEAR modules:
    (See `horde/docs/INSTALL`_ for instructions on installing PEAR modules)
 
index 4765416..36ace86 100644 (file)
@@ -975,15 +975,7 @@ class IMP_Compose
             $htmlBody->setCharset($charset);
             $htmlBody->setDisposition('inline');
             $htmlBody->setDescription(Horde_String::convertCharset(_("HTML Version of Message"), $nls_charset, $charset));
-
-            /* Run tidy on the HTML, if available. */
-            if ($tidy_config = IMP::getTidyConfig(strlen($body_html))) {
-                $tidy = tidy_parse_string(Horde_String::convertCharset($body_html, $charset, 'UTF-8'), $tidy_config, 'utf8');
-                $tidy->cleanRepair();
-                $htmlBody->setContents(Horde_String::convertCharset(tidy_get_output($tidy), 'UTF-8', $charset));
-            } else {
-                $htmlBody->setContents($body_html);
-            }
+            $htmlBody->setContents(Horde_Text_Filter::filter($msg, 'cleanhtml', array('charset' => $charset)));
 
             $textBody->setDescription(Horde_String::convertCharset(_("Plaintext Version of Message"), $nls_charset, $charset));
 
@@ -2217,17 +2209,8 @@ class IMP_Compose
             }
         }
 
-        /* Run tidy on the HTML. */
-        if (($mode == 'html)' &&
-            ($tidy_config = IMP::getTidyConfig($part->getBytes())))) {
-            $tidy_config['show-body-only'] = true;
-            $tidy = tidy_parse_string(Horde_String::convertCharset($msg, $charset, 'UTF-8'), $tidy_config, 'UTF8');
-            $tidy->cleanRepair();
-            $msg = Horde_String::convertCharset(tidy_get_output($tidy), 'UTF-8', $charset);
-        }
-
         if ($mode == 'html') {
-            $msg = Horde_Text_Filter::filter($msg, 'xss', array('body_only' => true, 'strip_styles' => true, 'strip_style_attributes' => false));
+            $msg = Horde_Text_Filter::filter($msg, array('cleanhtml', 'xss'), array(array('body_only' => true, 'charset' => $charset), array('body_only' => true, 'strip_styles' => true, 'strip_style_attributes' => false)));
         } elseif ($type == 'text/html') {
             $msg = Horde_Text_Filter::filter($msg, 'html2text', array('charset' => $charset));
             $type = 'text/plain';
index b0f3ccd..d7f6645 100644 (file)
@@ -1380,34 +1380,6 @@ class IMP
     }
 
     /**
-     * Determines if the tidy extension is available and is the correct
-     * version.  Returns the config array.
-     *
-     * @param integer $size  Size of the HTML data, in bytes.
-     *
-     * @return mixed  The config array, or false if tidy is not available.
-     */
-    static public function getTidyConfig($size)
-    {
-        if (!Horde_Util::extensionExists('tidy') ||
-            function_exists('tidy_load_config') &&
-            ($size > 250000)) {
-            return false;
-        }
-
-        return array(
-            'wrap' => 0,
-            'indent' => true,
-            'indent-spaces' => 4,
-            'tab-size' => 4,
-            'output-xhtml' => true,
-            'enclose-block-text' => true,
-            'hide-comments' => true,
-            'numeric-entities' => true
-        );
-    }
-
-    /**
      * Outputs the necessary script tags, honoring local configuration
      * choices as to script caching.
      */
index a893b45..ddb4bd8 100644 (file)
@@ -116,20 +116,6 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html
             $msg_charset = $charset;
         }
 
-        /* Run tidy on the HTML. */
-        if ($this->getConfigParam('tidy') &&
-            ($tidy_config = IMP::getTidyConfig(Horde_String::length($data)))) {
-            if ($msg_charset == 'us-ascii') {
-                $tidy = tidy_parse_string($data, $tidy_config, 'ascii');
-                $tidy->cleanRepair();
-                $data = tidy_get_output($tidy);
-            } else {
-                $tidy = tidy_parse_string(Horde_String::convertCharset($data, $msg_charset, 'UTF-8'), $tidy_config, 'utf8');
-                $tidy->cleanRepair();
-                $data = Horde_String::convertCharset(tidy_get_output($tidy), 'UTF-8', $msg_charset);
-            }
-        }
-
         /* Sanitize the HTML. */
         $cleanhtml = $this->_cleanHTML($data, $inline);
         $data = $cleanhtml['html'];
index 85c57fc..24f4fa8 100644 (file)
@@ -163,11 +163,6 @@ $module_list = array(
         'descrip' => 'OpenSSL Support',
         'error' => 'The openssl module is required to use S/MIME in IMP. Compile PHP with <code>--with-openssl</code> to activate.',
         'fatal' => false
-    ),
-    'tidy' => array(
-        'descrip' => 'Tidy support',
-        'error' => 'If the tidy PHP extension is available, IMP can use it to sanitize the output of HTML messages before displaying to the user, and to clean outgoing HTML messages created in the HTML composition mode. See <code>imp/docs/INSTALL</code> for more information.',
-        'fatal' => false,
     )
 );