Branch 'roundcubemail-plugins-kolab-3.1' - plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Wed Oct 16 15:44:25 CEST 2013


 plugins/libkolab/lib/kolab_storage.php        |    3 ++
 plugins/libkolab/lib/kolab_storage_folder.php |   37 ++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

New commits:
commit 0e39734b88b755ed3f4a8eb1dede6841d46592d8
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Thu Oct 3 12:02:19 2013 +0200

    Add methods to read and set a folder's UID (migrated from iRony)

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




More information about the commits mailing list