[Svn] r4637 - in trunk/roundcubemail: . program/lib

trac at roundcube.net trac at roundcube.net
Fri Apr 8 09:22:08 CEST 2011


Author: alec
Date: 2011-04-08 02:22:07 -0500 (Fri, 08 Apr 2011)
New Revision: 4637

Modified:
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/program/lib/html2text.php
Log:
- Fix bug where some content would cause hang on html2text conversion (#1487863) 


Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2011-04-08 07:08:30 UTC (rev 4636)
+++ trunk/roundcubemail/CHANGELOG	2011-04-08 07:22:07 UTC (rev 4637)
@@ -1,8 +1,9 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Fix bug where some content would cause hang on html2text conversion (#1487863)
 - Improve space-stuffing handling in format=flowed messages (#1487861)
-- Fixed bug where some dates would produce SQL error in MySQL (#1487856)
+- Fix bug where some dates would produce SQL error in MySQL (#1487856)
 - Added workaround for some IMAP server with broken STATUS response (#1487859)
 - Fix bug where default_charset was not used for text messages (#1487836)
 - Enable TinyMCE's contextmenu (#1487014)

Modified: trunk/roundcubemail/program/lib/html2text.php
===================================================================
--- trunk/roundcubemail/program/lib/html2text.php	2011-04-08 07:08:30 UTC (rev 4636)
+++ trunk/roundcubemail/program/lib/html2text.php	2011-04-08 07:22:07 UTC (rev 4637)
@@ -572,9 +572,16 @@
      */
     function _convert_pre(&$text)
     {
+        // get the content of PRE element
         while (preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches)) {
-            $result = preg_replace($this->pre_search, $this->pre_replace, $matches[1]);
-            $text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text, 1);
+            // convert the content
+            $this->pre_content = sprintf('<div><br>%s<br></div>',
+                preg_replace($this->pre_search, $this->pre_replace, $matches[1]));
+            // replace the content (use callback because content can contain $0 variable)
+            $text = preg_replace_callback('/<pre[^>]*>.*<\/pre>/ismU', 
+                array('html2text', '_preg_pre_callback'), $text, 1);
+            // free memory
+            $this->pre_content = '';
         }
     }
 
@@ -639,9 +646,8 @@
      *
      *  @param  array PREG matches
      *  @return string
-     *  @access private
      */
-    function _preg_callback($matches)
+    private function _preg_callback($matches)
     {
         switch($matches[1]) {
         case 'b':
@@ -659,13 +665,23 @@
     }
 
     /**
+     *  Callback function for preg_replace_callback use in PRE content handler.
+     *
+     *  @param  array PREG matches
+     *  @return string
+     */
+    private function _preg_pre_callback($matches)
+    {
+        return $this->pre_content;
+    }
+
+    /**
      *  Strtoupper multibyte wrapper function
      *
      *  @param  string
      *  @return string
-     *  @access private
      */
-    function _strtoupper($str)
+    private function _strtoupper($str)
     {
         if (function_exists('mb_strtoupper'))
             return mb_strtoupper($str);

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list