From acf851f823fba5354c2227e48c3097a524312268 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 7 Jan 2013 17:53:37 +0100 Subject: Fix address fields import from CSV (#1488900) --- tests/src/Csv2vcard/tb_plain.vcf | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/src') diff --git a/tests/src/Csv2vcard/tb_plain.vcf b/tests/src/Csv2vcard/tb_plain.vcf index aace259d8..b001c3924 100644 --- a/tests/src/Csv2vcard/tb_plain.vcf +++ b/tests/src/Csv2vcard/tb_plain.vcf @@ -15,4 +15,6 @@ ORG:Organization URL;TYPE=homepage:http://page.com URL;TYPE=other:http://webpage.tld BDAY;VALUE=date:1970-11-15 +ADR;TYPE=home:;;Priv address;City;region;xx-xxx;USA +ADR;TYPE=work:;;Addr work;;;33-333;Poland END:VCARD -- cgit v1.2.3 From 6d41d8fd4bbd3f8854669fbf2fc5a4910803125a Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Fri, 18 Jan 2013 21:26:18 +0100 Subject: Fix format=flowed unfolding on quoted lines; added tests for rcube_mime::format_flowed() and rcube_mime::unfold_flowed() --- program/lib/Roundcube/rcube_mime.php | 3 ++- tests/Framework/Mime.php | 22 ++++++++++++++++++++++ tests/src/format-flowed-unfolded.txt | 14 ++++++++++++++ tests/src/format-flowed.txt | 16 ++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/src/format-flowed-unfolded.txt create mode 100644 tests/src/format-flowed.txt (limited to 'tests/src') diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php index eef8ca17c..d5fb35bcd 100644 --- a/program/lib/Roundcube/rcube_mime.php +++ b/program/lib/Roundcube/rcube_mime.php @@ -480,7 +480,8 @@ class rcube_mime $q = strlen(str_replace(' ', '', $regs[0])); $line = substr($line, strlen($regs[0])); - if ($q == $q_level && $line + 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] == ' ' ) { diff --git a/tests/Framework/Mime.php b/tests/Framework/Mime.php index dcd55992a..1f9a8c58f 100644 --- a/tests/Framework/Mime.php +++ b/tests/Framework/Mime.php @@ -120,4 +120,26 @@ class Framework_Mime extends PHPUnit_Framework_TestCase $this->assertEquals($item['out'], $res, "Header decoding for: " . $idx); } } + + /** + * Test format=flowed unfolding + */ + function test_format_flowed() + { + $raw = file_get_contents(TESTS_DIR . 'src/format-flowed-unfolded.txt'); + $flowed = file_get_contents(TESTS_DIR . 'src/format-flowed.txt'); + + $this->assertEquals($flowed, rcube_mime::format_flowed($raw, 80), "Test correct folding and space-stuffing"); + } + + /** + * Test format=flowed unfolding + */ + function test_unfold_flowed() + { + $flowed = file_get_contents(TESTS_DIR . 'src/format-flowed.txt'); + $unfolded = file_get_contents(TESTS_DIR . 'src/format-flowed-unfolded.txt'); + + $this->assertEquals($unfolded, rcube_mime::unfold_flowed($flowed), "Test correct unfolding of quoted lines"); + } } diff --git a/tests/src/format-flowed-unfolded.txt b/tests/src/format-flowed-unfolded.txt new file mode 100644 index 000000000..8245d59d4 --- /dev/null +++ b/tests/src/format-flowed-unfolded.txt @@ -0,0 +1,14 @@ +I'm replying on this with a very long line which is then wrapped and space-stuffed because the draft is saved as format=flowed. +From what's specified in RFC 2646 some lines need to be space-stuffed to avoid muning during transport. + +X + +On XX.YY.YYYY Y:YY, Somebody wrote: +> This part is a reply wihtout any flowing lines. rcube_mime::unfold_flowed() +> has to be careful with empty quoted lines because they might end with a +> space but still shouldn't be considered as flowed! +> +> The above empty line should persist after unfolding. +> xxxxxxxxxx. xxxx xxxxx xxxxx xxxx xx xx.xx. xxxxxx xxxxxxxxxxxx, xxxx xx +> +> ... and this one as well. diff --git a/tests/src/format-flowed.txt b/tests/src/format-flowed.txt new file mode 100644 index 000000000..522f829c6 --- /dev/null +++ b/tests/src/format-flowed.txt @@ -0,0 +1,16 @@ +I'm replying on this with a very long line which is then wrapped and +space-stuffed because the draft is saved as format=flowed. + From what's specified in RFC 2646 some lines need to be space-stuffed to +avoid muning during transport. + +X + +On XX.YY.YYYY Y:YY, Somebody wrote: +> This part is a reply wihtout any flowing lines. rcube_mime::unfold_flowed() +> has to be careful with empty quoted lines because they might end with a +> space but still shouldn't be considered as flowed! +> +> The above empty line should persist after unfolding. +> xxxxxxxxxx. xxxx xxxxx xxxxx xxxx xx xx.xx. xxxxxx xxxxxxxxxxxx, xxxx xx +> +> ... and this one as well. -- cgit v1.2.3 From aabd62828672c055205292c77f1463260f3b0c51 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 20 Jan 2013 11:12:24 +0100 Subject: Improve format=flowed text unfolding, add test for signature separator handling --- program/lib/Roundcube/rcube_mime.php | 18 +++++++++++------- tests/src/format-flowed-unfolded.txt | 3 +++ tests/src/format-flowed.txt | 3 +++ 3 files changed, 17 insertions(+), 7 deletions(-) (limited to 'tests/src') 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 -- cgit v1.2.3 From 7ebed11b05fe9b3659d18ed797572e7ffccad5a3 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 20 Jan 2013 11:57:46 +0100 Subject: More improvements to format=flowed handling + fix in wordwrap() used internally by format_flowed() --- program/lib/Roundcube/rcube_mime.php | 17 ++++++++++------- tests/src/format-flowed-unfolded.txt | 2 ++ tests/src/format-flowed.txt | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'tests/src') diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php index fd91ca979..e9d5cf148 100644 --- a/program/lib/Roundcube/rcube_mime.php +++ b/program/lib/Roundcube/rcube_mime.php @@ -477,9 +477,10 @@ class rcube_mime foreach ($text as $idx => $line) { if ($line[0] == '>') { - $len = strlen($line); - $line = preg_replace('/^>+ {0,1}/', '', $line); - $q = $len - strlen($line); + // remove quote chars, store level in $q + $line = preg_replace('/^>+/', '', $line, -1, $q); + // remove (optional) space-staffing + $line = preg_replace('/^ /', '', $line); // The same paragraph (We join current line with the previous one) when: // - the same level of quoting @@ -540,10 +541,12 @@ class rcube_mime foreach ($text as $idx => $line) { if ($line != '-- ') { - if ($line[0] == '>' && preg_match('/^(>+ {0,1})+/', $line, $regs)) { - $level = substr_count($regs[0], '>'); + if ($line[0] == '>') { + // remove quote chars, store level in $level + $line = preg_replace('/^>+/', '', $line, -1, $level); + // remove (optional) space-staffing + $line = preg_replace('/^ /', '', $line); $prefix = str_repeat('>', $level) . ' '; - $line = rtrim(substr($line, strlen($regs[0]))); $line = $prefix . self::wordwrap($line, $length - $level - 2, " \r\n$prefix", false, $charset); } else if ($line) { @@ -583,7 +586,7 @@ class rcube_mime while (count($para)) { $line = array_shift($para); if ($line[0] == '>') { - $string .= $line.$break; + $string .= $line . (count($para) ? $break : ''); continue; } diff --git a/tests/src/format-flowed-unfolded.txt b/tests/src/format-flowed-unfolded.txt index b422f981b..14e526be4 100644 --- a/tests/src/format-flowed-unfolded.txt +++ b/tests/src/format-flowed-unfolded.txt @@ -13,5 +13,7 @@ On XX.YY.YYYY Y:YY, Somebody wrote: > > ... and this one as well. +> > text + -- Sig diff --git a/tests/src/format-flowed.txt b/tests/src/format-flowed.txt index d3bd90eed..a390ffd11 100644 --- a/tests/src/format-flowed.txt +++ b/tests/src/format-flowed.txt @@ -15,5 +15,7 @@ On XX.YY.YYYY Y:YY, Somebody wrote: > > ... and this one as well. +> > text + -- Sig -- cgit v1.2.3 From d8270b66ccca4aef0db76bade89a398b1d33abe9 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 18 Mar 2013 19:51:32 +0100 Subject: Fix wrapping of text lines with the same length as specified length limit --- program/lib/Roundcube/rcube_mime.php | 7 ++++--- tests/src/format-flowed.txt | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'tests/src') diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php index 2f24a1bb3..d21e3b4d5 100644 --- a/program/lib/Roundcube/rcube_mime.php +++ b/program/lib/Roundcube/rcube_mime.php @@ -595,11 +595,12 @@ class rcube_mime while (count($list)) { $line = array_shift($list); $l = mb_strlen($line); - $newlen = $len + $l + ($len ? 1 : 0); + $space = $len ? 1 : 0; + $newlen = $len + $l + $space; if ($newlen <= $width) { - $string .= ($len ? ' ' : '').$line; - $len += (1 + $l); + $string .= ($space ? ' ' : '').$line; + $len += ($space + $l); } else { if ($l > $width) { diff --git a/tests/src/format-flowed.txt b/tests/src/format-flowed.txt index a390ffd11..359a41aec 100644 --- a/tests/src/format-flowed.txt +++ b/tests/src/format-flowed.txt @@ -1,7 +1,7 @@ I'm replying on this with a very long line which is then wrapped and space-stuffed because the draft is saved as format=flowed. - From what's specified in RFC 2646 some lines need to be space-stuffed to -avoid muning during transport. + From what's specified in RFC 2646 some lines need to be space-stuffed to avoid +muning during transport. X -- cgit v1.2.3