summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2014-05-12 20:22:10 +0200
committerAleksander Machniak <alec@alec.pl>2014-05-12 20:22:10 +0200
commit1053ae5e729203b16d792c53640b6273feed2056 (patch)
tree5a40574f34e0bc08ce30287df527a25ec999e931 /program
parente2b4760e846e8b74f2f674e1fa25d82ba21e7a2e (diff)
parente0881f985d558a1084ccc1c50702c4867b94f4c1 (diff)
Merge branch 'dev-text2html' of github.com:roundcube/roundcubemail into dev-text2html
Diffstat (limited to 'program')
-rw-r--r--program/lib/Roundcube/rcube_text2html.php27
1 files changed, 17 insertions, 10 deletions
diff --git a/program/lib/Roundcube/rcube_text2html.php b/program/lib/Roundcube/rcube_text2html.php
index cb4390e5d..60016fffd 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);
}
@@ -259,17 +259,24 @@ 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);
+ // make the whole line non-breakable
+ $text = str_replace(array(' ', '-'), array($nbsp, '-&#8288;'), $text);
}
return $text;