From b2ea1a7d059fb054645f84eec6d08d7c26649a9e Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 7 Oct 2011 06:02:30 +0000 Subject: [PATCH] new method groupdav_principals::url2uid to convert a principal url to a calendar uid, fixes emclient uses urn:uuid urls in outbox posts to get freebusy --- calendar/inc/class.calendar_ical.inc.php | 28 ++-------- .../inc/class.groupdav_principals.inc.php | 56 +++++++++++++++++++ 2 files changed, 60 insertions(+), 24 deletions(-) diff --git a/calendar/inc/class.calendar_ical.inc.php b/calendar/inc/class.calendar_ical.inc.php index d9a1a7d5dc..a39cc0db1b 100644 --- a/calendar/inc/class.calendar_ical.inc.php +++ b/calendar/inc/class.calendar_ical.inc.php @@ -2236,7 +2236,7 @@ class calendar_ical extends calendar_boupdate * @param array $component VEVENT * @param string $version vCal version (1.0/2.0) * @param array $supportedFields supported fields of the device - * @param string $principalURL='' Used for CalDAV imports + * @param string $principalURL='' Used for CalDAV imports, no longer used in favor of groupdav_principals::url2uid() * @param string $check_component='Horde_iCalendar_vevent' * * @return array|boolean event on success, false on failure @@ -2705,29 +2705,6 @@ class calendar_ical extends calendar_boupdate { $role = $attributes['params']['ROLE']; } - // try pricipal url from CalDAV - if (strpos($attributes['value'], 'http') === 0) - { - if (!empty($principalURL) && strstr($attributes['value'], $principalURL) !== false) - { - $uid = $this->user; - if ($this->log) - { - error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ - . "(): Found myself: '$uid'\n",3,$this->logfile); - } - } - else - { - if ($this->log) - { - error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ - . '(): Unknown URI: ' . $attributes['value'] - . "\n",3,$this->logfile); - } - $attributes['value'] = ''; - } - } // parse email and cn from attendee if (preg_match('/MAILTO:([@.a-z0-9_-]+)|MAILTO:"?([.a-z0-9_ -]*)"?[ ]*<([@.a-z0-9_-]*)>/i', $attributes['value'],$matches)) @@ -2767,6 +2744,9 @@ class calendar_ical extends calendar_boupdate // we use the current user $uid = $this->user; } + // check principal url from CalDAV here after X-EGROUPWARE-UID and to get optional X-EGROUPWARE-QUANTITY + if (!$uid) $uid = groupdav_principals::url2uid($attributes['value']); + // try to find an email address if (!$uid && $email && ($uid = $GLOBALS['egw']->accounts->name2id($email, 'account_email'))) { diff --git a/phpgwapi/inc/class.groupdav_principals.inc.php b/phpgwapi/inc/class.groupdav_principals.inc.php index 011310d909..4c2483c048 100644 --- a/phpgwapi/inc/class.groupdav_principals.inc.php +++ b/phpgwapi/inc/class.groupdav_principals.inc.php @@ -722,6 +722,62 @@ class groupdav_principals extends groupdav_handler )); } + /** + * Convert CalDAV principal URL to a calendar uid + * + * @param string $url + * @param string|array $only_type=null allowed types, return false for other (valid) types, eg. "users", "groups" or "resources", default all + * @return int|string|boolean integer account_id, string calendar uid or false if not a supported uid + */ + static public function url2uid($url, $only_type=null) + { + if (!$only_type) $only_type = array('accounts', 'groups', 'resources', 'mailto'); + + if ($url[0] == '/') + { + $schema = 'http'; + } + else + { + list($schema, $rest) = explode(':', $url, 2); + } + if (empty($rest)) return false; + + switch(strtolower($schema)) + { + case 'http': + case 'https': + list(,$rest) = explode($GLOBALS['egw_info']['server']['webserver_url'].'/groupdav.php/principals/', $url); + list($type, $name) = explode('/', $rest); + $uid = $GLOBALS['egw']->accounts->name2id($name, 'account_lid', $type[0]); // u=users, g=groups + break; + + case 'mailto': + if (($uid = $GLOBALS['egw']->accounts->name2id($rest, 'account_email'))) + { + $type = $uid > 0 ? 'accounts' : 'groups'; + break; + } + // todo: contacts (uid "c" + break; + + case 'urn': + list($urn_type, $name) = explode(':', $rest, 2); + if ($urn_type === 'uuid' && ($uid = $GLOBALS['egw']->accounts->name2id($name, 'account_lid'))) + { + $type = $uid > 0 ? 'accounts' : 'groups'; + break; + } + // todo: resources + break; + + default: + error_log(__METHOD__."('$url') unsupported principal type '$schema'!"); + return false; + } + return $uid && in_array($type, $only_type) ? $uid : false; + } + /** * Add collection of a single group to a collection *