diff options
author | Aleksander Machniak <alec@alec.pl> | 2013-01-20 11:12:24 +0100 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2013-01-21 11:55:57 +0100 |
commit | aabd62828672c055205292c77f1463260f3b0c51 (patch) | |
tree | da3ca6349fb620c0d00e7c9edfdea2188c6162a0 | |
parent | 67cb017b0cdda3c2dcc7d9434fdbaca5f4ead938 (diff) |
Improve format=flowed text unfolding, add test for signature separator handling
-rw-r--r-- | program/lib/Roundcube/rcube_mime.php | 18 | ||||
-rw-r--r-- | tests/src/format-flowed-unfolded.txt | 3 | ||||
-rw-r--r-- | tests/src/format-flowed.txt | 3 |
3 files changed, 17 insertions, 7 deletions
diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php index d5fb35bcd..fd91ca979 100644 --- a/program/lib/Roundcube/rcube_mime.php +++ b/program/lib/Roundcube/rcube_mime.php @@ -476,14 +476,18 @@ class rcube_mime $q_level = 0; foreach ($text as $idx => $line) { - if ($line[0] == '>' && preg_match('/^(>+\s*)/', $line, $regs)) { - $q = strlen(str_replace(' ', '', $regs[0])); - $line = substr($line, strlen($regs[0])); - + if ($line[0] == '>') { + $len = strlen($line); + $line = preg_replace('/^>+ {0,1}/', '', $line); + $q = $len - strlen($line); + + // The same paragraph (We join current line with the previous one) when: + // - the same level of quoting + // - previous line was flowed + // - previous line contains more than only one single space (and quote char(s)) if ($q == $q_level - && strlen($line[$last]) > 1 // don't hit if line only consist of one single white space - && isset($text[$last]) - && $text[$last][strlen($text[$last])-1] == ' ' + && isset($text[$last]) && $text[$last][strlen($text[$last])-1] == ' ' + && !preg_match('/^>+ {0,1}$/', $text[$last]) ) { $text[$last] .= $line; unset($text[$idx]); diff --git a/tests/src/format-flowed-unfolded.txt b/tests/src/format-flowed-unfolded.txt index 8245d59d4..b422f981b 100644 --- a/tests/src/format-flowed-unfolded.txt +++ b/tests/src/format-flowed-unfolded.txt @@ -12,3 +12,6 @@ On XX.YY.YYYY Y:YY, Somebody wrote: > xxxxxxxxxx. xxxx xxxxx xxxxx xxxx xx xx.xx. xxxxxx xxxxxxxxxxxx, xxxx xx
>
> ... and this one as well.
+
+--
+Sig
diff --git a/tests/src/format-flowed.txt b/tests/src/format-flowed.txt index 522f829c6..d3bd90eed 100644 --- a/tests/src/format-flowed.txt +++ b/tests/src/format-flowed.txt @@ -14,3 +14,6 @@ On XX.YY.YYYY Y:YY, Somebody wrote: > xxxxxxxxxx. xxxx xxxxx xxxxx xxxx xx xx.xx. xxxxxx xxxxxxxxxxxx, xxxx xx
>
> ... and this one as well.
+
+--
+Sig
|