Date: Tue, 27 Apr 2010 09:45:22 +0000 (+0200)
Subject: Start refactoring the IMAP driver classes in Kolab_Storage.
X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7ce81d16b5b39763acc25e03428c1098f78a523a;p=horde.git
Start refactoring the IMAP driver classes in Kolab_Storage.
---
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver.php
index 75d8cf6fb..1f5ef55df 100644
--- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver.php
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver.php
@@ -1,6 +1,6 @@
+ * @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
+ * @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
index 000000000..5f182bf5d
--- /dev/null
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Cclient.php
@@ -0,0 +1,428 @@
+
+ * @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
+ * @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
index 000000000..87b061ec6
--- /dev/null
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Base.php
@@ -0,0 +1,275 @@
+
+ * @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
+ * @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
index 000000000..0f118f9b9
--- /dev/null
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Log.php
@@ -0,0 +1,275 @@
+
+ * @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
+ * @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
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Imap.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Imap.php
index 2edaf30e0..1da8cc397 100644
--- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Imap.php
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Imap.php
@@ -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
index 000000000..fa550bc1c
--- /dev/null
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Mock.php
@@ -0,0 +1,434 @@
+
+ * @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
+ * @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
index 000000000..de54fe754
--- /dev/null
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Pear.php
@@ -0,0 +1,428 @@
+
+ * @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
+ * @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
diff --git a/framework/Kolab_Storage/package.xml b/framework/Kolab_Storage/package.xml
index e154aaa1b..5e61a2dcf 100644
--- a/framework/Kolab_Storage/package.xml
+++ b/framework/Kolab_Storage/package.xml
@@ -31,8 +31,8 @@
jan@horde.orgyes
- 2010-04-07
-
+ 2010-04-27
+
0.4.00.1.0
@@ -74,7 +74,15 @@
+
+
+
+
+
+
+
+
@@ -131,6 +139,11 @@
+
+
+
+
+
@@ -143,6 +156,7 @@
+
@@ -233,7 +247,13 @@
+
+
+
+
+
+
@@ -272,6 +292,8 @@
+
+
@@ -342,7 +364,7 @@
alphaalpha
- 2010-04-07
+ 2010-04-27LGPL
* 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
index 000000000..a51ae3317
--- /dev/null
+++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Class/Driver/MockTest.php
@@ -0,0 +1,74 @@
+
+ * @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
+ * @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()
+ );
+ }
+}