summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Kolab/CardDAV/ContactsBackend.php31
-rw-r--r--lib/Kolab/CardDAV/Plugin.php1
2 files changed, 24 insertions, 8 deletions
diff --git a/lib/Kolab/CardDAV/ContactsBackend.php b/lib/Kolab/CardDAV/ContactsBackend.php
index 7150f4e..97242a0 100644
--- a/lib/Kolab/CardDAV/ContactsBackend.php
+++ b/lib/Kolab/CardDAV/ContactsBackend.php
@@ -408,9 +408,14 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
private function parse_vcard($cardData, $uid)
{
try {
- VObject\Property::$classMap['REV'] = 'Sabre\\VObject\\Property\\DateTime';
-
- $vobject = VObject\Reader::read($cardData, VObject\Reader::OPTION_FORGIVING | VObject\Reader::OPTION_IGNORE_INVALID_LINES);
+ // use already parsed object
+ if (Plugin::$parsed_vcard && Plugin::$parsed_vcard->UID == $uid) {
+ $vobject = Plugin::$parsed_vcard;
+ }
+ else {
+ VObject\Property::$classMap['REV'] = 'Sabre\\VObject\\Property\\DateTime';
+ $vobject = VObject\Reader::read($cardData, VObject\Reader::OPTION_FORGIVING | VObject\Reader::OPTION_IGNORE_INVALID_LINES);
+ }
if ($vobject && $vobject->name == 'VCARD') {
$contact = $this->_to_array($vobject);
@@ -550,11 +555,18 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
private function _to_array($vc)
{
$contact = array(
- 'uid' => strval($vc->UID),
- 'name' => strval($vc->FN),
- 'changed' => $vc->REV ? $vc->REV->getDateTime() : null,
+ 'uid' => strval($vc->UID),
+ 'name' => strval($vc->FN),
);
+ if ($vc->REV) {
+ try { $contact['changed'] = $vc->REV->getDateTime(); }
+ catch (\Exception $e) {
+ try { $contact['changed'] = new \DateTime(strval($vc->REV)); }
+ catch (\Exception $e) { }
+ }
+ }
+
$phonetypemap = array_flip($this->phonetypes);
// map attributes to internal fields
@@ -648,8 +660,8 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
case 'IMPP':
$type = strtolower((string)$prop->offsetGet('X-SERVICE-TYPE'));
- $protocol = $type ? ($this->improtocols[$type] ?: $type) . ':' : '';
- $contact['im'][] = $protocol . $prop->value;
+ $protocol = $type && !preg_match('/^[a-z]+:/i', $prop->value) ? ($this->improtocols[$type] ?: $type) . ':' : '';
+ $contact['im'][] = $protocol . urldecode($prop->value);
break;
case 'PHOTO':
@@ -670,6 +682,9 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
}
}
+ if (is_array($contact['im']))
+ $contact['im'] = array_unique($contact['im']);
+
return $contact;
}
diff --git a/lib/Kolab/CardDAV/Plugin.php b/lib/Kolab/CardDAV/Plugin.php
index 6268989..5c39c07 100644
--- a/lib/Kolab/CardDAV/Plugin.php
+++ b/lib/Kolab/CardDAV/Plugin.php
@@ -56,6 +56,7 @@ class Plugin extends CardDAV\Plugin
$data = DAV\StringUtil::ensureUTF8($data);
try {
+ VObject\Property::$classMap['REV'] = 'Sabre\\VObject\\Property\\DateTime';
$vobj = VObject\Reader::read($data, VObject\Reader::OPTION_FORGIVING | VObject\Reader::OPTION_IGNORE_INVALID_LINES);
if ($vobj->name == 'VCARD')