Send fully qualified mailbox identifiers in Bonnie API calls

This commit is contained in:
Thomas Bruederli 2014-07-30 09:26:29 +02:00
parent 93fc135e9c
commit 43cf285391
4 changed files with 60 additions and 23 deletions

View file

@ -1359,9 +1359,9 @@ class kolab_driver extends calendar_driver
return false; return false;
} }
list($uid, $folder) = $this->_resolve_event_identity($event); list($uid, $mailbox) = $this->_resolve_event_identity($event);
$result = $this->bonnie_api->changelog('event', $uid, $folder); $result = $this->bonnie_api->changelog('event', $uid, $mailbox);
if (is_array($result) && $result['uid'] == $uid) { if (is_array($result) && $result['uid'] == $uid) {
return $result['changes']; return $result['changes'];
} }
@ -1384,10 +1384,10 @@ class kolab_driver extends calendar_driver
return false; return false;
} }
list($uid, $folder) = $this->_resolve_event_identity($event); list($uid, $mailbox) = $this->_resolve_event_identity($event);
// call Bonnie API // call Bonnie API
$result = $this->bonnie_api->diff('event', $uid, $rev, $folder); $result = $this->bonnie_api->diff('event', $uid, $rev, $mailbox);
if (is_array($result) && $result['uid'] == $uid) { if (is_array($result) && $result['uid'] == $uid) {
$result['rev'] = $rev; $result['rev'] = $rev;
@ -1502,23 +1502,17 @@ class kolab_driver extends calendar_driver
} }
$calid = $event['calendar']; $calid = $event['calendar'];
list($uid, $folder) = $this->_resolve_event_identity($event); list($uid, $mailbox) = $this->_resolve_event_identity($event);
// call Bonnie API // call Bonnie API
$result = $this->bonnie_api->get('event', $uid, $rev, $folder); $result = $this->bonnie_api->get('event', $uid, $rev, $mailbox);
if (is_array($result) && $result['uid'] == $uid && !empty($result['xml'])) { if (is_array($result) && $result['uid'] == $uid && !empty($result['xml'])) {
$format = kolab_format::factory('event'); $format = kolab_format::factory('event');
$format->load($result['xml']); $format->load($result['xml']);
$event = $format->to_array(); $event = $format->to_array();
if ($format->is_valid()) { if ($format->is_valid()) {
if ($result['folder'] && ($cal = $this->get_calendar(kolab_storage::id_encode($result['folder'])))) { $event['calendar'] = $calid;
$event['calendar'] = $cal->id;
}
else {
$event['calendar'] = $calid;
}
$event['rev'] = $result['rev']; $event['rev'] = $result['rev'];
return self::to_rcube_event($event); return self::to_rcube_event($event);
} }
@ -1534,11 +1528,11 @@ class kolab_driver extends calendar_driver
*/ */
private function _resolve_event_identity($event) private function _resolve_event_identity($event)
{ {
$folder = null; $mailbox = null;
if (is_array($event)) { if (is_array($event)) {
$uid = $event['id'] ?: $event['uid']; $uid = $event['id'] ?: $event['uid'];
if ($cal = $this->get_calendar($event['calendar']) && !($cal instanceof kolab_invitation_calendar)) { if (($cal = $this->get_calendar($event['calendar'])) && !($cal instanceof kolab_invitation_calendar)) {
$folder = $cal->name; $mailbox = $cal->get_mailbox_id();
} }
} }
else { else {
@ -1550,7 +1544,7 @@ class kolab_driver extends calendar_driver
if (!in_array($uid, $demo_uids)) if (!in_array($uid, $demo_uids))
$uid = reset($demo_uids); $uid = reset($demo_uids);
return array($uid, $folder); return array($uid, $mailbox);
} }
/** /**

View file

@ -114,6 +114,17 @@ class kolab_invitation_calendar
return $this->get_name(); return $this->get_name();
} }
/**
* Getter for the Cyrus mailbox identifier corresponding to this folder
*
* @return string Mailbox ID
*/
public function get_mailbox_id()
{
// this is a virtual collection and has no concrete mailbox ID
return null;
}
/** /**
* Return color to display this calendar * Return color to display this calendar
*/ */

View file

@ -50,25 +50,25 @@ class kolab_bonnie_api
/** /**
* Wrapper function for <object>.changelog() API call * Wrapper function for <object>.changelog() API call
*/ */
public function changelog($type, $uid, $folder=null) public function changelog($type, $uid, $mailbox=null)
{ {
return $this->client->execute($type.'.changelog', array('uid' => $uid, 'folder' => $folder)); return $this->client->execute($type.'.changelog', array('uid' => $uid, 'mailbox' => $mailbox));
} }
/** /**
* Wrapper function for <object>.diff() API call * Wrapper function for <object>.diff() API call
*/ */
public function diff($type, $uid, $rev, $folder=null) public function diff($type, $uid, $rev, $mailbox=null)
{ {
return $this->client->execute($type.'.diff', array('uid' => $uid, 'rev' => $rev, 'folder' => $folder)); return $this->client->execute($type.'.diff', array('uid' => $uid, 'rev' => $rev, 'mailbox' => $mailbox));
} }
/** /**
* Wrapper function for <object>.get() API call * Wrapper function for <object>.get() API call
*/ */
public function get($type, $uid, $rev, $folder=null) public function get($type, $uid, $rev, $mailbox=null)
{ {
return $this->client->execute($type.'.get', array('uid' => $uid, 'rev' => intval($rev), 'folder' => $folder)); return $this->client->execute($type.'.get', array('uid' => $uid, 'rev' => intval($rev), 'mailbox' => $mailbox));
} }
/** /**

View file

@ -167,6 +167,38 @@ abstract class kolab_storage_folder_api
return join('/', $path); return join('/', $path);
} }
/**
* Getter for the Cyrus mailbox identifier corresponding to this folder
* (e.g. user/john.doe/Calendar/Personal@example.org)
*
* @return string Mailbox ID
*/
public function get_mailbox_id()
{
$info = $this->get_folder_info();
$owner = $this->get_owner();
list($user, $domain) = explode('@', $owner);
switch ($info['namespace']) {
case 'personal':
return sprintf('user/%s/%s@%s', $user, $this->name, $domain);
case 'shared':
$ns = $this->imap->get_namespace('shared');
$prefix = is_array($ns) ? $ns[0][0] : '';
list(, $domain) = explode('@', rcube::get_instance()->get_user_name());
return substr($this->name, strlen($prefix)) . '@' . $domain;
default:
$ns = $this->imap->get_namespace('other');
$prefix = is_array($ns) ? $ns[0][0] : '';
list($user, $folder) = explode($this->imap->get_hierarchy_delimiter(), substr($info['name'], strlen($prefix)), 2);
if (strpos($user, '@')) {
list($user, $domain) = explode('@', $user);
}
return sprintf('user/%s/%s@%s', $user, $folder, $domain);
}
}
/** /**
* Get the color value stored in metadata * Get the color value stored in metadata