From 38c19a20641234a9a3a9a1e77e8f1202163ed13d Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 1 May 2013 11:19:47 +0200 Subject: Fix csv2vcard test --- tests/src/Csv2vcard/tb_plain.csv | 2 +- tests/src/Csv2vcard/tb_plain.vcf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/src/Csv2vcard/tb_plain.csv b/tests/src/Csv2vcard/tb_plain.csv index 94ea766c0..4c4af14ca 100644 --- a/tests/src/Csv2vcard/tb_plain.csv +++ b/tests/src/Csv2vcard/tb_plain.csv @@ -1,2 +1,2 @@ First Name,Last Name,Display Name,Nickname,Primary Email,Secondary Email,Screen Name,Work Phone,Home Phone,Fax Number,Pager Number,Mobile Number,Home Address,Home Address 2,Home City,Home State,Home ZipCode,Home Country,Work Address,Work Address 2,Work City,Work State,Work ZipCode,Work Country,Job Title,Department,Organization,Web Page 1,Web Page 2,Birth Year,Birth Month,Birth Day,Custom 1,Custom 2,Custom 3,Custom 4,Notes, -Firstname,Lastname,Displayname,Nick,test@domain.tld,next@domain.tld,,phone work,phone home,fax,pager,mobile,Priv address,,City,region,xx-xxx,USA,Addr work,,city,region,33-333,Poland,title,department,Organization,http://page.com,http://webpage.tld,1970,11,15,,,,,, +Firstname,Lastname,Displayname,Nick,test@domain.tld,next@domain.tld,,phone work,phone home,fax,pager,mobile,Priv address,,City,region,xx-xxx,USA,Addr work,,Wcity,Wstate,33-333,Poland,title,department,Organization,http://page.com,http://webpage.tld,1970,11,15,,,,,, diff --git a/tests/src/Csv2vcard/tb_plain.vcf b/tests/src/Csv2vcard/tb_plain.vcf index b001c3924..2aa91adf8 100644 --- a/tests/src/Csv2vcard/tb_plain.vcf +++ b/tests/src/Csv2vcard/tb_plain.vcf @@ -16,5 +16,5 @@ 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 +ADR;TYPE=work:;;Addr work;Wcity;Wstate;33-333;Poland END:VCARD -- cgit v1.2.3 From 2ce01932fef0abfc6d76dc134024c879a72f9cb7 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 3 May 2013 08:24:26 +0200 Subject: Fix another text wrap issue (added test case) --- program/lib/Roundcube/rcube_mime.php | 4 ++-- tests/Framework/Mime.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php index 0a4bfbddb..53724cbba 100644 --- a/program/lib/Roundcube/rcube_mime.php +++ b/program/lib/Roundcube/rcube_mime.php @@ -659,8 +659,8 @@ class rcube_mime $cutLength = $spacePos + 1; } else { - $subString = $string; - $cutLength = null; + $subString = $substr_func($string, 0, $breakPos, $charset); + $cutLength = $breakPos + 1; } } else { diff --git a/tests/Framework/Mime.php b/tests/Framework/Mime.php index 61123dd85..3035ba062 100644 --- a/tests/Framework/Mime.php +++ b/tests/Framework/Mime.php @@ -185,6 +185,10 @@ class Framework_Mime extends PHPUnit_Framework_TestCase array("----------------------------------------------------------------------------------------\nabc def123456789012345", 76), "----------------------------------------------------------------------------------------\nabc def123456789012345", ), + array( + array("-------\nabc def", 5), + "-------\nabc\ndef", + ), ); foreach ($samples as $sample) { -- cgit v1.2.3 From b92ec5c86d2f85c43705ada6fbcb8912f48907f0 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 3 May 2013 09:26:13 +0200 Subject: Fix bug where multi-level quoting was replaced with one-level quoted text after format=flowed wrapping --- program/lib/Roundcube/rcube_mime.php | 14 ++++++++------ tests/src/format-flowed-unfolded.txt | 2 +- tests/src/format-flowed.txt | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php index 53724cbba..63549fbec 100644 --- a/program/lib/Roundcube/rcube_mime.php +++ b/program/lib/Roundcube/rcube_mime.php @@ -478,9 +478,10 @@ class rcube_mime $q_level = 0; foreach ($text as $idx => $line) { - if ($line[0] == '>') { - // remove quote chars, store level in $q - $line = preg_replace('/^>+/', '', $line, -1, $q); + if (preg_match('/^(>+)/', $line, $m)) { + // remove quote chars + $q = strlen($m[1]); + $line = preg_replace('/^>+/', '', $line); // remove (optional) space-staffing $line = preg_replace('/^ /', '', $line); @@ -543,9 +544,10 @@ class rcube_mime foreach ($text as $idx => $line) { if ($line != '-- ') { - if ($line[0] == '>') { - // remove quote chars, store level in $level - $line = preg_replace('/^>+/', '', $line, -1, $level); + if (preg_match('/^(>+)/', $line, $m)) { + // remove quote chars + $level = strlen($m[1]); + $line = preg_replace('/^>+/', '', $line); // remove (optional) space-staffing and spaces before the line end $line = preg_replace('/(^ | +$)/', '', $line); $prefix = str_repeat('>', $level) . ' '; diff --git a/tests/src/format-flowed-unfolded.txt b/tests/src/format-flowed-unfolded.txt index 14e526be4..0af9b7130 100644 --- a/tests/src/format-flowed-unfolded.txt +++ b/tests/src/format-flowed-unfolded.txt @@ -5,7 +5,7 @@ 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 +>> 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. diff --git a/tests/src/format-flowed.txt b/tests/src/format-flowed.txt index 359a41aec..da36064e0 100644 --- a/tests/src/format-flowed.txt +++ b/tests/src/format-flowed.txt @@ -7,7 +7,7 @@ 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 +>> 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. -- cgit v1.2.3 From 3a0dc87856cc0c2a47649e58e930621506e64cbf Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 5 May 2013 16:38:58 +0200 Subject: Fix backslash character handling on vCard import (#1489085) --- CHANGELOG | 1 + program/lib/Roundcube/rcube_vcard.php | 23 ++++++++++++++++++++++- tests/Framework/VCard.php | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/CHANGELOG b/CHANGELOG index 56d5d7b72..c97df8c96 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Fix backslash character handling on vCard import (#1489085) - Fix csv import from Thunderbird with French localization (#1489059) - Fix messages list focus issue in Opera and Webkit (#1489058) - Make PHP code eval() free, use create_function() diff --git a/program/lib/Roundcube/rcube_vcard.php b/program/lib/Roundcube/rcube_vcard.php index 54bb9521d..cc3a35850 100644 --- a/program/lib/Roundcube/rcube_vcard.php +++ b/program/lib/Roundcube/rcube_vcard.php @@ -784,9 +784,30 @@ class rcube_vcard } return $result; } + + $s = strtr($s, $rep2); + } + + // some implementations (GMail) use non-standard backslash before colon (#1489085) + // we will handle properly any backslashed character - removing dummy backslahes + // return strtr($s, array("\r" => '', '\\\\' => '\\', '\n' => "\n", '\N' => "\n", '\,' => ',', '\;' => ';')); + + $s = str_replace("\r", '', $s); + $pos = 0; + + while (($pos = strpos($s, '\\', $pos)) !== false) { + $next = substr($s, $pos + 1, 1); + if ($next == 'n' || $next == 'N') { + $s = substr_replace($s, "\n", $pos, 2); + } + else { + $s = substr_replace($s, '', $pos, 1); + } + + $pos += 1; } - return strtr($s, array("\r" => '', '\\\\' => '\\', '\n' => "\n", '\N' => "\n", '\,' => ',', '\;' => ';')); + return $s; } /** diff --git a/tests/Framework/VCard.php b/tests/Framework/VCard.php index 15aa5d816..3353b5b13 100644 --- a/tests/Framework/VCard.php +++ b/tests/Framework/VCard.php @@ -65,6 +65,20 @@ class Framework_VCard extends PHPUnit_Framework_TestCase $this->assertEquals("prefix", $vcard['prefix'], "Decode backslash character"); } + /** + * Backslash parsing test (#1489085) + */ + function test_parse_five() + { + $vcard = "BEGIN:VCARD\nVERSION:3.0\nN:last\\\\\\a;fir\\nst\nURL:http\\://domain.tld\nEND:VCARD"; + $vcard = new rcube_vcard($vcard, null); + $vcard = $vcard->get_assoc(); + + $this->assertEquals("last\\a", $vcard['surname'], "Decode dummy backslash character"); + $this->assertEquals("fir\nst", $vcard['firstname'], "Decode backslash character"); + $this->assertEquals("http://domain.tld", $vcard['website:other'][0], "Decode dummy backslash character"); + } + function test_import() { $input = file_get_contents($this->_srcpath('apple.vcf')); -- cgit v1.2.3