[Svn] r4223 - in trunk/roundcubemail: . program/lib program/steps/mail tests

trac at roundcube.net trac at roundcube.net
Sun Nov 14 12:35:39 CET 2010


Author: alec
Date: 2010-11-14 05:35:38 -0600 (Sun, 14 Nov 2010)
New Revision: 4223

Added:
   trunk/roundcubemail/tests/html_to_text.php
Modified:
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/program/lib/html2text.php
   trunk/roundcubemail/program/steps/mail/compose.inc
Log:
- Fix hanling of HTML entity strings in plai text messages


Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2010-11-14 10:09:14 UTC (rev 4222)
+++ trunk/roundcubemail/CHANGELOG	2010-11-14 11:35:38 UTC (rev 4223)
@@ -69,6 +69,7 @@
 - Fix handling of folders with name "0" (#1487119)
 - Fix handling of folders with "<>" characters in name
 - jQuery 1.4.4
+- Fix handling of HTML entity strings in plain text messages
 
 RELEASE 0.4.2
 -------------

Modified: trunk/roundcubemail/program/lib/html2text.php
===================================================================
--- trunk/roundcubemail/program/lib/html2text.php	2010-11-14 10:09:14 UTC (rev 4222)
+++ trunk/roundcubemail/program/lib/html2text.php	2010-11-14 11:35:38 UTC (rev 4223)
@@ -167,7 +167,6 @@
         '/&(apos|rsquo|lsquo|#8216|#8217);/i',   // Single quotes
         '/>/i',                               // Greater-than
         '/</i',                               // Less-than
-        '/&(amp|#38);/i',                        // Ampersand
         '/&(copy|#169);/i',                      // Copyright
         '/&(trade|#8482|#153);/i',               // Trademark
         '/&(reg|#174);/i',                       // Registered
@@ -176,6 +175,7 @@
         '/&(bull|#149|#8226);/i',                // Bullet
         '/&(pound|#163);/i',                     // Pound sign
         '/&(euro|#8364);/i',                     // Euro sign
+        '/&(amp|#38);/i',                        // Ampersand: see _converter()
         '/[ ]{2,}/'                              // Runs of spaces, post-handling
     );
 
@@ -210,7 +210,6 @@
         "'",                                    // Single quotes
         '>',
         '<',
-        '&',
         '(c)',
         '(tm)',
         '(R)',
@@ -219,6 +218,7 @@
         '*',
         '£',
         'EUR',                                  // Euro sign. € ?
+        '|+|amp|+|',                            // Ampersand: see _converter()
         ' '                                     // Runs of spaces, post-handling
     );
 
@@ -502,8 +502,12 @@
         $text = preg_replace_callback($this->callback_search, array('html2text', '_preg_callback'), $text);
 
         // Remove unknown/unhandled entities (this cannot be done in search-and-replace block)
-        $text = preg_replace('/&#?[a-z0-9]{2,7};/i', '', $text); 
+        $text = preg_replace('/&([a-zA-Z0-9]{2,6}|#[0-9]{2,4});/', '', $text);
 
+        // Convert "|+|amp|+|" into "&", need to be done after handling of unknown entities
+        // This properly handles situation of "&quot;" in input string
+        $text = str_replace('|+|amp|+|', '&', $text);
+
         // Strip any other HTML tags
         $text = strip_tags($text, $this->allowed_tags);
 

Modified: trunk/roundcubemail/program/steps/mail/compose.inc
===================================================================
--- trunk/roundcubemail/program/steps/mail/compose.inc	2010-11-14 10:09:14 UTC (rev 4222)
+++ trunk/roundcubemail/program/steps/mail/compose.inc	2010-11-14 11:35:38 UTC (rev 4223)
@@ -646,9 +646,20 @@
   $out .= $msgtype->show();
 
   // If desired, set this textarea to be editable by TinyMCE
-  if ($isHtml) $attrib['class'] = 'mce_editor';
-  $textarea = new html_textarea($attrib);
-  $out .= $textarea->show($MESSAGE_BODY);
+  if ($isHtml) {
+    $attrib['class'] = 'mce_editor';
+    $textarea = new html_textarea($attrib);
+    $out .= $textarea->show($MESSAGE_BODY);
+  }
+  else {
+    $textarea = new html_textarea($attrib);
+    $out .= $textarea->show('');
+    // quote plain text, inject into textarea
+    $table = get_html_translation_table(HTML_SPECIALCHARS);
+    $MESSAGE_BODY = strtr($MESSAGE_BODY, $table);
+    $out = substr($out, 0, -11) . $MESSAGE_BODY . '</textarea>';
+  }
+
   $out .= $form_end ? "\n$form_end" : '';
 
   $OUTPUT->set_env('composebody', $attrib['id']);

Added: trunk/roundcubemail/tests/html_to_text.php
===================================================================
--- trunk/roundcubemail/tests/html_to_text.php	                        (rev 0)
+++ trunk/roundcubemail/tests/html_to_text.php	2010-11-14 11:35:38 UTC (rev 4223)
@@ -0,0 +1,46 @@
+<?php
+
+/**
+ * Test class to test html2text class
+ *
+ * @package Tests
+ */
+class rcube_test_html2text extends UnitTestCase
+{
+
+    function __construct()
+    {
+        $this->UnitTestCase("HTML-to-Text conversion tests");
+
+    }
+
+    function test_html2text()
+    {
+        $data = array(
+            0 => array(
+                'title' => 'Test entry',
+                'in'    => '',
+                'out'   => '',
+            ),
+            1 => array(
+                'title' => 'Basic HTML entities',
+                'in'    => '"&',
+                'out'   => '"&',
+            ),
+            2 => array(
+                'title' => 'HTML entity string',
+                'in'    => '&quot;',
+                'out'   => '"',
+            ),
+        );
+
+        $ht = new html2text(null, false, false);
+
+        foreach ($data as $item) {
+            $ht->set_html($item['in']);
+            $res = $ht->get_text();
+            $this->assertEqual($item['out'], $res, $item['title']);
+        }
+    }
+
+}

-------------- next part --------------
_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn


More information about the Svn mailing list