From d9d276ea700186a11c6525fec375160a76229b76 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 12 May 2014 10:20:42 +0200
Subject: Improve _convert_line() performance

---
 program/lib/Roundcube/rcube_text2html.php | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

(limited to 'program/lib/Roundcube')

diff --git a/program/lib/Roundcube/rcube_text2html.php b/program/lib/Roundcube/rcube_text2html.php
index 5da771ac8..6032726b0 100644
--- a/program/lib/Roundcube/rcube_text2html.php
+++ b/program/lib/Roundcube/rcube_text2html.php
@@ -259,14 +259,20 @@ class rcube_text2html
 
         // replace spaces with non-breaking spaces
         if ($is_flowed) {
-            $text = preg_replace_callback('/(^|[^ ])( +)/', function($matches) {
-                    if (!strlen($matches[2])) {
-                        return str_repeat($nbsp, strlen($matches[2]));
-                    }
-                    else {
-                        return $matches[1] . ' ' . str_repeat($nbsp, strlen($matches[2])-1);
-                    }
-                }, $text);
+            $pos  = 0;
+            $diff = 0;
+            $len  = strlen($nbsp);
+            $copy = $text;
+
+            while (($pos = strpos($text, ' ', $pos)) !== false) {
+                if ($pos == 0 || $text[$pos-1] == ' ') {
+                    $copy = substr_replace($copy, $nbsp, $pos + $diff, 1);
+                    $diff += $len - 1;
+                }
+                $pos++;
+            }
+
+            $text = $copy;
         }
         else {
             $text = str_replace(' ', $nbsp, $text);
-- 
cgit v1.2.3


From d41367492dbbd7fdb074cd1374044917fc2e82df Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 12 May 2014 11:19:27 +0200
Subject: Fix flowed lines recognition

---
 program/lib/Roundcube/rcube_text2html.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'program/lib/Roundcube')

diff --git a/program/lib/Roundcube/rcube_text2html.php b/program/lib/Roundcube/rcube_text2html.php
index 6032726b0..9ca3f960f 100644
--- a/program/lib/Roundcube/rcube_text2html.php
+++ b/program/lib/Roundcube/rcube_text2html.php
@@ -163,7 +163,7 @@ class rcube_text2html
         // find/mark quoted lines...
         for ($n=0, $cnt=count($text); $n < $cnt; $n++) {
             $flowed = false;
-            if ($this->config['flowed'] && ord($text[0]) == $flowed_char) {
+            if ($this->config['flowed'] && ord($text[$n][0]) == $flowed_char) {
                 $flowed   = true;
                 $text[$n] = substr($text[$n], 1);
             }
-- 
cgit v1.2.3


From e0881f985d558a1084ccc1c50702c4867b94f4c1 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 12 May 2014 11:22:06 +0200
Subject: Disable wrapping non-flowed lines on dash character

---
 program/lib/Roundcube/rcube_text2html.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

(limited to 'program/lib/Roundcube')

diff --git a/program/lib/Roundcube/rcube_text2html.php b/program/lib/Roundcube/rcube_text2html.php
index 9ca3f960f..e0502c42b 100644
--- a/program/lib/Roundcube/rcube_text2html.php
+++ b/program/lib/Roundcube/rcube_text2html.php
@@ -275,7 +275,8 @@ class rcube_text2html
             $text = $copy;
         }
         else {
-            $text = str_replace(' ', $nbsp, $text);
+            // make the whole line non-breakable
+            $text = str_replace(array(' ', '-'), array($nbsp, '-&#8288;'), $text);
         }
 
         return $text;
-- 
cgit v1.2.3