2 commits - plugins/kolab_activesync plugins/libkolab

Aleksander Machniak machniak at kolabsys.com
Sat Mar 15 15:19:59 CET 2014


 plugins/kolab_activesync/kolab_activesync_ui.php |    2 
 plugins/libkolab/lib/kolab_format.php            |   48 ++++++++++++++++++++++-
 plugins/libkolab/lib/kolab_format_note.php       |   43 ++++++++++++++++++--
 plugins/libkolab/lib/kolab_format_xcal.php       |   40 -------------------
 4 files changed, 89 insertions(+), 44 deletions(-)

New commits:
commit 02a84b391f4b9986bc4cdda8574ec2653404efb7
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Sat Mar 15 15:19:24 2014 +0100

    Display folders of type 'note' for selection to sync

diff --git a/plugins/kolab_activesync/kolab_activesync_ui.php b/plugins/kolab_activesync/kolab_activesync_ui.php
index 6dcdcaa..84c8b88 100644
--- a/plugins/kolab_activesync/kolab_activesync_ui.php
+++ b/plugins/kolab_activesync/kolab_activesync_ui.php
@@ -95,7 +95,7 @@ class kolab_activesync_ui
             $attrib['id'] = 'foldersubscriptions';
 
         // group folders by type (show only known types)
-        $folder_groups = array('mail' => array(), 'contact' => array(), 'event' => array(), 'task' => array());
+        $folder_groups = array('mail' => array(), 'contact' => array(), 'event' => array(), 'task' => array(), 'note' => array());
         $folder_types  = kolab_storage::folders_typedata();
         $imei          = $this->device['_id'];
         $subscribed    = array();


commit bf283d2fc2afd61b2eb2bb4c5ff392709949074a
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Sat Mar 15 15:18:29 2014 +0100

    Support Note objects

diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php
index 238ac64..11a5c4f 100644
--- a/plugins/libkolab/lib/kolab_format.php
+++ b/plugins/libkolab/lib/kolab_format.php
@@ -45,7 +45,7 @@ abstract class kolab_format
     protected $version = '3.0';
 
     const KTYPE_PREFIX = 'application/x-vnd.kolab.';
-    const PRODUCT_ID = 'Roundcube-libkolab-0.9';
+    const PRODUCT_ID   = 'Roundcube-libkolab-0.9';
 
     /**
      * Factory method to instantiate a kolab_format object of the given type and version
@@ -497,4 +497,50 @@ abstract class kolab_format
     {
         return array();
     }
+
+    protected function get_attachments(&$object)
+    {
+        // handle attachments
+        $vattach = $this->obj->attachments();
+        for ($i=0; $i < $vattach->size(); $i++) {
+            $attach = $vattach->get($i);
+
+            // skip cid: attachments which are mime message parts handled by kolab_storage_folder
+            if (substr($attach->uri(), 0, 4) != 'cid:' && $attach->label()) {
+                $name    = $attach->label();
+                $content = $attach->data();
+                $object['_attachments'][$name] = array(
+                    'name'     => $name,
+                    'mimetype' => $attach->mimetype(),
+                    'size'     => strlen($content),
+                    'content'  => $content,
+                );
+            }
+            else if (substr($attach->uri(), 0, 4) == 'http') {
+                $object['links'][] = $attach->uri();
+            }
+        }
+    }
+
+    protected function set_attachments($object)
+    {
+        // save attachments
+        $vattach = new vectorattachment;
+        foreach ((array) $object['_attachments'] as $cid => $attr) {
+            if (empty($attr))
+                continue;
+            $attach = new Attachment;
+            $attach->setLabel((string)$attr['name']);
+            $attach->setUri('cid:' . $cid, $attr['mimetype']);
+            $vattach->push($attach);
+        }
+
+        foreach ((array) $object['links'] as $link) {
+            $attach = new Attachment;
+            $attach->setUri($link, 'unknown');
+            $vattach->push($attach);
+        }
+
+        $this->obj->setAttachments($vattach);
+    }
 }
diff --git a/plugins/libkolab/lib/kolab_format_note.php b/plugins/libkolab/lib/kolab_format_note.php
index 04a8421..1f49dee 100644
--- a/plugins/libkolab/lib/kolab_format_note.php
+++ b/plugins/libkolab/lib/kolab_format_note.php
@@ -31,6 +31,11 @@ class kolab_format_note extends kolab_format
     protected $read_func = 'readNote';
     protected $write_func = 'writeNote';
 
+    protected $sensitivity_map = array(
+        'public'       => kolabformat::ClassPublic,
+        'private'      => kolabformat::ClassPrivate,
+        'confidential' => kolabformat::ClassConfidential,
+    );
 
     /**
      * Set properties to the kolabformat object
@@ -42,7 +47,12 @@ class kolab_format_note extends kolab_format
         // set common object properties
         parent::set($object);
 
-        // TODO: set object propeties
+        $this->obj->setSummary($object['title']);
+        $this->obj->setDescription($object['description']);
+        $this->obj->setClassification($this->sensitivity_map[$object['sensitivity']]);
+        $this->obj->setCategories(self::array2vector($object['categories']));
+
+        $this->set_attachments($object);
 
         // cache this data
         $this->data = $object;
@@ -73,10 +83,35 @@ class kolab_format_note extends kolab_format
         // read common object props into local data object
         $object = parent::to_array($data);
 
-        // TODO: read object properties
+        $sensitivity_map = array_flip($this->sensitivity_map);
 
-        $this->data = $object;
-        return $this->data;
+        // read object properties
+        $object += array(
+            'sensitivity' => $sensitivity_map[$this->obj->classification()],
+            'categories'  => self::vector2array($this->obj->categories()),
+            'title'       => $this->obj->summary(),
+            'description' => $this->obj->description(),
+        );
+
+        $this->get_attachments($object);
+
+        return $this->data = $object;
+    }
+
+    /**
+     * Callback for kolab_storage_cache to get object specific tags to cache
+     *
+     * @return array List of tags to save in cache
+     */
+    public function get_tags()
+    {
+        $tags = array();
+
+        foreach ((array) $this->data['categories'] as $cat) {
+            $tags[] = rcube_utils::normalize_string($cat);
+        }
+
+        return $tags;
     }
 
 }
diff --git a/plugins/libkolab/lib/kolab_format_xcal.php b/plugins/libkolab/lib/kolab_format_xcal.php
index 4af692c..a2544f4 100644
--- a/plugins/libkolab/lib/kolab_format_xcal.php
+++ b/plugins/libkolab/lib/kolab_format_xcal.php
@@ -237,26 +237,7 @@ abstract class kolab_format_xcal extends kolab_format
             }
         }
 
-        // handle attachments
-        $vattach = $this->obj->attachments();
-        for ($i=0; $i < $vattach->size(); $i++) {
-            $attach = $vattach->get($i);
-
-            // skip cid: attachments which are mime message parts handled by kolab_storage_folder
-            if (substr($attach->uri(), 0, 4) != 'cid:' && $attach->label()) {
-                $name    = $attach->label();
-                $content = $attach->data();
-                $object['_attachments'][$name] = array(
-                    'name'     => $name,
-                    'mimetype' => $attach->mimetype(),
-                    'size'     => strlen($content),
-                    'content'  => $content,
-                );
-            }
-            else if (substr($attach->uri(), 0, 4) == 'http') {
-                $object['links'][] = $attach->uri();
-            }
-        }
+        $this->get_attachments($object);
 
         return $object;
     }
@@ -443,24 +424,7 @@ abstract class kolab_format_xcal extends kolab_format
         }
         $this->obj->setAlarms($valarms);
 
-        // save attachments
-        $vattach = new vectorattachment;
-        foreach ((array)$object['_attachments'] as $cid => $attr) {
-            if (empty($attr))
-                continue;
-            $attach = new Attachment;
-            $attach->setLabel((string)$attr['name']);
-            $attach->setUri('cid:' . $cid, $attr['mimetype']);
-            $vattach->push($attach);
-        }
-
-        foreach ((array)$object['links'] as $link) {
-            $attach = new Attachment;
-            $attach->setUri($link, 'unknown');
-            $vattach->push($attach);
-        }
-
-        $this->obj->setAttachments($vattach);
+        $this->set_attachments($object);
     }
 
     /**




More information about the commits mailing list