summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2013-09-09 16:52:01 (GMT)
committerThomas Bruederli <thomas@roundcube.net>2013-09-09 16:52:01 (GMT)
commit9e666e10d85026ba9c1065b3098bdb6adc15b008 (patch)
tree1c752deaa74d753239c2b46e7ff8ba5fed64edae
parent049941ee190d83d3975aa883e6e7dc88c34be736 (diff)
downloadiRony-9e666e10d85026ba9c1065b3098bdb6adc15b008.tar.gz
Fix birthday and anniversary sync in CardDAV (#2142).
Respect Apple's proprietary X-ABDATE + X-ABLABEL fields for anniversary.
-rw-r--r--lib/Kolab/CardDAV/ContactsBackend.php39
1 files changed, 36 insertions, 3 deletions
diff --git a/lib/Kolab/CardDAV/ContactsBackend.php b/lib/Kolab/CardDAV/ContactsBackend.php
index 41e1ca3..458b3ed 100644
--- a/lib/Kolab/CardDAV/ContactsBackend.php
+++ b/lib/Kolab/CardDAV/ContactsBackend.php
@@ -686,12 +686,24 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
if (!empty($contact['gender']))
$vc->add('SEX', $contact['gender']);
+ // convert date cols to DateTime objects
+ foreach (array('birthday','anniversary') as $key) {
+ if (!empty($contact[$key]) && !$contact[$key] instanceof \DateTime) {
+ try {
+ $contact[$key] = new \DateTime('@' . \rcube_utils::strtotime($contact[$key]));
+ }
+ catch (\Exception $e) {
+ $contact[$key] = null;
+ }
+ }
+ }
+
if (!empty($contact['birthday']) && $contact['birthday'] instanceof \DateTime) {
// FIXME: Date values are ignored by Thunderbird
$contact['birthday']->_dateonly = true;
$vc->add(VObjectUtils::datetime_prop('BDAY', $contact['birthday'], false));
}
- if (!empty($contact['anniversary']) && $contact['birthday'] instanceof \DateTime) {
+ if (!empty($contact['anniversary']) && $contact['anniversary'] instanceof \DateTime) {
$contact['anniversary']->_dateonly = true;
$vc->add(VObjectUtils::datetime_prop('ANNIVERSARY', $contact['anniversary'], false));
}
@@ -715,6 +727,13 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
$vc->add($prop[0], $prop[1]);
}
+ // send anniversary field as itemN.X-ABDATE
+ if ($this->useragent == 'macosx' && !empty($contact['anniversary'])) {
+ $vc->add(VObjectUtils::datetime_prop('iRony.X-ABDATE', $contact['anniversary'], false));
+ $vc->add('iRony.X-ABLabel', '_$!<Anniversary>!$_');
+ unset($vc->ANNIVERSARY);
+ }
+
if (!empty($contact['changed']))
$vc->add(VObjectUtils::datetime_prop('REV', $contact['changed'], true));
@@ -743,6 +762,18 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
}
}
+ // map Apple proprietary anniversary field to regular field
+ foreach ($vc->select('X-ABDATE') as $prop) {
+ $labelkey = $prop->group ? $prop->group . '.X-ABLABEL' : 'X-ABLABEL';
+ $labels = $vc->select($labelkey);
+ if (!empty($labels) && ($label = reset($labels)) && strtolower(trim($label->value, '_$!<>')) == 'anniversary') {
+ $prop->group = null;
+ $prop->name = 'ANNIVERSARY';
+ unset($vc->{$labelkey});
+ break;
+ }
+ }
+
$phonetypemap = array_flip($this->phonetypes);
// map attributes to internal fields
@@ -870,8 +901,10 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
case 'CUSTOM3':
case 'CUSTOM4':
default:
- if (substr($prop->name, 0, 2) == 'X-' || substr($prop->name, 0, 6) == 'CUSTOM')
- $contact['x-custom'][] = array($prop->name, strval($prop->value));
+ if (substr($prop->name, 0, 2) == 'X-' || substr($prop->name, 0, 6) == 'CUSTOM') {
+ $prefix = $prop->group ? $prop->group . '.' : '';
+ $contact['x-custom'][] = array($prefix . $prop->name, strval($prop->value));
+ }
break;
}
}