summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-10-03 10:02:19 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2013-10-16 13:44:17 (GMT)
commit0e39734b88b755ed3f4a8eb1dede6841d46592d8 (patch)
tree00ae0a24acde5e9039d16053b2fbf2e81d7fcda7
parent977b9d8ad75844684e8ff8aa210e761add733dd1 (diff)
downloadroundcubemail-plugins-kolab-0e39734b88b755ed3f4a8eb1dede6841d46592d8.tar.gz
Add methods to read and set a folder's UID (migrated from iRony)
-rw-r--r--plugins/libkolab/lib/kolab_storage.php3
-rw-r--r--plugins/libkolab/lib/kolab_storage_folder.php37
2 files changed, 40 insertions, 0 deletions
diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php
index 1e44de1..23d273b 100644
--- a/plugins/libkolab/lib/kolab_storage.php
+++ b/plugins/libkolab/lib/kolab_storage.php
@@ -31,6 +31,9 @@ class kolab_storage
const COLOR_KEY_PRIVATE = '/private/vendor/kolab/color';
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';
public static $version = '3.0';
public static $last_error;
diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php
index 896061e..7f2e961 100644
--- a/plugins/libkolab/lib/kolab_storage_folder.php
+++ b/plugins/libkolab/lib/kolab_storage_folder.php
@@ -260,6 +260,43 @@ class kolab_storage_folder
}
/**
+ * Helper method to extract folder UID metadata
+ *
+ * @return string Folder's UID
+ */
+ 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);
+ $metadata = $this->get_metadata($metakeys);
+ 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()), 12, '-'), '-');
+ $this->set_uid($uid);
+
+ return $uid;
+ }
+
+ /**
+ * Helper method to set an UID value to the given IMAP folder instance
+ *
+ * @param string Folder's UID
+ * @return boolean True on succes, False on failure
+ */
+ 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));
+ }
+ return $success;
+ }
+
+ /**
* Check activation status of this folder
*
* @return boolean True if enabled, false if not