/usr/share/php/Horde/Kolab/Storage/Folder/Namespace.php is in php-horde-kolab-storage 2.2.1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | <?php
/**
* The Horde_Kolab_Storage_Folder_Namespace:: class handles IMAP namespaces and allows
* to derive folder information from folder names.
*
* PHP version 5
*
* @category Kolab
* @package Kolab_Storage
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
/**
* The Horde_Kolab_Storage_Folder_Namespace:: class handles IMAP namespaces and allows
* to derive folder information from folder names.
*
* Copyright 2004-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Kolab
* @package Kolab_Storage
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Kolab_Storage
*/
abstract class Horde_Kolab_Storage_Folder_Namespace
implements IteratorAggregate, Serializable
{
/** The possible namespace types (RFC 2342 [5]) */
const PERSONAL = 'personal';
const OTHER = 'other';
const SHARED = 'shared';
/**
* The current user.
*
* @var string
*/
protected $user;
/**
* The namespaces.
*
* @var array
*/
private $_namespaces = array();
/**
* The namespaces with a defined prefix.
*
* @var array
*/
private $_prefix_namespaces = array();
/**
* The fallback namespace matching any path if no other namesace matches.
*
* @var Horde_Kolab_Storage_Folder_Namespace_Element
*/
private $_any;
/**
* Constructor.
*
* @param array $namespaces The namespaces.
*/
public function __construct(array $namespaces)
{
$this->initialize($namespaces);
}
/**
* Initialize the class with a set of namespace configurations.
*
* @param array $namespaces The namespaces.
*
* @return NULL
*/
protected function initialize(array $namespaces)
{
$this->_namespaces = $namespaces;
foreach ($this->_namespaces as $namespace) {
if ($namespace->getName() == '') {
$this->_any = $namespace;
} else {
$this->_prefix_namespaces[] = $namespace;
}
}
}
/**
* Match a folder name with the corresponding namespace.
*
* @param string $name The name of the folder.
*
* @return Horde_Kolab_Storage_Folder_Namespace_Element The corresponding namespace.
*
* @throws Horde_Kolab_Storage_Exception If the namespace of the folder
* cannot be determined.
*/
public function matchNamespace($name)
{
foreach ($this->_prefix_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)
);
}
/**
* 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 $this->matchNamespace($name)->getOwner($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 $this->matchNamespace($name)->getSubpath($name);
}
/**
* Get the parent for the given folder name.
*
* @param string $name The parent folder name.
*
* @return string The parent.
*/
public function getParent($name)
{
return $this->matchNamespace($name)->getParent($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 $this->matchNamespace($name)->getTitle($name);
}
/**
* Construct the Kolab storage folder name based on the folder
* title and the owner.
*
* @param string $owner The owner of the folder.
* @param string $subpath The folder subpath.
* @param string $prefix The namespace prefix.
*
* @return string The folder name for the backend.
*/
public function constructFolderName($owner, $subpath, $prefix = null)
{
if (empty($owner)) {
return $this->_getNamespace(self::SHARED, $prefix)
->generatePath($subpath, $owner);
} else if ($owner == $this->user) {
return $this->_getNamespace(self::PERSONAL, $prefix)
->generatePath($subpath, $owner);
} else {
return $this->_getNamespace(self::OTHER, $prefix)
->generatePath($subpath, $owner);
}
}
/**
* Generate an IMAP folder name in the personal namespace.
*
* @param string $title The new folder title.
*
* @return string The IMAP folder name.
*/
public function setTitle($title)
{
return $this->_getNamespace(self::PERSONAL)
->generateName(explode(':', $title));
}
/**
* Generate an IMAP folder name in the other namespace.
*
* @param string $title The new folder title.
* @param string $owner The new owner of the folder.
*
* @return string The IMAP folder name.
*/
public function setTitleInOther($title, $owner)
{
$path = explode(':', $title);
array_unshift($path, $owner);
return $this->_getNamespace(self::OTHER)->generateName($path);
}
/**
* Generate an IMAP folder name in the shared namespace.
*
* @param string $title The new folder title.
*
* @return string The IMAP folder name.
*/
public function setTitleInShared($title)
{
return $this->_getNamespace(self::SHARED)
->generateName(explode(':', $title));
}
/**
* Get the namespace matching the given type and (optional) prefix.
*
* @param string $type The namespace type.
* @param string $prefix The namespace prefix
*
* @return Horde_Kolab_Storage_Folder_Namespace_Element The namespace.
*/
private function _getNamespace($type, $prefix = null)
{
$matching = array();
foreach ($this->_namespaces as $namespace) {
if ($namespace->getType() == $type &&
($prefix === null || $namespace->getName() === $prefix)) {
$matching[] = $namespace;
}
}
if (count($matching) == 1) {
return $matching[0];
} else if (count($matching) > 1) {
throw new Horde_Kolab_Storage_Exception(
'Multiple namespaces of the same type!'
);
} else {
throw new Horde_Kolab_Storage_Exception(
sprintf(
'No namespace of the type %s%s!',
$type,
($prefix !== null) ? ' with prefix \"' . $prefix . '\"' : ''
)
);
}
}
/**
*/
public function getIterator()
{
return new ArrayIterator($this->_namespaces);
}
/**
* Convert the namespace description to a string.
*
* @return string The namespace description.
*/
public function __toString()
{
return get_class($this) . ': ' . join(', ', $this->_namespaces);
}
}
|