diff --git a/program/lib/Roundcube/rcube_text2html.php b/program/lib/Roundcube/rcube_text2html.php index 8bcda301c..363f1b21f 100644 --- a/program/lib/Roundcube/rcube_text2html.php +++ b/program/lib/Roundcube/rcube_text2html.php @@ -158,10 +158,10 @@ class rcube_text2html // split body into single lines $text = preg_split('/\r?\n/', $text); $quote_level = 0; - $last = -1; + $last = null; - // find/mark quoted lines... - for ($n=0, $cnt=count($text); $n < $cnt; $n++) { + // wrap quoted lines with
+ for ($n = 0, $cnt = count($text); $n < $cnt; $n++) { $flowed = false; if ($this->config['flowed'] && ord($text[$n][0]) == $flowed_char) { $flowed = true; @@ -172,43 +172,71 @@ class rcube_text2html $q = substr_count($regs[0], '>'); $text[$n] = substr($text[$n], strlen($regs[0])); $text[$n] = $this->_convert_line($text[$n], $flowed || $this->config['wrap']); + $_length = strlen(str_replace(' ', '', $text[$n])); if ($q > $quote_level) { - $text[$n] = $replacer->get_replacement($replacer->add( - str_repeat('', $quote_level))) + . $text[$n]; + + unset($text[$n]); + } + else { + $last = $n; } } $quote_level = $q; + $length = $_length; } if ($quote_level > 0) { - $text[$n] = $replacer->get_replacement($replacer->add( - str_repeat('', $quote_level))) . $text[$n]; + $text[$last] .= $replacer->get_replacement($replacer->add( + str_repeat('', $quote_level))); } $text = join("\n", $text); // colorize signature (up to', $q - $quote_level))) . $text[$n]; - $last = $n; + if ($last !== null) { + $text[$last] .= (!$length ? "\n" : '') + . $replacer->get_replacement($replacer->add( + str_repeat('', $quote_level))) . $text[$n]; + $text[$last] .= (!$length ? "\n" : '') + . $replacer->get_replacement($replacer->add( + str_repeat('', $q - $quote_level))) + . $text[$n]; + + unset($text[$n]); + } + else { + $text[$n] = $replacer->get_replacement($replacer->add( + str_repeat('', $quote_level - $q))) + . $text[$n]; + + unset($text[$n]); + } + else { $last = $n; } } else { $text[$n] = $this->_convert_line($text[$n], $flowed || $this->config['wrap']); - $q = 0; + $q = 0; + $_length = strlen(str_replace(' ', '', $text[$n])); if ($quote_level > 0) { - $text[$n] = $replacer->get_replacement($replacer->add( - str_repeat('', $q - $quote_level))) . $text[$n]; + + $last = $n; + } } else if ($q < $quote_level) { - $text[$n] = $replacer->get_replacement($replacer->add( - str_repeat('', $quote_level - $q))) . $text[$n]; + $text[$last] .= (!$length ? "\n" : '') + . $replacer->get_replacement($replacer->add( + str_repeat('
aaaa_", $options); $data[] = array(">aaaa\n>aaaa", "
aaaa
aaaa", $options); $data[] = array(">aaaa \n>bbbb\ncccc dddd", "
aaaa
aaaa_cccc_dddd", $options); + $data[] = array("aaaa-bbbb/cccc", "aaaa-bbbb/cccc", $options); $options['flowed'] = true; @@ -63,6 +64,16 @@ class Framework_Text2Html extends PHPUnit_Framework_TestCase $data[] = array(">aaaa\n>aaaa", "
bbbb
aaaa", $options); $data[] = array(">aaaa \n>bbbb\ncccc dddd", "
aaaa
aaaa bbbbcccc_dddd", $options); + $options['flowed'] = false; + $options['wrap'] = true; + + $data[] = array(">>aaaa bbbb\n>>\n>>>\n>cccc\n\ndddd eeee", + "
aaaa bbbbcccc
aaaa
bbbb
cccc
", $options); + return $data; }test