From f864495b7b7ab577e3aba5f06b34f92649de4a4b Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 01 Dec 2014 08:26:52 -0500
Subject: [PATCH] Fix import of multiple contact email addresses from Outlook-csv format (#1490169)
---
CHANGELOG | 1 +
program/localization/de_DE/csv2vcard.inc | 2 ++
program/localization/en_US/csv2vcard.inc | 2 ++
tests/src/Csv2vcard/outlook.csv | 2 ++
program/lib/Roundcube/rcube_csv2vcard.php | 16 +++++++++++-----
tests/Framework/Csv2vcard.php | 18 ++++++++++++++++++
tests/src/Csv2vcard/outlook.vcf | 7 +++++++
7 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index 09835e0..9fa2742 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================
+- Fix import of multiple contact email addresses from Outlook-csv format (#1490169)
- Fix drag-n-drop to folders expanded while dragging (#1490157)
- Fix import of multiple contact groups from Google-csv format (#1490159)
diff --git a/program/lib/Roundcube/rcube_csv2vcard.php b/program/lib/Roundcube/rcube_csv2vcard.php
index 8eff4d5..5f6ccd1 100644
--- a/program/lib/Roundcube/rcube_csv2vcard.php
+++ b/program/lib/Roundcube/rcube_csv2vcard.php
@@ -52,9 +52,9 @@
'company' => 'organization',
//'company_main_phone' => '',
'department' => 'department',
- //'email_2_address' => '', //@TODO
+ 'email_2_address' => 'email:other',
//'email_2_type' => '',
- //'email_3_address' => '', //@TODO
+ 'email_3_address' => 'email:other',
//'email_3_type' => '',
'email_address' => 'email:pref',
//'email_type' => '',
@@ -186,9 +186,9 @@
//'company_main_phone' => "Company Main Phone",
'department' => "Department",
//'directory_server' => "Directory Server",
- //'email_2_address' => "E-mail 2 Address",
+ 'email_2_address' => "E-mail 2 Address",
//'email_2_type' => "E-mail 2 Type",
- //'email_3_address' => "E-mail 3 Address",
+ 'email_3_address' => "E-mail 3 Address",
//'email_3_type' => "E-mail 3 Type",
'email_address' => "E-mail Address",
//'email_type' => "E-mail Type",
@@ -554,7 +554,13 @@
foreach ($this->map as $idx => $name) {
$value = $data[$idx];
if ($value !== null && $value !== '') {
- $contact[$name] = $value;
+ if (!empty($contact[$name])) {
+ $contact[$name] = (array) $contact[$name];
+ $contact[$name][] = $value;
+ }
+ else {
+ $contact[$name] = $value;
+ }
}
}
diff --git a/program/localization/de_DE/csv2vcard.inc b/program/localization/de_DE/csv2vcard.inc
index fa3317b..73341f7 100644
--- a/program/localization/de_DE/csv2vcard.inc
+++ b/program/localization/de_DE/csv2vcard.inc
@@ -33,6 +33,8 @@
$map['company'] = "Firma";
$map['department'] = "Abteilung";
$map['email_address'] = "E-Mail-Adresse";
+$map['email_2_address'] = "E-Mail 2: Adresse";
+$map['email_3_address'] = "E-Mail 3: Adresse";
$map['first_name'] = "Vorname";
$map['gender'] = "Geschlecht";
$map['home_city'] = "Ort privat";
diff --git a/program/localization/en_US/csv2vcard.inc b/program/localization/en_US/csv2vcard.inc
index e7b8679..a2a0c3f 100644
--- a/program/localization/en_US/csv2vcard.inc
+++ b/program/localization/en_US/csv2vcard.inc
@@ -40,6 +40,8 @@
$map['company'] = "Company";
$map['department'] = "Department";
$map['email_address'] = "E-mail Address";
+$map['email_2_address'] = "E-mail 2 Address";
+$map['email_3_address'] = "E-mail 3 Address";
$map['first_name'] = "First Name";
$map['gender'] = "Gender";
$map['home_city'] = "Home City";
diff --git a/tests/Framework/Csv2vcard.php b/tests/Framework/Csv2vcard.php
index 4f48dfa..34faf7d 100644
--- a/tests/Framework/Csv2vcard.php
+++ b/tests/Framework/Csv2vcard.php
@@ -73,4 +73,22 @@
$this->assertEquals($vcf_text, $vcard);
}
+
+ function test_import_outlook()
+ {
+ $csv_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/outlook.csv');
+ $vcf_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/outlook.vcf');
+
+ $csv = new rcube_csv2vcard;
+ $csv->import($csv_text);
+ $result = $csv->export();
+ $vcard = $result[0]->export(false);
+
+ $this->assertCount(1, $result);
+
+ $vcf_text = trim(str_replace("\r\n", "\n", $vcf_text));
+ $vcard = trim(str_replace("\r\n", "\n", $vcard));
+
+ $this->assertEquals($vcf_text, $vcard);
+ }
}
diff --git a/tests/src/Csv2vcard/outlook.csv b/tests/src/Csv2vcard/outlook.csv
new file mode 100644
index 0000000..ffa0828
--- /dev/null
+++ b/tests/src/Csv2vcard/outlook.csv
@@ -0,0 +1,2 @@
+E-mail Address,E-mail 2 Address,E-mail 3 Address
+test1@domain.tld,test2@domain.tld,test3@domain.tld
diff --git a/tests/src/Csv2vcard/outlook.vcf b/tests/src/Csv2vcard/outlook.vcf
new file mode 100644
index 0000000..ffd7e05
--- /dev/null
+++ b/tests/src/Csv2vcard/outlook.vcf
@@ -0,0 +1,7 @@
+BEGIN:VCARD
+VERSION:3.0
+FN:test1@domain.tld
+EMAIL;TYPE=INTERNET;TYPE=PREF:test1@domain.tld
+EMAIL;TYPE=INTERNET;TYPE=OTHER:test2@domain.tld
+EMAIL;TYPE=INTERNET;TYPE=OTHER:test3@domain.tld
+END:VCARD
--
Gitblit v1.9.1