Don't use private namespace for folder uniqueid annotations (T491)
This commit is contained in:
parent
bbddeb6345
commit
3239eeb947
3 changed files with 55 additions and 13 deletions
|
@ -32,7 +32,6 @@ class kolab_storage
|
|||
const NAME_KEY_SHARED = '/shared/vendor/kolab/displayname';
|
||||
const NAME_KEY_PRIVATE = '/private/vendor/kolab/displayname';
|
||||
const UID_KEY_SHARED = '/shared/vendor/kolab/uniqueid';
|
||||
const UID_KEY_PRIVATE = '/private/vendor/kolab/uniqueid';
|
||||
const UID_KEY_CYRUS = '/shared/vendor/cmu/cyrus-imapd/uniqueid';
|
||||
|
||||
const ERROR_IMAP_CONN = 1;
|
||||
|
|
|
@ -154,19 +154,24 @@ class kolab_storage_folder extends kolab_storage_folder_api
|
|||
public function get_uid()
|
||||
{
|
||||
// UID is defined in folder METADATA
|
||||
$metakeys = array(kolab_storage::UID_KEY_SHARED, kolab_storage::UID_KEY_PRIVATE, kolab_storage::UID_KEY_CYRUS);
|
||||
$metakeys = array(kolab_storage::UID_KEY_SHARED, kolab_storage::UID_KEY_CYRUS);
|
||||
$metadata = $this->get_metadata($metakeys);
|
||||
foreach ($metakeys as $key) {
|
||||
if (($uid = $metadata[$key])) {
|
||||
|
||||
if ($metadata !== null) {
|
||||
foreach ($metakeys as $key) {
|
||||
if ($uid = $metadata[$key]) {
|
||||
return $uid;
|
||||
}
|
||||
}
|
||||
|
||||
// generate a folder UID and set it to IMAP
|
||||
$uid = rtrim(chunk_split(md5($this->name . $this->get_owner() . uniqid('-', true)), 12, '-'), '-');
|
||||
if ($this->set_uid($uid)) {
|
||||
return $uid;
|
||||
}
|
||||
}
|
||||
|
||||
// generate a folder UID and set it to IMAP
|
||||
$uid = rtrim(chunk_split(md5($this->name . $this->get_owner() . uniqid('-', true)), 12, '-'), '-');
|
||||
if ($this->set_uid($uid)) {
|
||||
return $uid;
|
||||
}
|
||||
$this->check_error();
|
||||
|
||||
// create hash from folder name if we can't write the UID metadata
|
||||
return md5($this->name . $this->get_owner());
|
||||
|
@ -180,9 +185,7 @@ class kolab_storage_folder extends kolab_storage_folder_api
|
|||
*/
|
||||
public function set_uid($uid)
|
||||
{
|
||||
if (!($success = $this->set_metadata(array(kolab_storage::UID_KEY_SHARED => $uid)))) {
|
||||
$success = $this->set_metadata(array(kolab_storage::UID_KEY_PRIVATE => $uid));
|
||||
}
|
||||
$success = $this->set_metadata(array(kolab_storage::UID_KEY_SHARED => $uid));
|
||||
|
||||
$this->check_error();
|
||||
return $success;
|
||||
|
|
|
@ -135,7 +135,7 @@ class kolab_storage_folder_test extends PHPUnit_Framework_TestCase
|
|||
|
||||
function test_006_activate()
|
||||
{
|
||||
$folder = new kolab_storage_folder('Calendar', 'contact');
|
||||
$folder = new kolab_storage_folder('Calendar', 'event');
|
||||
$this->assertTrue($folder->activate(true));
|
||||
$this->assertTrue($folder->is_active());
|
||||
|
||||
|
@ -167,4 +167,44 @@ class kolab_storage_folder_test extends PHPUnit_Framework_TestCase
|
|||
$folder = new kolab_storage_folder('Contacts', 'contact');
|
||||
$this->assertEquals($folder->count(), 1);
|
||||
}
|
||||
|
||||
function test_T491_get_uid()
|
||||
{
|
||||
$rcmail = rcmail::get_instance();
|
||||
$imap = $rcmail->get_storage();
|
||||
$db = $rcmail->get_dbh();
|
||||
|
||||
// clear cache
|
||||
//$imap->clear_cache('mailboxes.metadata', true);
|
||||
|
||||
// get folder UID
|
||||
$folder = new kolab_storage_folder('Calendar', 'event', 'event');
|
||||
$uid = $folder->get_uid();
|
||||
|
||||
// now get folder uniqueid annotations
|
||||
$annotations = array(
|
||||
'cyrus' => kolab_storage::UID_KEY_CYRUS,
|
||||
'shared' => kolab_storage::UID_KEY_SHARED,
|
||||
'private' => '/private/vendor/kolab/uniqueid',
|
||||
);
|
||||
foreach ($annotations as $key => $annotation) {
|
||||
$meta = $imap->get_metadata('Calendar', $annotation);
|
||||
$annotations[$key] = $meta['Calendar'][$annotation];
|
||||
}
|
||||
|
||||
// compare results
|
||||
if ($annotations['shared']) {
|
||||
$this->assertSame($annotations['shared'], $uid);
|
||||
}
|
||||
else if ($annotations['cyrus']) {
|
||||
$this->assertSame($annotations['cyrus'], $uid);
|
||||
}
|
||||
else {
|
||||
// never use private namespace
|
||||
$this->assertTrue($annotations['private'] != $uid);
|
||||
}
|
||||
|
||||
// @TODO: check if the cache contains valid entries, not so simple with memcache
|
||||
// as the cache key name is quite internal to the rcube_imap class.
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue