Start refactoring the IMAP driver classes in Kolab_Storage.
authorGunnar Wrobel <p@rdus.de>
Tue, 27 Apr 2010 09:45:22 +0000 (11:45 +0200)
committerGunnar Wrobel <wrobel@temple.(none)>
Tue, 27 Apr 2010 09:54:08 +0000 (11:54 +0200)
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Base.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Cclient.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Base.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Log.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Imap.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Mock.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Pear.php [new file with mode: 0644]
framework/Kolab_Storage/package.xml
framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/MockTest.php [new file with mode: 0644]

index 75d8cf6..1f5ef55 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * The driver for accessing Kolab storage.
+ * The driver definition for accessing Kolab storage.
  *
  * PHP version 5
  *
@@ -12,7 +12,7 @@
  */
 
 /**
- * The driver class for accessing Kolab storage.
+ * The driver definition for accessing Kolab storage.
  *
  * Copyright 2004-2010 The Horde Project (http://www.horde.org/)
  *
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Storage
  */
-abstract class Horde_Kolab_Storage_Driver
+interface Horde_Kolab_Storage_Driver
 {
     /**
      * Return the id of the user currently authenticated.
      *
      * @return string The id of the user that opened the connection.
      */
-    abstract public function getAuth();
+    public function getAuth();
 
     /**
      * Does the given folder exist?
@@ -41,7 +41,129 @@ abstract class Horde_Kolab_Storage_Driver
      *
      * @return boolean True in case the folder exists, false otherwise.
      */
-    abstract public function exists($folder);
+    public function exists($folder);
+
+    /**
+     * Opens the given folder.
+     *
+     * @param string $folder  The folder to open
+     *
+     * @return mixed  True in case the folder was opened successfully, a PEAR
+     *                error otherwise.
+     */
+    public function select($folder);
+
+    /**
+     * Returns the status of the current folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  An array that contains 'uidvalidity' and 'uidnext'.
+     */
+    public function status($folder);
+
+    /**
+     * Returns the message ids of the messages in this folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  The message ids.
+     */
+    public function getUids($folder);
+
+    /**
+     * Create the specified folder.
+     *
+     * @param string $folder The folder to create.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function create($folder);
+
+    /**
+     * Delete the specified folder.
+     *
+     * @param string $folder  The folder to delete.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function delete($folder);
+
+    /**
+     * Rename the specified folder.
+     *
+     * @param string $old  The folder to rename.
+     * @param string $new  The new name of the folder.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function rename($old, $new);
+
+    /**
+     * Appends a message to the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param string $msg     The message to append.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function appendMessage($mailbox, $msg);
+
+    /**
+     * Deletes messages from the current folder.
+     *
+     * @param integer $uids  IMAP message ids.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function deleteMessages($mailbox, $uids);
+
+    /**
+     * Moves a message to a new folder.
+     *
+     * @param integer $uid        IMAP message id.
+     * @param string $new_folder  Target folder.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function moveMessage($old_folder, $uid, $new_folder);
+
+    /**
+     * Expunges messages in the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function expunge($mailbox);
+
+    /**
+     * Retrieves the message headers for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param int $uid                The message id.
+     * @param boolean $peek_for_body  Prefetch the body.
+     *
+     * @return mixed  The message header or a PEAR error in case of an error.
+     */
+    public function getMessageHeader($mailbox, $uid, $peek_for_body = true);
+
+    /**
+     * Retrieves the message body for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param integet $uid  The message id.
+     *
+     * @return mixed  The message body or a PEAR error in case of an error.
+     */
+    public function getMessageBody($mailbox, $uid);
 
     /**
      * Retrieve the access rights for a folder.
@@ -50,7 +172,7 @@ abstract class Horde_Kolab_Storage_Driver
      *
      * @return An array of rights.
      */
-    abstract public function getAcl(Horde_Kolab_Storage_Folder $folder);
+    public function getAcl(Horde_Kolab_Storage_Folder $folder);
 
     /**
      * Set the access rights for a folder.
@@ -61,7 +183,7 @@ abstract class Horde_Kolab_Storage_Driver
      *
      * @return NULL
      */
-    abstract public function setAcl($folder, $user, $acl);
+    public function setAcl($folder, $user, $acl);
 
     /**
      * Delete the access rights for user on a folder.
@@ -71,20 +193,40 @@ abstract class Horde_Kolab_Storage_Driver
      *
      * @return NULL
      */
-    abstract public function deleteAcl($folder, $user);
+    public function deleteAcl($folder, $user);
+
+    /**
+     * Fetches the annotation on a folder.
+     *
+     * @param string $entry  The entry to fetch.
+     * @param string $folder The name of the folder.
+     *
+     * @return string The annotation value.
+     */
+    public function getAnnotation($entry, $folder);
+
+    /**
+     * Sets the annotation on a folder.
+     *
+     * @param string $entry  The entry to set.
+     * @param array  $value  The values to set
+     * @param string $folder The name of the folder.
+     *
+     * @return NULL
+     */
+    public function setAnnotation($entry, $value, $folder);
 
     /**
      * Retrieve the namespace information for this connection.
      *
      * @return Horde_Kolab_Storage_Namespace The initialized namespace handler.
      */
-    abstract public function getNamespace();
+    public function getNamespace();
 
     /**
      * Get the group handler for this connection.
      *
      * @return Horde_Group The group handler.
      */
-    abstract public function getGroupHandler();
-
+    public function getGroupHandler();
 }
\ No newline at end of file
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Base.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Base.php
new file mode 100644 (file)
index 0000000..33af192
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+/**
+ * The base driver definition for accessing Kolab storage drivers.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * The base driver definition for accessing Kolab storage drivers.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+abstract class Horde_Kolab_Storage_Driver_Base
+implements Horde_Kolab_Storage_Driver
+{
+    /**
+     * The group handler for this connection.
+     *
+     * @var Horde_Group
+     */
+    private $_groups;
+
+    /**
+     * Additional connection parameters.
+     *
+     * @var array
+     */
+    private $_params;
+
+    /**
+     * Constructor.
+     *
+     * @param Group $groups The groups handler.
+     * @param array $params Connection parameters.
+     */
+    public function __construct(Group $groups, $params = array())
+    {
+        $this->_groups = $groups;
+        $this->_params = $params;
+    }
+
+    /**
+     * Return a parameter setting for this connection.
+     *
+     * @param string $key     The parameter key.
+     * @param mixed  $default An optional default value.
+     *
+     * @return mixed The parameter value.
+     */
+    public function getParam($key, $default = null)
+    {
+        return isset($this->_params[$key]) ? $this->_params[$key] : $default;
+    }
+
+    /**
+     * Retrieve the namespace information for this connection.
+     *
+     * @return Horde_Kolab_Storage_Namespace The initialized namespace handler.
+     */
+    public function getNamespace()
+    {
+        if (isset($this->_params['namespaces'])) {
+            return new Horde_Kolab_Storage_Namespace_Config(
+                $this->_params['namespaces']
+            );
+        }
+        return new Horde_Kolab_Storage_Namespace_Fixed();
+    }
+
+    /**
+     * Get the group handler for this connection.
+     *
+     * @return Horde_Group The group handler.
+     */
+    public function getGroupHandler()
+    {
+        return $this->_groups;
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Cclient.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Cclient.php
new file mode 100644 (file)
index 0000000..5f182bf
--- /dev/null
@@ -0,0 +1,428 @@
+<?php
+/**
+ * An cclient based Kolab storage driver.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * An cclient based Kolab storage driver.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Driver_Cclient
+implements Horde_Kolab_Storage_Driver
+{
+    /**
+     * The group handler for this connection.
+     *
+     * @var Horde_Group
+     */
+    private $_groups;
+
+    /**
+     * Constructor.
+     *
+     * @param array  $params Connection parameters.
+     */
+    public function __construct(
+        Group $groups
+    ) {
+        $this->_groups = $groups;
+    }
+
+    /**
+     * Return the id of the user currently authenticated.
+     *
+     * @return string The id of the user that opened the IMAP connection.
+     */
+    public function getAuth()
+    {
+        return $this->_imap->getParam('username');
+    }
+
+    /**
+     * Retrieves a list of mailboxes on the server.
+     *
+     * @return array The list of mailboxes.
+     */
+    public function getMailboxes()
+    {
+        return $this->_imap->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array('flat' => true));
+    }
+
+    /**
+     * Opens the given folder.
+     *
+     * @param string $folder  The folder to open
+     *
+     * @return mixed  True in case the folder was opened successfully, a PEAR
+     *                error otherwise.
+     */
+    public function select($folder)
+    {
+        $this->_imap->openMailbox($folder, Horde_Imap_Client::OPEN_AUTO);
+        return true;
+    }
+
+    /**
+     * Does the given folder exist?
+     *
+     * @param string $folder The folder to check.
+     *
+     * @return boolean True in case the folder exists, false otherwise.
+     */
+    public function exists($folder)
+    {
+        $folders = $this->getMailboxes();
+        if (in_array($folder, $folders)) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Returns the status of the current folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  An array that contains 'uidvalidity' and 'uidnext'.
+     */
+    public function status($folder)
+    {
+        return $this->_imap->status($folder,
+                                    Horde_Imap_Client::STATUS_UIDNEXT
+                                    | Horde_Imap_Client::STATUS_UIDVALIDITY);
+    }
+
+    /**
+     * Returns the message ids of the messages in this folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  The message ids.
+     */
+    public function getUids($folder)
+    {
+        $search_query = new Horde_Imap_Client_Search_Query();
+        $search_query->flag('DELETED', false);
+        $uidsearch = $this->_imap->search($folder, $search_query);
+        $uids = $uidsearch['match'];
+        return $uids;
+    }
+
+    /**
+     * Create the specified folder.
+     *
+     * @param string $folder The folder to create.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function create($folder)
+    {
+        return $this->_imap->createMailbox($folder);
+    }
+
+    /**
+     * Delete the specified folder.
+     *
+     * @param string $folder  The folder to delete.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function delete($folder)
+    {
+        return $this->_imap->deleteMailbox($folder);
+    }
+
+    /**
+     * Rename the specified folder.
+     *
+     * @param string $old  The folder to rename.
+     * @param string $new  The new name of the folder.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function rename($old, $new)
+    {
+        return $this->_imap->renameMailbox($old, $new);
+    }
+
+    /**
+     * Appends a message to the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param string $msg     The message to append.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function appendMessage($mailbox, $msg)
+    {
+        return $this->_imap->append($mailbox, array(array('data' => $msg)));
+    }
+
+    /**
+     * Deletes messages from the current folder.
+     *
+     * @param integer $uids  IMAP message ids.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function deleteMessages($mailbox, $uids)
+    {
+        if (!is_array($uids)) {
+            $uids = array($uids);
+        }
+        return $this->_imap->store($mailbox, array('add' => array('\\deleted'), 'ids' => $uids));
+    }
+
+    /**
+     * Moves a message to a new folder.
+     *
+     * @param integer $uid        IMAP message id.
+     * @param string $new_folder  Target folder.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function moveMessage($old_folder, $uid, $new_folder)
+    {
+        $options = array('ids' => array($uid), 'move' => true);
+        return $this->_imap->copy($old_folder, $new_folder, $options);
+    }
+
+    /**
+     * Expunges messages in the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function expunge($mailbox)
+    {
+        return $this->_imap->expunge($mailbox);
+    }
+
+    /**
+     * Retrieves the message headers for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param int $uid                The message id.
+     * @param boolean $peek_for_body  Prefetch the body.
+     *
+     * @return mixed  The message header or a PEAR error in case of an error.
+     */
+    public function getMessageHeader($mailbox, $uid, $peek_for_body = true)
+    {
+        $options = array('ids' => array($uid));
+        $criteria = array(
+            Horde_Imap_Client::FETCH_HEADERTEXT => array(
+                array(
+                )
+            )
+        );
+        $result = $this->_imap->fetch($mailbox, $criteria, $options);
+        return $result[$uid]['headertext'][0];
+    }
+
+    /**
+     * Retrieves the message body for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param integet $uid  The message id.
+     *
+     * @return mixed  The message body or a PEAR error in case of an error.
+     */
+    public function getMessageBody($mailbox, $uid)
+    {
+        $options = array('ids' => array($uid));
+        $criteria = array(
+            Horde_Imap_Client::FETCH_BODYTEXT => array(
+                array(
+                )
+            )
+        );
+        $result = $this->_imap->fetch($mailbox, $criteria, $options);
+        return $result[$uid]['bodytext'][0];
+    }
+
+    /**
+     * Retrieve the access rights for a folder.
+     *
+     * @param Horde_Kolab_Storage_Folder $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    public function getAcl(Horde_Kolab_Storage_Folder $folder)
+    {
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            if ($folder->getOwner() == $this->getAuth()) {
+                try {
+                    return $this->_getAcl($folder->getName());
+                } catch (Exception $e) {
+                    return array($this->getAuth() => $this->_getMyAcl($folder->getName()));
+                }
+            } else {
+                $acl = $this->_getMyAcl($folder->getName());
+                if (strpos($acl, 'a')) {
+                    try {
+                        return $this->_getAcl($folder->getName());
+                    } catch (Exception $e) {
+                    }
+                }
+                return array($this->getAuth() => $acl);
+            }
+        } else {
+            return array($this->getAuth() => 'lrid');
+        }
+    }
+
+    /**
+     * Retrieve the access rights for a folder.
+     *
+     * @param string $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    private function _getAcl($folder)
+    {
+        $acl = $this->_imap->getACL($folder);
+        $result = array();
+        foreach ($acl as $user => $rights) {
+            $result[$user] = join('', $rights);
+        }
+        return $result;
+    }
+    
+    /**
+     * Retrieve the access rights on a folder for the current user.
+     *
+     * @param string $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    private function _getMyAcl($folder)
+    {
+        return $this->_imap->getMyACLRights($folder);
+    }
+
+    /**
+     * Set the access rights for a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to set the ACL for.
+     * @param string $acl     The ACL.
+     *
+     * @return NULL
+     */
+    public function setAcl($folder, $user, $acl)
+    {
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            $this->_imap->setACL($folder, $user, array('rights' => $acl));
+        }
+    }
+
+    /**
+     * Delete the access rights for user on a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to delete the ACL for
+     *
+     * @return NULL
+     */
+    public function deleteAcl($folder, $user)
+    {
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            $this->_imap->setACL($folder, $user, array('remove' => true));
+        }
+    }
+
+    /**
+     * Fetches the annotation on a folder.
+     *
+     * @param string $entry         The entry to fetch.
+     * @param string $mailbox_name  The name of the folder.
+     *
+     * @return mixed  The annotation value or a PEAR error in case of an error.
+     */
+    public function getAnnotation($entry, $mailbox_name)
+    {
+        try {
+            $result = $this->_imap->getMetadata($mailbox_name, $entry);
+        } catch (Exception $e) {
+            return '';
+        }
+        return isset($result[$mailbox_name][$entry]) ? $result[$mailbox_name][$entry] : '';
+    }
+
+    /**
+     * Sets the annotation on a folder.
+     *
+     * @param string $entry          The entry to set.
+     * @param array  $value          The values to set
+     * @param string $mailbox_name   The name of the folder.
+     *
+     * @return mixed  True if successfull, a PEAR error otherwise.
+     */
+    public function setAnnotation($entry, $value, $mailbox_name)
+    {
+        return $this->_imap->setMetadata($mailbox_name,
+                                         array($entry => $value));
+    }
+
+
+    /**
+     * Retrieve the namespace information for this connection.
+     *
+     * @return Horde_Kolab_Storage_Namespace The initialized namespace handler.
+     */
+    public function getNamespace()
+    {
+        if ($this->_imap->queryCapability('NAMESPACE') === true) {
+            return new Horde_Kolab_Storage_Namespace_Imap(
+                $this->_imap->getNamespaces(),
+                isset($this->_params['namespaces']) ? $this->_params['namespaces'] : array()
+            );
+        } else if (isset($this->_params['namespaces'])) {
+            return new Horde_Kolab_Storage_Namespace_Config(
+                $this->_params['namespaces']
+            );
+        }
+        return new Horde_Kolab_Storage_Namespace_Fixed();
+    }
+
+    /**
+     * Get the group handler for this connection.
+     *
+     * @return Horde_Group The group handler.
+     */
+    public function getGroupHandler()
+    {
+        return $this->_groups;
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Base.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Base.php
new file mode 100644 (file)
index 0000000..87b061e
--- /dev/null
@@ -0,0 +1,275 @@
+<?php
+/**
+ * The basic driver decorator definition for accessing Kolab storage.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * The basic driver decorator definition for accessing Kolab storage.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Driver_Decorator_Base
+implements Horde_Kolab_Storage_Driver
+{
+    /**
+     * Return the id of the user currently authenticated.
+     *
+     * @return string The id of the user that opened the connection.
+     */
+    public function getAuth()
+    {
+    }
+
+    /**
+     * Does the given folder exist?
+     *
+     * @param string $folder The folder to check.
+     *
+     * @return boolean True in case the folder exists, false otherwise.
+     */
+    public function exists($folder)
+    {
+    }
+
+    /**
+     * Opens the given folder.
+     *
+     * @param string $folder  The folder to open
+     *
+     * @return mixed  True in case the folder was opened successfully, a PEAR
+     *                error otherwise.
+     */
+    public function select($folder)
+    {
+    }
+
+    /**
+     * Returns the status of the current folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  An array that contains 'uidvalidity' and 'uidnext'.
+     */
+    public function status($folder)
+    {
+    }
+
+    /**
+     * Returns the message ids of the messages in this folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  The message ids.
+     */
+    public function getUids($folder)
+    {
+    }
+
+    /**
+     * Create the specified folder.
+     *
+     * @param string $folder The folder to create.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function create($folder)
+    {
+    }
+
+    /**
+     * Delete the specified folder.
+     *
+     * @param string $folder  The folder to delete.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function delete($folder)
+    {
+    }
+
+    /**
+     * Rename the specified folder.
+     *
+     * @param string $old  The folder to rename.
+     * @param string $new  The new name of the folder.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function rename($old, $new)
+    {
+    }
+
+    /**
+     * Appends a message to the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param string $msg     The message to append.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function appendMessage($mailbox, $msg)
+    {
+    }
+
+    /**
+     * Deletes messages from the current folder.
+     *
+     * @param integer $uids  IMAP message ids.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function deleteMessages($mailbox, $uids)
+    {
+    }
+
+    /**
+     * Moves a message to a new folder.
+     *
+     * @param integer $uid        IMAP message id.
+     * @param string $new_folder  Target folder.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function moveMessage($old_folder, $uid, $new_folder)
+    {
+    }
+
+    /**
+     * Expunges messages in the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function expunge($mailbox)
+    {
+    }
+
+    /**
+     * Retrieves the message headers for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param int $uid                The message id.
+     * @param boolean $peek_for_body  Prefetch the body.
+     *
+     * @return mixed  The message header or a PEAR error in case of an error.
+     */
+    public function getMessageHeader($mailbox, $uid, $peek_for_body = true)
+    {
+    }
+
+    /**
+     * Retrieves the message body for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param integet $uid  The message id.
+     *
+     * @return mixed  The message body or a PEAR error in case of an error.
+     */
+    public function getMessageBody($mailbox, $uid)
+    {
+    }
+
+    /**
+     * Retrieve the access rights for a folder.
+     *
+     * @param Horde_Kolab_Storage_Folder $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    public function getAcl(Horde_Kolab_Storage_Folder $folder)
+    {
+    }
+
+    /**
+     * Set the access rights for a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to set the ACL for.
+     * @param string $acl     The ACL.
+     *
+     * @return NULL
+     */
+    public function setAcl($folder, $user, $acl)
+    {
+    }
+
+    /**
+     * Delete the access rights for user on a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to delete the ACL for
+     *
+     * @return NULL
+     */
+    public function deleteAcl($folder, $user)
+    {
+    }
+
+    /**
+     * Fetches the annotation on a folder.
+     *
+     * @param string $entry  The entry to fetch.
+     * @param string $folder The name of the folder.
+     *
+     * @return string The annotation value.
+     */
+    public function getAnnotation($entry, $folder)
+    {
+    }
+
+    /**
+     * Sets the annotation on a folder.
+     *
+     * @param string $entry  The entry to set.
+     * @param array  $value  The values to set
+     * @param string $folder The name of the folder.
+     *
+     * @return NULL
+     */
+    public function setAnnotation($entry, $value, $folder)
+    {
+    }
+
+    /**
+     * Retrieve the namespace information for this connection.
+     *
+     * @return Horde_Kolab_Storage_Namespace The initialized namespace handler.
+     */
+    public function getNamespace()
+    {
+    }
+
+    /**
+     * Get the group handler for this connection.
+     *
+     * @return Horde_Group The group handler.
+     */
+    public function getGroupHandler()
+    {
+    }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Log.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Log.php
new file mode 100644 (file)
index 0000000..0f118f9
--- /dev/null
@@ -0,0 +1,275 @@
+<?php
+/**
+ * A log decorator definition for the Kolab storage drivers.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * The basic driver decorator definition for accessing Kolab storage.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Driver_Decorator_Log
+extends Horde_Kolab_Storage_Driver_Decorator_Base
+{
+    /**
+     * Return the id of the user currently authenticated.
+     *
+     * @return string The id of the user that opened the connection.
+     */
+    public function getAuth()
+    {
+    }
+
+    /**
+     * Does the given folder exist?
+     *
+     * @param string $folder The folder to check.
+     *
+     * @return boolean True in case the folder exists, false otherwise.
+     */
+    public function exists($folder)
+    {
+    }
+
+    /**
+     * Opens the given folder.
+     *
+     * @param string $folder  The folder to open
+     *
+     * @return mixed  True in case the folder was opened successfully, a PEAR
+     *                error otherwise.
+     */
+    public function select($folder)
+    {
+    }
+
+    /**
+     * Returns the status of the current folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  An array that contains 'uidvalidity' and 'uidnext'.
+     */
+    public function status($folder)
+    {
+    }
+
+    /**
+     * Returns the message ids of the messages in this folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  The message ids.
+     */
+    public function getUids($folder)
+    {
+    }
+
+    /**
+     * Create the specified folder.
+     *
+     * @param string $folder The folder to create.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function create($folder)
+    {
+    }
+
+    /**
+     * Delete the specified folder.
+     *
+     * @param string $folder  The folder to delete.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function delete($folder)
+    {
+    }
+
+    /**
+     * Rename the specified folder.
+     *
+     * @param string $old  The folder to rename.
+     * @param string $new  The new name of the folder.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function rename($old, $new)
+    {
+    }
+
+    /**
+     * Appends a message to the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param string $msg     The message to append.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function appendMessage($mailbox, $msg)
+    {
+    }
+
+    /**
+     * Deletes messages from the current folder.
+     *
+     * @param integer $uids  IMAP message ids.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function deleteMessages($mailbox, $uids)
+    {
+    }
+
+    /**
+     * Moves a message to a new folder.
+     *
+     * @param integer $uid        IMAP message id.
+     * @param string $new_folder  Target folder.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function moveMessage($old_folder, $uid, $new_folder)
+    {
+    }
+
+    /**
+     * Expunges messages in the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function expunge($mailbox)
+    {
+    }
+
+    /**
+     * Retrieves the message headers for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param int $uid                The message id.
+     * @param boolean $peek_for_body  Prefetch the body.
+     *
+     * @return mixed  The message header or a PEAR error in case of an error.
+     */
+    public function getMessageHeader($mailbox, $uid, $peek_for_body = true)
+    {
+    }
+
+    /**
+     * Retrieves the message body for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param integet $uid  The message id.
+     *
+     * @return mixed  The message body or a PEAR error in case of an error.
+     */
+    public function getMessageBody($mailbox, $uid)
+    {
+    }
+
+    /**
+     * Retrieve the access rights for a folder.
+     *
+     * @param Horde_Kolab_Storage_Folder $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    public function getAcl(Horde_Kolab_Storage_Folder $folder)
+    {
+    }
+
+    /**
+     * Set the access rights for a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to set the ACL for.
+     * @param string $acl     The ACL.
+     *
+     * @return NULL
+     */
+    public function setAcl($folder, $user, $acl)
+    {
+    }
+
+    /**
+     * Delete the access rights for user on a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to delete the ACL for
+     *
+     * @return NULL
+     */
+    public function deleteAcl($folder, $user)
+    {
+    }
+
+    /**
+     * Fetches the annotation on a folder.
+     *
+     * @param string $entry  The entry to fetch.
+     * @param string $folder The name of the folder.
+     *
+     * @return string The annotation value.
+     */
+    public function getAnnotation($entry, $folder)
+    {
+    }
+
+    /**
+     * Sets the annotation on a folder.
+     *
+     * @param string $entry  The entry to set.
+     * @param array  $value  The values to set
+     * @param string $folder The name of the folder.
+     *
+     * @return NULL
+     */
+    public function setAnnotation($entry, $value, $folder)
+    {
+    }
+
+    /**
+     * Retrieve the namespace information for this connection.
+     *
+     * @return Horde_Kolab_Storage_Namespace The initialized namespace handler.
+     */
+    public function getNamespace()
+    {
+    }
+
+    /**
+     * Get the group handler for this connection.
+     *
+     * @return Horde_Group The group handler.
+     */
+    public function getGroupHandler()
+    {
+    }
+}
\ No newline at end of file
index 2edaf30..1da8cc3 100644 (file)
@@ -25,7 +25,8 @@
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Storage
  */
-class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
+class Horde_Kolab_Storage_Driver_Imap
+extends Horde_Kolab_Storage_Driver_Base
 {
     /**
      * The IMAP connection
@@ -35,23 +36,17 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
     private $_imap;
 
     /**
-     * The group handler for this connection.
-     *
-     * @var Horde_Group
-     */
-    private $_groups;
-
-    /**
      * Constructor.
      *
      * @param array  $params Connection parameters.
      */
     public function __construct(
         Horde_Imap_Client_Base $imap,
-        Group $groups
+        Group $groups,
+        $params = array()
     ) {
         $this->_imap   = $imap;
-        $this->_groups = $groups;
+        parent::__construct($groups, $params);
     }
 
     /**
@@ -111,7 +106,7 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
      *
      * @return array  An array that contains 'uidvalidity' and 'uidnext'.
      */
-    function status($folder)
+    public function status($folder)
     {
         return $this->_imap->status($folder,
                                     Horde_Imap_Client::STATUS_UIDNEXT
@@ -125,7 +120,7 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
      *
      * @return array  The message ids.
      */
-    function getUids($folder)
+    public function getUids($folder)
     {
         $search_query = new Horde_Imap_Client_Search_Query();
         $search_query->flag('DELETED', false);
@@ -155,7 +150,7 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
      * @return mixed True in case the operation was successfull, a
      *               PEAR error otherwise.
      */
-    function delete($folder)
+    public function delete($folder)
     {
         return $this->_imap->deleteMailbox($folder);
     }
@@ -169,7 +164,7 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
      * @return mixed True in case the operation was successfull, a
      *               PEAR error otherwise.
      */
-    function rename($old, $new)
+    public function rename($old, $new)
     {
         return $this->_imap->renameMailbox($old, $new);
     }
@@ -183,7 +178,7 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
      *
      * @return mixed  True or a PEAR error in case of an error.
      */
-    function appendMessage($mailbox, $msg)
+    public function appendMessage($mailbox, $msg)
     {
         return $this->_imap->append($mailbox, array(array('data' => $msg)));
     }
@@ -195,7 +190,7 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
      *
      * @return mixed  True or a PEAR error in case of an error.
      */
-    function deleteMessages($mailbox, $uids)
+    public function deleteMessages($mailbox, $uids)
     {
         if (!is_array($uids)) {
             $uids = array($uids);
@@ -211,7 +206,7 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
      *
      * @return mixed  True or a PEAR error in case of an error.
      */
-    function moveMessage($old_folder, $uid, $new_folder)
+    public function moveMessage($old_folder, $uid, $new_folder)
     {
         $options = array('ids' => array($uid), 'move' => true);
         return $this->_imap->copy($old_folder, $new_folder, $options);
@@ -225,7 +220,7 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
      *
      * @return mixed  True or a PEAR error in case of an error.
      */
-    function expunge($mailbox)
+    public function expunge($mailbox)
     {
         return $this->_imap->expunge($mailbox);
     }
@@ -240,7 +235,7 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
      *
      * @return mixed  The message header or a PEAR error in case of an error.
      */
-    function getMessageHeader($mailbox, $uid, $peek_for_body = true)
+    public function getMessageHeader($mailbox, $uid, $peek_for_body = true)
     {
         $options = array('ids' => array($uid));
         $criteria = array(
@@ -262,7 +257,7 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
      *
      * @return mixed  The message body or a PEAR error in case of an error.
      */
-    function getMessageBody($mailbox, $uid)
+    public function getMessageBody($mailbox, $uid)
     {
         $options = array('ids' => array($uid));
         $criteria = array(
@@ -377,7 +372,7 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
      *
      * @return mixed  The annotation value or a PEAR error in case of an error.
      */
-    function getAnnotation($entry, $mailbox_name)
+    public function getAnnotation($entry, $mailbox_name)
     {
         try {
             $result = $this->_imap->getMetadata($mailbox_name, $entry);
@@ -413,24 +408,9 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
         if ($this->_imap->queryCapability('NAMESPACE') === true) {
             return new Horde_Kolab_Storage_Namespace_Imap(
                 $this->_imap->getNamespaces(),
-                isset($this->_params['namespaces']) ? $this->_params['namespaces'] : array()
-            );
-        } else if (isset($this->_params['namespaces'])) {
-            return new Horde_Kolab_Storage_Namespace_Config(
-                $this->_params['namespaces']
+                $this->getParam('namespaces', array())
             );
         }
-        return new Horde_Kolab_Storage_Namespace_Fixed();
-    }
-
-    /**
-     * Get the group handler for this connection.
-     *
-     * @return Horde_Group The group handler.
-     */
-    public function getGroupHandler()
-    {
-        return $this->_groups;
+        return parent::getNamespace();
     }
-
 }
\ No newline at end of file
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Mock.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Mock.php
new file mode 100644 (file)
index 0000000..fa550bc
--- /dev/null
@@ -0,0 +1,434 @@
+<?php
+/**
+ * An Kolab storage mock driver.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * An Kolab storage mock driver.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Driver_Mock
+extends Horde_Kolab_Storage_Driver_Base
+{
+    /**
+     * The data of the mailbox currently opened
+     *
+     * @var array
+     */
+    private $_mbox = null;
+
+    /**
+     * The name of the mailbox currently opened
+     *
+     * @var array
+     */
+    private $_mboxname = null;
+
+    /**
+     * Parse the folder name into an id for this mock driver.
+     *
+     * @return string The folder id.
+     */
+    private function _parseFolder($folder)
+    {
+        if (substr($folder, 0, 5) == 'INBOX') {
+            $user = split('@', $this->_user);
+            return 'user/' . $user[0] . substr($folder, 5);
+        }
+        return $folder;
+    }
+
+    /**
+     * Return the id of the user currently authenticated.
+     *
+     * @return string The id of the user that opened the IMAP connection.
+     */
+    public function getAuth()
+    {
+        return $this->_imap->getParam('username');
+    }
+
+    /**
+     * Retrieves a list of mailboxes on the server.
+     *
+     * @return array The list of mailboxes.
+     */
+    public function getMailboxes()
+    {
+        return $this->_imap->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array('flat' => true));
+    }
+
+    /**
+     * Opens the given folder.
+     *
+     * @param string $folder  The folder to open
+     *
+     * @return mixed  True in case the folder was opened successfully, a PEAR
+     *                error otherwise.
+     */
+    public function select($folder)
+    {
+        $folder = $this->_parseFolder($folder);
+        if (!isset($GLOBALS['KOLAB_TESTING'][$folder])) {
+            throw new Horde_Kolab_Storage_Exception(sprintf("IMAP folder %s does not exist!", $folder));
+        }
+        $this->_mbox = &$GLOBALS['KOLAB_TESTING'][$folder];
+        $this->_mboxname = $folder;
+        return true;
+    }
+
+    /**
+     * Does the given folder exist?
+     *
+     * @param string $folder The folder to check.
+     *
+     * @return boolean True in case the folder exists, false otherwise.
+     */
+    public function exists($folder)
+    {
+        $folders = $this->getMailboxes();
+        if (in_array($folder, $folders)) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Returns the status of the current folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  An array that contains 'uidvalidity' and 'uidnext'.
+     */
+    public function status($folder)
+    {
+        return $this->_imap->status($folder,
+                                    Horde_Imap_Client::STATUS_UIDNEXT
+                                    | Horde_Imap_Client::STATUS_UIDVALIDITY);
+    }
+
+    /**
+     * Returns the message ids of the messages in this folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  The message ids.
+     */
+    public function getUids($folder)
+    {
+        $search_query = new Horde_Imap_Client_Search_Query();
+        $search_query->flag('DELETED', false);
+        $uidsearch = $this->_imap->search($folder, $search_query);
+        $uids = $uidsearch['match'];
+        return $uids;
+    }
+
+    /**
+     * Create the specified folder.
+     *
+     * @param string $folder The folder to create.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function create($folder)
+    {
+        return $this->_imap->createMailbox($folder);
+    }
+
+    /**
+     * Delete the specified folder.
+     *
+     * @param string $folder  The folder to delete.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function delete($folder)
+    {
+        return $this->_imap->deleteMailbox($folder);
+    }
+
+    /**
+     * Rename the specified folder.
+     *
+     * @param string $old  The folder to rename.
+     * @param string $new  The new name of the folder.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function rename($old, $new)
+    {
+        return $this->_imap->renameMailbox($old, $new);
+    }
+
+    /**
+     * Appends a message to the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param string $msg     The message to append.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function appendMessage($mailbox, $msg)
+    {
+        return $this->_imap->append($mailbox, array(array('data' => $msg)));
+    }
+
+    /**
+     * Deletes messages from the current folder.
+     *
+     * @param integer $uids  IMAP message ids.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function deleteMessages($mailbox, $uids)
+    {
+        if (!is_array($uids)) {
+            $uids = array($uids);
+        }
+        return $this->_imap->store($mailbox, array('add' => array('\\deleted'), 'ids' => $uids));
+    }
+
+    /**
+     * Moves a message to a new folder.
+     *
+     * @param integer $uid        IMAP message id.
+     * @param string $new_folder  Target folder.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function moveMessage($old_folder, $uid, $new_folder)
+    {
+        $options = array('ids' => array($uid), 'move' => true);
+        return $this->_imap->copy($old_folder, $new_folder, $options);
+    }
+
+    /**
+     * Expunges messages in the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function expunge($mailbox)
+    {
+        return $this->_imap->expunge($mailbox);
+    }
+
+    /**
+     * Retrieves the message headers for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param int $uid                The message id.
+     * @param boolean $peek_for_body  Prefetch the body.
+     *
+     * @return mixed  The message header or a PEAR error in case of an error.
+     */
+    public function getMessageHeader($mailbox, $uid, $peek_for_body = true)
+    {
+        $options = array('ids' => array($uid));
+        $criteria = array(
+            Horde_Imap_Client::FETCH_HEADERTEXT => array(
+                array(
+                )
+            )
+        );
+        $result = $this->_imap->fetch($mailbox, $criteria, $options);
+        return $result[$uid]['headertext'][0];
+    }
+
+    /**
+     * Retrieves the message body for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param integet $uid  The message id.
+     *
+     * @return mixed  The message body or a PEAR error in case of an error.
+     */
+    public function getMessageBody($mailbox, $uid)
+    {
+        $options = array('ids' => array($uid));
+        $criteria = array(
+            Horde_Imap_Client::FETCH_BODYTEXT => array(
+                array(
+                )
+            )
+        );
+        $result = $this->_imap->fetch($mailbox, $criteria, $options);
+        return $result[$uid]['bodytext'][0];
+    }
+
+    /**
+     * Retrieve the access rights for a folder.
+     *
+     * @param Horde_Kolab_Storage_Folder $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    public function getAcl(Horde_Kolab_Storage_Folder $folder)
+    {
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            if ($folder->getOwner() == $this->getAuth()) {
+                try {
+                    return $this->_getAcl($folder->getName());
+                } catch (Exception $e) {
+                    return array($this->getAuth() => $this->_getMyAcl($folder->getName()));
+                }
+            } else {
+                $acl = $this->_getMyAcl($folder->getName());
+                if (strpos($acl, 'a')) {
+                    try {
+                        return $this->_getAcl($folder->getName());
+                    } catch (Exception $e) {
+                    }
+                }
+                return array($this->getAuth() => $acl);
+            }
+        } else {
+            return array($this->getAuth() => 'lrid');
+        }
+    }
+
+    /**
+     * Retrieve the access rights for a folder.
+     *
+     * @param string $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    private function _getAcl($folder)
+    {
+        $acl = $this->_imap->getACL($folder);
+        $result = array();
+        foreach ($acl as $user => $rights) {
+            $result[$user] = join('', $rights);
+        }
+        return $result;
+    }
+    
+    /**
+     * Retrieve the access rights on a folder for the current user.
+     *
+     * @param string $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    private function _getMyAcl($folder)
+    {
+        return $this->_imap->getMyACLRights($folder);
+    }
+
+    /**
+     * Set the access rights for a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to set the ACL for.
+     * @param string $acl     The ACL.
+     *
+     * @return NULL
+     */
+    public function setAcl($folder, $user, $acl)
+    {
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            $this->_imap->setACL($folder, $user, array('rights' => $acl));
+        }
+    }
+
+    /**
+     * Delete the access rights for user on a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to delete the ACL for
+     *
+     * @return NULL
+     */
+    public function deleteAcl($folder, $user)
+    {
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            $this->_imap->setACL($folder, $user, array('remove' => true));
+        }
+    }
+
+    /**
+     * Fetches the annotation on a folder.
+     *
+     * @param string $entry         The entry to fetch.
+     * @param string $mailbox_name  The name of the folder.
+     *
+     * @return mixed  The annotation value or a PEAR error in case of an error.
+     */
+    public function getAnnotation($entry, $mailbox_name)
+    {
+        $mailbox_name = $this->_parseFolder($mailbox_name);
+        $old_mbox = null;
+        if ($mailbox_name != $this->_mboxname) {
+            $old_mbox = $this->_mboxname;
+            $result = $this->select($mailbox_name);
+            if (is_a($result, 'PEAR_Error')) {
+                return $result;
+            }
+        }
+        if (!isset($this->_mbox['annotations'][$entries])
+            || !isset($this->_mbox['annotations'][$entries][$value])) {
+            return false;
+        }
+        $annotation = $this->_mbox['annotations'][$entries][$value];
+        if ($old_mbox) {
+            $this->select($old_mbox);
+        }
+        return $annotation;
+    }
+
+    /**
+     * Sets the annotation on a folder.
+     *
+     * @param string $entry          The entry to set.
+     * @param array  $value          The values to set
+     * @param string $mailbox_name   The name of the folder.
+     *
+     * @return mixed  True if successfull, a PEAR error otherwise.
+     */
+    public function setAnnotation($entry, $value, $mailbox_name)
+    {
+        return $this->_imap->setMetadata($mailbox_name,
+                                         array($entry => $value));
+    }
+
+    /**
+     * Get the group handler for this connection.
+     *
+     * @return Horde_Group The group handler.
+     */
+    public function getGroupHandler()
+    {
+        return $this->_groups;
+    }
+
+}
\ No newline at end of file
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Pear.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Pear.php
new file mode 100644 (file)
index 0000000..de54fe7
--- /dev/null
@@ -0,0 +1,428 @@
+<?php
+/**
+ * An PEAR-Net_Imap based Kolab storage driver.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * An PEAR-Net_Imap based Kolab storage driver.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Driver_Pear
+implements Horde_Kolab_Storage_Driver
+{
+    /**
+     * The group handler for this connection.
+     *
+     * @var Horde_Group
+     */
+    private $_groups;
+
+    /**
+     * Constructor.
+     *
+     * @param array  $params Connection parameters.
+     */
+    public function __construct(
+        Group $groups
+    ) {
+        $this->_groups = $groups;
+    }
+
+    /**
+     * Return the id of the user currently authenticated.
+     *
+     * @return string The id of the user that opened the IMAP connection.
+     */
+    public function getAuth()
+    {
+        return $this->_imap->getParam('username');
+    }
+
+    /**
+     * Retrieves a list of mailboxes on the server.
+     *
+     * @return array The list of mailboxes.
+     */
+    public function getMailboxes()
+    {
+        return $this->_imap->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array('flat' => true));
+    }
+
+    /**
+     * Opens the given folder.
+     *
+     * @param string $folder  The folder to open
+     *
+     * @return mixed  True in case the folder was opened successfully, a PEAR
+     *                error otherwise.
+     */
+    public function select($folder)
+    {
+        $this->_imap->openMailbox($folder, Horde_Imap_Client::OPEN_AUTO);
+        return true;
+    }
+
+    /**
+     * Does the given folder exist?
+     *
+     * @param string $folder The folder to check.
+     *
+     * @return boolean True in case the folder exists, false otherwise.
+     */
+    public function exists($folder)
+    {
+        $folders = $this->getMailboxes();
+        if (in_array($folder, $folders)) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Returns the status of the current folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  An array that contains 'uidvalidity' and 'uidnext'.
+     */
+    public function status($folder)
+    {
+        return $this->_imap->status($folder,
+                                    Horde_Imap_Client::STATUS_UIDNEXT
+                                    | Horde_Imap_Client::STATUS_UIDVALIDITY);
+    }
+
+    /**
+     * Returns the message ids of the messages in this folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  The message ids.
+     */
+    public function getUids($folder)
+    {
+        $search_query = new Horde_Imap_Client_Search_Query();
+        $search_query->flag('DELETED', false);
+        $uidsearch = $this->_imap->search($folder, $search_query);
+        $uids = $uidsearch['match'];
+        return $uids;
+    }
+
+    /**
+     * Create the specified folder.
+     *
+     * @param string $folder The folder to create.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function create($folder)
+    {
+        return $this->_imap->createMailbox($folder);
+    }
+
+    /**
+     * Delete the specified folder.
+     *
+     * @param string $folder  The folder to delete.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function delete($folder)
+    {
+        return $this->_imap->deleteMailbox($folder);
+    }
+
+    /**
+     * Rename the specified folder.
+     *
+     * @param string $old  The folder to rename.
+     * @param string $new  The new name of the folder.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function rename($old, $new)
+    {
+        return $this->_imap->renameMailbox($old, $new);
+    }
+
+    /**
+     * Appends a message to the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param string $msg     The message to append.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function appendMessage($mailbox, $msg)
+    {
+        return $this->_imap->append($mailbox, array(array('data' => $msg)));
+    }
+
+    /**
+     * Deletes messages from the current folder.
+     *
+     * @param integer $uids  IMAP message ids.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function deleteMessages($mailbox, $uids)
+    {
+        if (!is_array($uids)) {
+            $uids = array($uids);
+        }
+        return $this->_imap->store($mailbox, array('add' => array('\\deleted'), 'ids' => $uids));
+    }
+
+    /**
+     * Moves a message to a new folder.
+     *
+     * @param integer $uid        IMAP message id.
+     * @param string $new_folder  Target folder.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function moveMessage($old_folder, $uid, $new_folder)
+    {
+        $options = array('ids' => array($uid), 'move' => true);
+        return $this->_imap->copy($old_folder, $new_folder, $options);
+    }
+
+    /**
+     * Expunges messages in the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function expunge($mailbox)
+    {
+        return $this->_imap->expunge($mailbox);
+    }
+
+    /**
+     * Retrieves the message headers for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param int $uid                The message id.
+     * @param boolean $peek_for_body  Prefetch the body.
+     *
+     * @return mixed  The message header or a PEAR error in case of an error.
+     */
+    function getMessageHeader($mailbox, $uid, $peek_for_body = true)
+    {
+        $options = array('ids' => array($uid));
+        $criteria = array(
+            Horde_Imap_Client::FETCH_HEADERTEXT => array(
+                array(
+                )
+            )
+        );
+        $result = $this->_imap->fetch($mailbox, $criteria, $options);
+        return $result[$uid]['headertext'][0];
+    }
+
+    /**
+     * Retrieves the message body for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param integet $uid  The message id.
+     *
+     * @return mixed  The message body or a PEAR error in case of an error.
+     */
+    function getMessageBody($mailbox, $uid)
+    {
+        $options = array('ids' => array($uid));
+        $criteria = array(
+            Horde_Imap_Client::FETCH_BODYTEXT => array(
+                array(
+                )
+            )
+        );
+        $result = $this->_imap->fetch($mailbox, $criteria, $options);
+        return $result[$uid]['bodytext'][0];
+    }
+
+    /**
+     * Retrieve the access rights for a folder.
+     *
+     * @param Horde_Kolab_Storage_Folder $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    public function getAcl(Horde_Kolab_Storage_Folder $folder)
+    {
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            if ($folder->getOwner() == $this->getAuth()) {
+                try {
+                    return $this->_getAcl($folder->getName());
+                } catch (Exception $e) {
+                    return array($this->getAuth() => $this->_getMyAcl($folder->getName()));
+                }
+            } else {
+                $acl = $this->_getMyAcl($folder->getName());
+                if (strpos($acl, 'a')) {
+                    try {
+                        return $this->_getAcl($folder->getName());
+                    } catch (Exception $e) {
+                    }
+                }
+                return array($this->getAuth() => $acl);
+            }
+        } else {
+            return array($this->getAuth() => 'lrid');
+        }
+    }
+
+    /**
+     * Retrieve the access rights for a folder.
+     *
+     * @param string $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    private function _getAcl($folder)
+    {
+        $acl = $this->_imap->getACL($folder);
+        $result = array();
+        foreach ($acl as $user => $rights) {
+            $result[$user] = join('', $rights);
+        }
+        return $result;
+    }
+    
+    /**
+     * Retrieve the access rights on a folder for the current user.
+     *
+     * @param string $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    private function _getMyAcl($folder)
+    {
+        return $this->_imap->getMyACLRights($folder);
+    }
+
+    /**
+     * Set the access rights for a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to set the ACL for.
+     * @param string $acl     The ACL.
+     *
+     * @return NULL
+     */
+    public function setAcl($folder, $user, $acl)
+    {
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            $this->_imap->setACL($folder, $user, array('rights' => $acl));
+        }
+    }
+
+    /**
+     * Delete the access rights for user on a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to delete the ACL for
+     *
+     * @return NULL
+     */
+    public function deleteAcl($folder, $user)
+    {
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            $this->_imap->setACL($folder, $user, array('remove' => true));
+        }
+    }
+
+    /**
+     * Fetches the annotation on a folder.
+     *
+     * @param string $entry         The entry to fetch.
+     * @param string $mailbox_name  The name of the folder.
+     *
+     * @return mixed  The annotation value or a PEAR error in case of an error.
+     */
+    public function getAnnotation($entry, $mailbox_name)
+    {
+        try {
+            $result = $this->_imap->getMetadata($mailbox_name, $entry);
+        } catch (Exception $e) {
+            return '';
+        }
+        return isset($result[$mailbox_name][$entry]) ? $result[$mailbox_name][$entry] : '';
+    }
+
+    /**
+     * Sets the annotation on a folder.
+     *
+     * @param string $entry          The entry to set.
+     * @param array  $value          The values to set
+     * @param string $mailbox_name   The name of the folder.
+     *
+     * @return mixed  True if successfull, a PEAR error otherwise.
+     */
+    public function setAnnotation($entry, $value, $mailbox_name)
+    {
+        return $this->_imap->setMetadata($mailbox_name,
+                                         array($entry => $value));
+    }
+
+
+    /**
+     * Retrieve the namespace information for this connection.
+     *
+     * @return Horde_Kolab_Storage_Namespace The initialized namespace handler.
+     */
+    public function getNamespace()
+    {
+        if ($this->_imap->queryCapability('NAMESPACE') === true) {
+            return new Horde_Kolab_Storage_Namespace_Imap(
+                $this->_imap->getNamespaces(),
+                isset($this->_params['namespaces']) ? $this->_params['namespaces'] : array()
+            );
+        } else if (isset($this->_params['namespaces'])) {
+            return new Horde_Kolab_Storage_Namespace_Config(
+                $this->_params['namespaces']
+            );
+        }
+        return new Horde_Kolab_Storage_Namespace_Fixed();
+    }
+
+    /**
+     * Get the group handler for this connection.
+     *
+     * @return Horde_Group The group handler.
+     */
+    public function getGroupHandler()
+    {
+        return $this->_groups;
+    }
+
+}
\ No newline at end of file
index e154aaa..5e61a2d 100644 (file)
@@ -31,8 +31,8 @@
   <email>jan@horde.org</email>
   <active>yes</active>
  </lead>
- <date>2010-04-07</date>
- <time>19:47:51</time>
+ <date>2010-04-27</date>
+ <time>11:44:55</time>
  <version>
   <release>0.4.0</release>
   <api>0.1.0</api>
      <dir name="Kolab">
       <dir name="Storage">
        <dir name="Driver">
+        <dir name="Decorator">
+         <file name="Base.php" role="php" />
+         <file name="Log.php" role="php" />
+        </dir> <!-- /lib/Horde/Kolab/Storage/Driver/Decorator -->
+        <file name="Base.php" role="php" />
+        <file name="Cclient.php" role="php" />
         <file name="Imap.php" role="php" />
+        <file name="Mock.php" role="php" />
+        <file name="Pear.php" role="php" />
        </dir> <!-- /lib/Horde/Kolab/Storage/Driver -->
        <dir name="Folder">
         <dir name="Decorator">
     <dir name="Horde">
      <dir name="Kolab">
       <dir name="Storage">
+       <dir name="Class">
+        <dir name="Driver">
+         <file name="MockTest.php" role="test" />
+        </dir> <!-- /test/Horde/Kolab/Storage/Class/Driver -->
+       </dir> <!-- /test/Horde/Kolab/Storage/Class -->
        <file name="AclTest.php" role="test" />
        <file name="AllTests.php" role="test" />
        <file name="AttachmentTest.php" role="test" />
        <file name="phpunit.xml" role="test" />
        <file name="Scenario.php" role="test" />
        <file name="StorageTest.php" role="test" />
+       <file name="TriggerTest.php" role="test" />
       </dir> <!-- /test/Horde/Kolab/Storage -->
      </dir> <!-- /test/Horde/Kolab -->
     </dir> <!-- /test/Horde -->
    <install as="Horde/Kolab/Storage/Exception.php" name="lib/Horde/Kolab/Storage/Exception.php" />
    <install as="Horde/Kolab/Storage/Folder.php" name="lib/Horde/Kolab/Storage/Folder.php" />
    <install as="Horde/Kolab/Storage/Namespace.php" name="lib/Horde/Kolab/Storage/Namespace.php" />
+   <install as="Horde/Kolab/Storage/Driver/Base.php" name="lib/Horde/Kolab/Storage/Driver/Base.php" />
+   <install as="Horde/Kolab/Storage/Driver/Cclient.php" name="lib/Horde/Kolab/Storage/Driver/Cclient.php" />
    <install as="Horde/Kolab/Storage/Driver/Imap.php" name="lib/Horde/Kolab/Storage/Driver/Imap.php" />
+   <install as="Horde/Kolab/Storage/Driver/Mock.php" name="lib/Horde/Kolab/Storage/Driver/Mock.php" />
+   <install as="Horde/Kolab/Storage/Driver/Pear.php" name="lib/Horde/Kolab/Storage/Driver/Pear.php" />
+   <install as="Horde/Kolab/Storage/Driver/Decorator/Base.php" name="lib/Horde/Kolab/Storage/Driver/Decorator/Base.php" />
+   <install as="Horde/Kolab/Storage/Driver/Decorator/Log.php" name="lib/Horde/Kolab/Storage/Driver/Decorator/Log.php" />
    <install as="Horde/Kolab/Storage/Folder/Base.php" name="lib/Horde/Kolab/Storage/Folder/Base.php" />
    <install as="Horde/Kolab/Storage/Folder/Permission.php" name="lib/Horde/Kolab/Storage/Folder/Permission.php" />
    <install as="Horde/Kolab/Storage/Folder/Decorator/Base.php" name="lib/Horde/Kolab/Storage/Folder/Decorator/Base.php" />
    <install as="Horde/Kolab/Storage/phpunit.xml" name="test/Horde/Kolab/Storage/phpunit.xml" />
    <install as="Horde/Kolab/Storage/Scenario.php" name="test/Horde/Kolab/Storage/Scenario.php" />
    <install as="Horde/Kolab/Storage/StorageTest.php" name="test/Horde/Kolab/Storage/StorageTest.php" />
+   <install as="Horde/Kolab/Storage/TriggerTest.php" name="test/Horde/Kolab/Storage/TriggerTest.php" />
+   <install as="Horde/Kolab/Storage/Class/Driver/MockTest.php" name="test/Horde/Kolab/Storage/Class/Driver/MockTest.php" />
   </filelist>
  </phprelease>
  <changelog>
     <release>alpha</release>
     <api>alpha</api>
    </stability>
-   <date>2010-04-07</date>
+   <date>2010-04-27</date>
    <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
    <notes>
 * Added namespace support (Bug #6691).
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/MockTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/MockTest.php
new file mode 100644 (file)
index 0000000..a51ae33
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Test the Kolab mock driver.
+ *
+ * PHP version 5
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../Autoload.php';
+
+/**
+ * Test the Kolab mock driver.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Class_Driver_MockTest
+extends PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        require_once 'Horde/Group.php';
+        require_once 'Horde/Group/mock.php';
+
+        $this->group = new Group_mock();
+    }
+
+    public function testGetAnnotationReturnsAnnotationValue()
+    {
+        $data = array();
+        $data['INBOX/Contacts']['annotations']['/vendor/kolab/folder-type']['value.shared'] = 'contact.default';
+        $driver = new Horde_Kolab_Storage_Driver_Mock(
+            $this->group,
+            $data
+        );
+        $this->assertEquals(
+            'contact.default',
+            $driver->getAnnotation('/vendor/kolab/folder-type', 'value.shared', 'INBOX/Contacts')
+        );
+    }
+
+    public function testGetNamespaceReturnsNamespaceHandler()
+    {
+        Horde_Nls::setCharset('UTF8');
+        $data = array();
+        $data['INBOX/Contacts']['annotations']['/vendor/kolab/folder-type']['value.shared'] = 'contact.default';
+        $driver = new Horde_Kolab_Storage_Driver_Mock(
+            $this->group,
+            $data
+        );
+        $this->assertType(
+            'Horde_Kolab_Storage_Namespace',
+            $driver->getNamespace()
+        );
+    }
+}