From e14c560d16f360ca6e2d83990f2abc6447c12fc1 Mon Sep 17 00:00:00 2001
From: Gunnar Wrobel
Date: Mon, 22 Mar 2010 17:28:07 +0100
Subject: [PATCH] Add the other two namespace drivers.
---
.../lib/Horde/Kolab/Storage/Namespace/Config.php | 81 ++++++++++++++++++++++
.../lib/Horde/Kolab/Storage/Namespace/Imap.php | 73 +++++++++++++++++++
framework/Kolab_Storage/package.xml | 4 ++
.../test/Horde/Kolab/Storage/NamespaceTest.php | 43 +++++++++++-
4 files changed, 200 insertions(+), 1 deletion(-)
create mode 100644 framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace/Config.php
create mode 100644 framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace/Imap.php
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace/Config.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace/Config.php
new file mode 100644
index 000000000..b1f8f0575
--- /dev/null
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace/Config.php
@@ -0,0 +1,81 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * The Horde_Kolab_Storage_Namespace_Config:: allows to configure the available
+ * IMAP namespaces on the Kolab server.
+ *
+ * Copyright 2004-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_Namespace_Config
+extends Horde_Kolab_Storage_Namespace
+{
+ /**
+ * The namespaces.
+ *
+ * @var array
+ */
+ protected $_namespaces = array(
+ self::PRIV => array(
+ 'INBOX' => '/',
+ ),
+ self::OTHER => array(
+ 'user' => '/',
+ ),
+ self::SHARED => array(
+ '' => '/',
+ ),
+ );
+
+ /**
+ * A prefix in the shared namespaces that will be ignored/removed.
+ *
+ * @var string
+ */
+ protected $_sharedPrefix = '';
+
+ /**
+ * Indicates the personal namespace that the class will use to create new
+ * folders.
+ *
+ * @var string
+ */
+ protected $_primaryPersonalNamespace = 'INBOX';
+
+ /**
+ * Constructor.
+ */
+ public function __construct(array $configuration)
+ {
+ if (isset($configuration['elements'])) {
+ $this->_namespaces = $configuration['elements'];
+ }
+ if (isset($configuration['shared_prefix'])) {
+ $this->_sharedPrefix = $configuration['shared_prefix'];
+ }
+ if (isset($configuration['add_namespace'])) {
+ $this->_primaryPersonalNamespace = $configuration['add_namespace'];
+ }
+ $this->_charset = Horde_Nls::getCharset();
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace/Imap.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace/Imap.php
new file mode 100644
index 000000000..89a9ae5d4
--- /dev/null
+++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace/Imap.php
@@ -0,0 +1,73 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * The Horde_Kolab_Storage_Namespace_Config:: allows to use the information from
+ * the IMAP NAMESPACE command to identify the IMAP namespaces on the Kolab
+ * server.
+ *
+ * Copyright 2004-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_Namespace_Imap
+extends Horde_Kolab_Storage_Namespace
+{
+ /**
+ * The namespaces.
+ *
+ * @var array
+ */
+ protected $_namespaces = array();
+
+ /**
+ * A prefix in the shared namespaces that will be ignored/removed.
+ *
+ * @var string
+ */
+ protected $_sharedPrefix = '';
+
+ /**
+ * Indicates the personal namespace that the class will use to create new
+ * folders.
+ *
+ * @var string
+ */
+ protected $_primaryPersonalNamespace = 'INBOX';
+
+ /**
+ * Constructor.
+ */
+ public function __construct(array $namespaces, array $configuration)
+ {
+ foreach ($namespaces as $namespace) {
+ $this->_namespaces[$namespace['type']][$namespace['name']] = $namespace['delimiter'];
+ }
+ if (isset($configuration['shared_prefix'])) {
+ $this->_sharedPrefix = $configuration['shared_prefix'];
+ }
+ if (isset($configuration['add_namespace'])) {
+ $this->_primaryPersonalNamespace = $configuration['add_namespace'];
+ }
+ $this->_charset = Horde_Nls::getCharset();
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Storage/package.xml b/framework/Kolab_Storage/package.xml
index 74d52cddc..30b4073a2 100644
--- a/framework/Kolab_Storage/package.xml
+++ b/framework/Kolab_Storage/package.xml
@@ -81,7 +81,9 @@
+
+
@@ -192,7 +194,9 @@
+
+
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/NamespaceTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/NamespaceTest.php
index f2de7d43e..bc949de70 100644
--- a/framework/Kolab_Storage/test/Horde/Kolab/Storage/NamespaceTest.php
+++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/NamespaceTest.php
@@ -267,7 +267,48 @@ class Horde_Kolab_Storage_NamespaceTest extends PHPUnit_Framework_TestCase
private function _getNamespaces()
{
return array(
- new Horde_Kolab_Storage_Namespace_Fixed()
+ new Horde_Kolab_Storage_Namespace_Fixed(),
+ new Horde_Kolab_Storage_Namespace_Config(
+ array(
+ 'elements' => array(
+ Horde_Kolab_Storage_Namespace::PRIV => array(
+ 'INBOX' => '/',
+ ),
+ Horde_Kolab_Storage_Namespace::OTHER => array(
+ 'user' => '/',
+ ),
+ Horde_Kolab_Storage_Namespace::SHARED => array(
+ '' => '/',
+ ),
+ ),
+ 'shared_prefix' => 'shared.',
+ 'add_namespace' => 'INBOX',
+ )
+ ),
+ new Horde_Kolab_Storage_Namespace_Imap(
+ array(
+ array(
+ 'name' => 'INBOX',
+ 'type' => Horde_Kolab_Storage_Namespace::PRIV,
+ 'delimiter' => '/',
+ ),
+ array(
+ 'name' => 'user',
+ 'type' => Horde_Kolab_Storage_Namespace::OTHER,
+ 'delimiter' => '/',
+ ),
+ array(
+ 'name' => '',
+ 'type' => Horde_Kolab_Storage_Namespace::SHARED,
+ 'delimiter' => '/',
+ ),
+ ),
+ array(
+ 'shared_prefix' => 'shared.',
+ 'add_namespace' => 'INBOX',
+ )
+ ),
+
);
}
}
\ No newline at end of file
--
2.11.0