From d2534c63f2c0b640a39fce2a71b14a5dcda6e7fd Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 18 Dec 2012 09:07:00 +0100 Subject: Cleanup, remove file paths from doc --- program/lib/Roundcube/rcube_csv2vcard.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'program/lib/Roundcube/rcube_csv2vcard.php') diff --git a/program/lib/Roundcube/rcube_csv2vcard.php b/program/lib/Roundcube/rcube_csv2vcard.php index 850c0c4c3..9c28a3b49 100644 --- a/program/lib/Roundcube/rcube_csv2vcard.php +++ b/program/lib/Roundcube/rcube_csv2vcard.php @@ -2,8 +2,6 @@ /* +-----------------------------------------------------------------------+ - | program/include/rcube_csv2vcard.php | - | | | This file is part of the Roundcube Webmail client | | Copyright (C) 2008-2012, The Roundcube Dev Team | | | -- cgit v1.2.3 From 745d8697ba6ff7b35bda24d9c2319a9ed848152c Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 7 Jan 2013 15:06:09 +0100 Subject: Fix quoted data handling in CSV files (#1488899) --- program/lib/Roundcube/rcube_csv2vcard.php | 37 +++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'program/lib/Roundcube/rcube_csv2vcard.php') diff --git a/program/lib/Roundcube/rcube_csv2vcard.php b/program/lib/Roundcube/rcube_csv2vcard.php index 9c28a3b49..f94a7aac7 100644 --- a/program/lib/Roundcube/rcube_csv2vcard.php +++ b/program/lib/Roundcube/rcube_csv2vcard.php @@ -271,13 +271,7 @@ class rcube_csv2vcard // Parse file foreach (preg_split("/[\r\n]+/", $csv) as $i => $line) { - $line = trim($line); - if (empty($line)) { - continue; - } - - $elements = rcube_utils::explode_quoted_string(',', $line); - + $elements = $this->parse_line($line); if (empty($elements)) { continue; } @@ -304,6 +298,35 @@ class rcube_csv2vcard return $this->vcards; } + /** + * Parse CSV file line + */ + protected function parse_line($line) + { + $line = trim($line); + if (empty($line)) { + return null; + } + + $fields = rcube_utils::explode_quoted_string(',', $line); + + // remove quotes if needed + if (!empty($fields)) { + foreach ($fields as $idx => $value) { + if (($len = strlen($value)) > 1 && $value[0] == '"' && $value[$len-1] == '"') { + // remove surrounding quotes + $value = substr($value, 1, -1); + // replace doubled quotes inside the string with single quote + $value = str_replace('""', '"', $value); + + $fields[$idx] = $value; + } + } + } + + return $fields; + } + /** * Parse CSV header line, detect fields mapping */ -- cgit v1.2.3 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) --- program/lib/Roundcube/rcube_csv2vcard.php | 9 +++++++++ tests/Framework/Csv2vcard.php | 1 + tests/src/Csv2vcard/tb_plain.vcf | 2 ++ 3 files changed, 12 insertions(+) (limited to 'program/lib/Roundcube/rcube_csv2vcard.php') diff --git a/program/lib/Roundcube/rcube_csv2vcard.php b/program/lib/Roundcube/rcube_csv2vcard.php index f94a7aac7..e8202c6d4 100644 --- a/program/lib/Roundcube/rcube_csv2vcard.php +++ b/program/lib/Roundcube/rcube_csv2vcard.php @@ -390,6 +390,15 @@ class rcube_csv2vcard } } + // Convert address(es) to rcube_vcard data + foreach ($contact as $idx => $value) { + $name = explode(':', $idx); + if (in_array($name[0], array('street', 'locality', 'region', 'zipcode', 'country'))) { + $contact['address:'.$name[1]][$name[0]] = $value; + unset($contact[$idx]); + } + } + // Create vcard object $vcard = new rcube_vcard(); foreach ($contact as $name => $value) { diff --git a/tests/Framework/Csv2vcard.php b/tests/Framework/Csv2vcard.php index 6fa3e163c..f460c42af 100644 --- a/tests/Framework/Csv2vcard.php +++ b/tests/Framework/Csv2vcard.php @@ -31,6 +31,7 @@ class Framework_Csv2vcard extends PHPUnit_Framework_TestCase $vcf_text = trim(str_replace("\r\n", "\n", $vcf_text)); $vcard = trim(str_replace("\r\n", "\n", $vcard)); +echo $vcard; $this->assertEquals($vcf_text, $vcard); } 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 c59ef9542a93a5cbacd99fe3dcfc0975bc749a12 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 11 Jan 2013 09:02:45 +0100 Subject: Support more Thunderbird CSV fields, added zh_TW localization for csv2vcard map (#1488901) --- program/lib/Roundcube/rcube_csv2vcard.php | 6 ++ program/localization/zh_TW/csv2vcard.inc | 99 +++++++++++++++++++++++++++++++ tests/Framework/Csv2vcard.php | 2 +- 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 program/localization/zh_TW/csv2vcard.inc (limited to 'program/lib/Roundcube/rcube_csv2vcard.php') diff --git a/program/lib/Roundcube/rcube_csv2vcard.php b/program/lib/Roundcube/rcube_csv2vcard.php index e8202c6d4..0d3276b84 100644 --- a/program/lib/Roundcube/rcube_csv2vcard.php +++ b/program/lib/Roundcube/rcube_csv2vcard.php @@ -124,6 +124,12 @@ class rcube_csv2vcard //'work_address_2' => '', 'work_country' => 'country:work', 'work_zipcode' => 'zipcode:work', + 'last' => 'surname', + 'first' => 'firstname', + 'work_city' => 'locality:work', + 'work_state' => 'region:work', + 'home_city_short' => 'locality:home', + 'home_state_short' => 'region:home', ); /** diff --git a/program/localization/zh_TW/csv2vcard.inc b/program/localization/zh_TW/csv2vcard.inc new file mode 100644 index 000000000..9fcacc818 --- /dev/null +++ b/program/localization/zh_TW/csv2vcard.inc @@ -0,0 +1,99 @@ + | + +-----------------------------------------------------------------------+ +*/ + +// This is a list of CSV column names specified in CSV file header +// These must be original texts used in Outlook/Thunderbird exported csv files +// Encoding UTF-8 + +$map = array(); + +// MS Outlook 2010 +$map['anniversary'] = "紀念日"; +$map['assistants_name'] = "助理"; +$map['assistants_phone'] = "助理電話"; +$map['birthday'] = "生日"; +$map['business_city'] = "商務 - 市/鎮"; +$map['business_countryregion'] = "商務 - 國家/地區"; +$map['business_fax'] = "商務傳真"; +$map['business_phone'] = "商務電話"; +$map['business_phone_2'] = "商務電話 2"; +$map['business_postal_code'] = "商務 - 郵遞區號"; +$map['business_state'] = "商務 - 縣市"; +$map['business_street'] = "商務 - 街"; +$map['car_phone'] = "汽車電話"; +$map['categories'] = "類別"; +$map['company'] = "公司"; +$map['department'] = "部門"; +$map['email_address'] = "電子郵件地址"; +$map['first_name'] = "名字"; +$map['gender'] = "性別"; +$map['home_city'] = "住家 - 市/鎮"; +$map['home_countryregion'] = "住家 - 國家/地區"; +$map['home_fax'] = "住家傳真"; +$map['home_phone'] = "住家電話"; +$map['home_phone_2'] = "住家電話 2"; +$map['home_postal_code'] = "住家 - 郵遞區號"; +$map['home_state'] = "住家 - 縣/市"; +$map['home_street'] = "住家 - 街"; +$map['job_title'] = "職稱"; +$map['last_name'] = "姓氏"; +$map['managers_name'] = "主管名稱"; +$map['middle_name'] = "中間名"; +$map['mobile_phone'] = "行動電話"; +$map['notes'] = "記事"; +$map['other_city'] = "其他 - 市/鎮"; +$map['other_countryregion'] = "其他 - 國家/地區"; +$map['other_fax'] = "其他傳真"; +$map['other_phone'] = "其他電話"; +$map['other_postal_code'] = "其他 - 郵遞區號"; +$map['other_state'] = "其他 - 縣/市"; +$map['other_street'] = "其他 - 街"; +$map['pager'] = "呼叫器"; +$map['primary_phone'] = "代表電話"; +$map['spouse'] = "配偶"; +$map['suffix'] = "稱謂"; +$map['title'] = "頭銜"; +$map['web_page'] = "網頁"; + +// Thunderbird +$map['last'] = "姓"; +$map['first'] = "名"; +$map['birth_day'] = "生日 (日)"; +$map['birth_month'] = "生日 (月)"; +$map['birth_year'] = "生日 (年)"; +$map['display_name'] = "顯示名稱"; +$map['fax_number'] = "傳真號碼"; +$map['home_address'] = "住家住址"; +$map['home_country'] = "居住國家"; +$map['home_zipcode'] = "住址郵遞區號"; +$map['mobile_number'] = "手機號碼"; +$map['nickname'] = "暱稱"; +$map['organization'] = "Organization"; +$map['pager_number'] = "呼叫器號碼"; +$map['primary_email'] = "主要 Email"; +$map['secondary_email'] = "次要 Email"; +$map['web_page_1'] = "網頁 1"; +$map['web_page_2'] = "網頁 2"; +$map['work_phone'] = "商務電話"; +$map['work_address'] = "商務地址"; +$map['work_country'] = "商務國家"; +$map['work_zipcode'] = "商務郵遞區號"; +$map['work_city'] = "商務市鎮"; +$map['work_state'] = "商務縣市"; +$map['home_city_short'] = "居住市鎮"; +$map['home_state_short'] = "居住縣市"; diff --git a/tests/Framework/Csv2vcard.php b/tests/Framework/Csv2vcard.php index f460c42af..5d52efc58 100644 --- a/tests/Framework/Csv2vcard.php +++ b/tests/Framework/Csv2vcard.php @@ -31,7 +31,7 @@ class Framework_Csv2vcard extends PHPUnit_Framework_TestCase $vcf_text = trim(str_replace("\r\n", "\n", $vcf_text)); $vcard = trim(str_replace("\r\n", "\n", $vcard)); -echo $vcard; + $this->assertEquals($vcf_text, $vcard); } -- cgit v1.2.3