summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube/rcube_csv2vcard.php
diff options
context:
space:
mode:
authorAndy Wermke <andy@dev.next-step-software.com>2013-04-04 16:10:23 +0200
committerAndy Wermke <andy@dev.next-step-software.com>2013-04-04 16:10:23 +0200
commit92cd7f34b07e86062f2c024039e3309768b48ce6 (patch)
tree63b9f39280ebcab80742d9f2b4db6a139c1791e1 /program/lib/Roundcube/rcube_csv2vcard.php
parent029d18f13bcf01aa2f1f08dbdfc6400c081bf7cb (diff)
parent443b92a7ee19e321b350750240e0fc54ec5be357 (diff)
Merge branch 'master' of https://github.com/roundcube/roundcubemail
Diffstat (limited to 'program/lib/Roundcube/rcube_csv2vcard.php')
-rw-r--r--program/lib/Roundcube/rcube_csv2vcard.php54
1 files changed, 45 insertions, 9 deletions
diff --git a/program/lib/Roundcube/rcube_csv2vcard.php b/program/lib/Roundcube/rcube_csv2vcard.php
index 850c0c4c3..0d3276b84 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 |
| |
@@ -126,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',
);
/**
@@ -273,13 +277,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;
}
@@ -307,6 +305,35 @@ class rcube_csv2vcard
}
/**
+ * 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
*/
protected function parse_header($elements)
@@ -369,6 +396,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) {