*
* @var array
*/
- protected $_namespaces = array(
- self::PRIV => array(
- 'INBOX' => '/',
- ),
- self::OTHER => array(
- 'user' => '/',
- ),
- self::SHARED => array(
- '' => '/',
- ),
- );
+ protected $_namespaces = array();
/**
* The characterset this module uses to communicate with the outside world.
protected $_sharedPrefix;
/**
+ * The namespace that matches any folder name not matching to another
+ * namespace.
+ *
+ * @var Horde_Kolab_Storage_Namespace_Element
+ */
+ protected $_any;
+
+ /**
* Indicates the personal namespace that the class will use to create new
* folders.
*
- * @var string
+ * @var Horde_Kolab_Storage_Namespace_Element
*/
protected $_primaryPersonalNamespace;
/**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ $this->_charset = Horde_Nls::getCharset();
+ if (empty($this->_primaryPersonalNamespace)) {
+ $priv = null;
+ foreach ($this->_namespaces as $namespace) {
+ if ($namespace->getName() == 'INBOX') {
+ $this->_primaryPersonalNamespace = $namespace;
+ break;
+ }
+ if (empty($priv) && $namespace->getType() == self::PRIV) {
+ $priv = $namespace;
+ }
+ }
+ if (empty($this->_primaryPersonalNamespace)) {
+ $this->_primaryPersonalNamespace = $priv;
+ }
+ }
+ }
+
+ /**
* Match a folder name with the corresponding namespace.
*
* @param string $name The name of the folder.
*
- * @return array The corresponding namespace.
+ * @return Horde_Kolab_Storage_Namespace_Element The corresponding namespace.
*
* @throws Horde_Kolab_Storage_Exception If the namespace of the folder
* cannot be determined.
*/
protected function matchNamespace($name)
{
- foreach (array(self::PRIV, self::OTHER, self::SHARED) as $type) {
- foreach ($this->_namespaces[$type] as $namespace => $delimiter) {
- if ($namespace === '' || strpos($name, $namespace) === 0) {
- return array(
- 'namespace' => $namespace,
- 'delimiter' => $delimiter,
- 'type' => $type,
- );
- }
+ foreach ($this->_namespaces as $namespace) {
+ if ($namespace->matches($name)) {
+ return $namespace;
}
}
+ if (!empty($this->_any)) {
+ return $this->_any;
+ }
throw new Horde_Kolab_Storage_Exception(
sprintf('Namespace of folder %s cannot be determined.', $name)
);
*/
public function getTitle($name)
{
- return join($this->_subpath($name, $this->matchNamespace($name)), ':');
+ $name = Horde_String::convertCharset($name, 'UTF7-IMAP', $this->_charset);
+ return $this->matchNamespace($name)->getTitle($name);
}
/**
*/
public function getOwner($name)
{
- $namespace = $this->matchNamespace($name);
$name = Horde_String::convertCharset($name, 'UTF7-IMAP', $this->_charset);
- $path = explode($namespace['delimiter'], $name);
- if ($namespace['type'] == self::PRIV) {
- return self::PRIV;
- }
- if ($namespace['type'] == self::OTHER) {
- $user = $path[1];
- $domain = strstr(array_pop($path), '@');
- if (!empty($domain)) {
- $user .= $domain;
- }
- return self::OTHER . ':' . $user;
- }
- if ($namespace['type'] == self::SHARED) {
- return self::SHARED;
- }
+ return $this->matchNamespace($name)->getOwner($name);
}
/**
*/
public function getSubpath($name)
{
- $namespace = $this->matchNamespace($name);
- $path = $this->_subpath($name, $namespace);
- return join($path, $namespace['delimiter']);
+ $name = Horde_String::convertCharset($name, 'UTF7-IMAP', $this->_charset);
+ return $this->matchNamespace($name)->getSubpath($name);
}
/**
$path = explode(':', $name);
if (empty($this->_sharedPrefix)
|| (strpos($path[0], $this->_sharedPrefix) === false
- && !in_array($path[0], array_keys($this->_namespaces[self::OTHER])))) {
- $namespace = $this->_getPrimaryPersonalNamespace();
- array_unshift($path, $namespace['namespace']);
- } else {
- $namespace = $this->matchNamespace($name);
- }
- return Horde_String::convertCharset(
- join($path, $namespace['delimiter']), $this->_charset, 'UTF7-IMAP'
- );
- }
-
- /**
- * Returns the primary personal namespace.
- *
- * @return array The primary personal namespace.
- */
- protected function _getPrimaryPersonalNamespace()
- {
- foreach ($this->_namespaces[self::PRIV] as $namespace => $delimiter) {
- if ($namespace == $this->_primaryPersonalNamespace) {
- return array(
- 'namespace' => $namespace,
- 'delimiter' => $delimiter,
- 'type' => self::PRIV,
- );
- }
- }
- return array(
- 'namespace' => array_shift(array_keys($this->_namespaces[self::PRIV])),
- 'delimiter' => reset($this->_namespaces[self::PRIV]),
- 'type' => self::PRIV,
- );
- }
-
- /**
- * Return an array describing the path elements of the folder.
- *
- * @param string $name The name of the folder.
- * @param array $namespace The namespace of the folder.
- *
- * @return array The path elements.
- */
- protected function _subpath($name, array $namespace)
- {
- $name = Horde_String::convertCharset($name, 'UTF7-IMAP', $this->_charset);
- $path = explode($namespace['delimiter'], $name);
- if ($path[0] == $namespace['namespace']) {
- array_shift($path);
- }
- if ($namespace['type'] == self::OTHER) {
- array_shift($path);
- }
- if (!empty($this->_sharedPrefix)
- && $namespace['type'] == self::SHARED) {
- if (strpos($path[0], $this->_sharedPrefix) === 0) {
- $path[0] = substr($path[0], strlen($this->_sharedPrefix));
- }
+ && $namespace->getType() != self::OTHER)) {
+ array_unshift($path, $this->_primaryPersonalNamespace->getName());
+ $namespace = $this->_primaryPersonalNamespace;
}
- //@todo: What about the potential trailing domain?
- return $path;
+ return Horde_String::convertCharset($namespace->generateName($path), $this->_charset, 'UTF7-IMAP');
}
}
\ No newline at end of file
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'];
+ parent::__construct();
+ foreach ($configuration as $element) {
+ if ($element['type'] == Horde_Kolab_Storage_Namespace::SHARED
+ && isset($element['prefix'])) {
+ $namespace_element = new Horde_Kolab_Storage_Namespace_Element_SharedWithPrefix(
+ $element['name'], $element['delimiter'], $element['prefix']
+ );
+ $this->_sharedPrefix = $element['prefix'];
+ } else {
+ $class = 'Horde_Kolab_Storage_Namespace_Element_' . ucfirst($element['type']);
+ $namespace_element = new $class($element['name'], $element['delimiter']);
+ }
+ if (empty($element['name'])) {
+ $this->_any = $namespace_element;
+ } else {
+ $this->_namespaces[] = $namespace_element;
+ }
+ if (isset($element['add'])) {
+ $this->_primaryPersonalNamespace = $namespace_element;
+ }
}
- $this->_charset = Horde_Nls::getCharset();
}
}
\ No newline at end of file
--- /dev/null
+<?php
+
+abstract class Horde_Kolab_Storage_Namespace_Element
+{
+ /**
+ * The prefix identifying this namespace.
+ *
+ * @var string
+ */
+ protected $_name;
+
+ /**
+ * The delimiter used for this namespace.
+ *
+ * @var string
+ */
+ protected $_delimiter;
+
+ /**
+ * Constructor.
+ *
+ * @param string $name The prefix identifying this namespace.
+ * @param string $delimiter The delimiter used for this namespace.
+ */
+ public function __construct($name, $delimiter)
+ {
+ $this->_name = $name;
+ $this->_delimiter = $delimiter;
+ }
+
+ /**
+ * Return the type of this namespace (private, other, or shared).
+ *
+ * @return string The type.
+ */
+ abstract public function getType();
+
+ /**
+ * Return the name of this namespace.
+ *
+ * @return string The name/prefix.
+ */
+ public function getName()
+ {
+ return $this->_name;
+ }
+
+ /**
+ * Does the folder name lie in this namespace?
+ *
+ * @param string $name The name of the folder.
+ *
+ * @return boolean True if the folder is element of this namespace.
+ */
+ public function matches($name)
+ {
+ return (strpos($name, $this->_name) === 0);
+ }
+
+ /**
+ * Return the owner of a folder.
+ *
+ * @param string $name The name of the folder.
+ *
+ * @return string The owner of the folder.
+ */
+ abstract public function getOwner($name);
+
+ /**
+ * Return the title of a folder.
+ *
+ * @param string $name The name of the folder.
+ *
+ * @return string The title of the folder.
+ */
+ public function getTitle($name)
+ {
+ return join($this->_subpath($name), ':');
+ }
+
+ /**
+ * Get the sub path for the given folder name.
+ *
+ * @param string $name The folder name.
+ *
+ * @return string The sub path.
+ */
+ public function getSubpath($name)
+ {
+ return join($this->_subpath($name), $this->_delimiter);
+ }
+
+ /**
+ * Return an array describing the path elements of the folder.
+ *
+ * @param string $name The name of the folder.
+ *
+ * @return array The path elements.
+ */
+ protected function _subpath($name)
+ {
+ $path = explode($this->_delimiter, $name);
+ if ($path[0] == $this->_name) {
+ array_shift($path);
+ }
+ //@todo: What about the potential trailing domain?
+ return $path;
+ }
+
+ /**
+ * Generate a folder path for the given path in this namespace.
+ *
+ * @param array $path The path of the folder.
+ *
+ * @return string The name of the folder.
+ */
+ public function generateName($path)
+ {
+ return join($path, $this->_delimiter);
+ }
+
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+class Horde_Kolab_Storage_Namespace_Element_Other
+extends Horde_Kolab_Storage_Namespace_Element
+{
+ /**
+ * Return the type of this namespace (private, other, or shared).
+ *
+ * @return string The type.
+ */
+ public function getType()
+ {
+ return Horde_Kolab_Storage_Namespace::OTHER;
+ }
+
+ /**
+ * Return the owner of a folder.
+ *
+ * @param string $name The name of the folder.
+ *
+ * @return string The owner of the folder.
+ */
+ public function getOwner($name)
+ {
+ $path = explode($this->_delimiter, $name);
+ $user = $path[1];
+ $domain = strstr(array_pop($path), '@');
+ if (!empty($domain)) {
+ $user .= $domain;
+ }
+ return Horde_Kolab_Storage_Namespace::OTHER . ':' . $user;
+ }
+
+ /**
+ * Return an array describing the path elements of the folder.
+ *
+ * @param string $name The name of the folder.
+ *
+ * @return array The path elements.
+ */
+ protected function _subpath($name)
+ {
+ $path = parent::_subpath($name);
+ array_shift($path);
+ return $path;
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+class Horde_Kolab_Storage_Namespace_Element_Private
+extends Horde_Kolab_Storage_Namespace_Element
+{
+ /**
+ * Return the type of this namespace (private, other, or shared).
+ *
+ * @return string The type.
+ */
+ public function getType()
+ {
+ return Horde_Kolab_Storage_Namespace::PRIV;
+ }
+
+ /**
+ * Return the owner of a folder.
+ *
+ * @param string $name The name of the folder.
+ *
+ * @return string The owner of the folder.
+ */
+ public function getOwner($name)
+ {
+ return Horde_Kolab_Storage_Namespace::PRIV;
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+class Horde_Kolab_Storage_Namespace_Element_Shared
+extends Horde_Kolab_Storage_Namespace_Element
+{
+ /**
+ * Return the type of this namespace (private, other, or shared).
+ *
+ * @return string The type.
+ */
+ public function getType()
+ {
+ return Horde_Kolab_Storage_Namespace::SHARED;
+ }
+
+ /**
+ * Return the owner of a folder.
+ *
+ * @param string $name The name of the folder.
+ *
+ * @return string The owner of the folder.
+ */
+ public function getOwner($name)
+ {
+ return Horde_Kolab_Storage_Namespace::SHARED;
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+class Horde_Kolab_Storage_Namespace_Element_SharedWithPrefix
+extends Horde_Kolab_Storage_Namespace_Element_Shared
+{
+ /**
+ * The prefix to hide when referencing this namespace.
+ *
+ * @var string
+ */
+ protected $_prefix;
+
+ /**
+ * Constructor.
+ *
+ * @param string $name The prefix identifying this namespace.
+ * @param string $delimiter The delimiter used for this namespace.
+ * @param string $prefix The prefix to hide.
+ */
+ public function __construct($name, $delimiter, $prefix)
+ {
+ parent::__construct($name, $delimiter);
+ $this->_prefix = $prefix;
+ }
+
+ /**
+ * Return an array describing the path elements of the folder.
+ *
+ * @param string $name The name of the folder.
+ *
+ * @return array The path elements.
+ */
+ protected function _subpath($name)
+ {
+ $path = parent::_subpath($name);
+ if (strpos($path[0], $this->_prefix) === 0) {
+ $path[0] = substr($path[0], strlen($this->_prefix));
+ }
+ return $path;
+ }
+}
\ No newline at end of file
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 = 'shared.';
-
- /**
* Indicates the personal namespace that the class will use to create new
* folders.
*
*/
public function __construct()
{
- $this->_charset = Horde_Nls::getCharset();
+ parent::__construct();
+
+ $priv = new Horde_Kolab_Storage_Namespace_Element_Private('INBOX', '/');
+ $other = new Horde_Kolab_Storage_Namespace_Element_Other('user', '/');
+ $shared = new Horde_Kolab_Storage_Namespace_Element_SharedWithPrefix('', '/', 'shared.');
+
+ $this->_namespaces = array($priv, $other);
+ $this->_any = $shared;
+ $this->_primaryPersonalNamespace = $priv;
+ $this->_sharedPrefix = 'shared.';
}
}
\ No newline at end of file
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
class Horde_Kolab_Storage_Namespace_Imap
-extends Horde_Kolab_Storage_Namespace
+extends Horde_Kolab_Storage_Namespace_Config
{
/**
- * 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)
{
+ $c = array();
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'];
+ if (in_array($namespace['name'], array_keys($configuration))) {
+ $namespace = array_merge($namespace, $configuration[$namespace['name']]);
+ }
+ $c[] = $namespace;
}
- $this->_charset = Horde_Nls::getCharset();
+ parent::__construct($c);
}
}
\ No newline at end of file
<file name="Namespace.php" role="php" />
<dir name="Namespace">
<file name="Config.php" role="php" />
+ <file name="Element.php" role="php" />
+ <dir name="Element">
+ <file name="Other.php" role="php" />
+ <file name="Private.php" role="php" />
+ <file name="Shared.php" role="php" />
+ <file name="SharedWithPrefix.php" role="php" />
+ </dir> <!-- /lib/Horde/Kolab/Storage/Element -->
<file name="Fixed.php" role="php" />
<file name="Imap.php" role="php" />
</dir> <!-- /lib/Horde/Kolab/Storage/Namespace -->
<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/Namespace/Config.php" name="lib/Horde/Kolab/Storage/Namespace/Config.php" />
+ <install as="Horde/Kolab/Storage/Namespace/Element.php" name="lib/Horde/Kolab/Storage/Namespace/Element.php" />
+ <install as="Horde/Kolab/Storage/Namespace/Element/Other.php" name="lib/Horde/Kolab/Storage/Namespace/Element/Other.php" />
+ <install as="Horde/Kolab/Storage/Namespace/Element/Private.php" name="lib/Horde/Kolab/Storage/Namespace/Element/Private.php" />
+ <install as="Horde/Kolab/Storage/Namespace/Element/Shared.php" name="lib/Horde/Kolab/Storage/Namespace/Element/Shared.php" />
+ <install as="Horde/Kolab/Storage/Namespace/Element/SharedWithPrefix.php" name="lib/Horde/Kolab/Storage/Namespace/Element/SharedWithPrefix.php" />
<install as="Horde/Kolab/Storage/Namespace/Fixed.php" name="lib/Horde/Kolab/Storage/Namespace/Fixed.php" />
<install as="Horde/Kolab/Storage/Namespace/Imap.php" name="lib/Horde/Kolab/Storage/Namespace/Imap.php" />
<install as="Horde/Kolab/Storage/Permission.php" name="lib/Horde/Kolab/Storage/Permission.php" />
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(
- '' => '/',
- ),
+ array(
+ 'type' => Horde_Kolab_Storage_Namespace::PRIV,
+ 'name' => 'INBOX',
+ 'delimiter' => '/',
+ 'add' => true,
+ ),
+ array(
+ 'type' => Horde_Kolab_Storage_Namespace::OTHER,
+ 'name' => 'user',
+ 'delimiter' => '/',
+ ),
+ array(
+ 'type' => Horde_Kolab_Storage_Namespace::SHARED,
+ 'name' => '',
+ 'delimiter' => '/',
+ 'prefix' => 'shared.'
),
- 'shared_prefix' => 'shared.',
- 'add_namespace' => 'INBOX',
)
),
new Horde_Kolab_Storage_Namespace_Imap(
),
),
array(
- 'shared_prefix' => 'shared.',
- 'add_namespace' => 'INBOX',
+ 'INBOX' => array(
+ 'add' => true,
+ ),
+ '' => array(
+ 'prefix' => 'shared.',
+ ),
)
),