/usr/share/php/Horde/Kolab/Storage/Driver/Pear.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 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | <?php
/**
* Copyright 2010-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
* @deprecated This class is not maintained and will be removed in future
* releases.
*/
/**
* An PEAR-Net_Imap based Kolab storage driver.
*
* @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
*/
class Horde_Kolab_Storage_Driver_Pear
extends Horde_Kolab_Storage_Driver_Base
{
/**
* Create the backend driver.
*
* @return mixed The backend driver.
*/
public function createBackend()
{
$config = $this->getParams();
if (isset($config['secure']) && $config['secure'] == 'ssl') {
$prefix = 'ssl://';
} else {
$prefix = '';
}
$client = new Net_IMAP(
$prefix . $config['host'],
$config['port'],
isset($config['secure']) && $config['secure'] == 'tls'
);
$client->_useUTF_7 = false;
if (isset($config['debug'])) {
if ($config['debug'] == 'STDOUT') {
$client->setDebug(true);
} else {
throw new Horde_Kolab_Storage_Exception('This driver does not support debug logging into a file.');
}
}
Horde_Kolab_Storage_Exception_Pear::catchError(
$client->login($config['username'], $config['password'], true, false)
);
return $client;
}
/**
* Retrieves a list of folders on the server.
*
* @return array The list of folders.
*/
public function listFolders()
{
$list = Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->getMailboxes()
);
return $this->decodeList($list);
}
/**
* Create the specified folder.
*
* @param string $folder The folder to create.
*
* @return NULL
*/
public function create($folder)
{
Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->createMailbox($this->encodePath($folder))
);
}
/**
* Delete the specified folder.
*
* @param string $folder The folder to delete.
*
* @return NULL
*/
public function delete($folder)
{
Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->deleteMailbox($this->encodePath($folder))
);
}
/**
* Rename the specified folder.
*
* @param string $old The folder to rename.
* @param string $new The new name of the folder.
*
* @return NULL
*/
public function rename($old, $new)
{
Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->renameMailbox(
$this->encodePath($old),
$this->encodePath($new)
)
);
}
/**
* Does the backend support ACL?
*
* @return boolean True if the backend supports ACLs.
*/
public function hasAclSupport()
{
return $this->getBackend()->hasCapability('ACL');
}
/**
* Retrieve the access rights for a folder.
*
* @param string $folder The folder to retrieve the ACL for.
*
* @return array An array of rights.
*/
public function getAcl($folder)
{
$result = Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->getACL($this->encodePath($folder))
);
$acl = array();
foreach ($result as $user) {
$acl[$user['USER']] = $user['RIGHTS'];
}
return $acl;
}
/**
* Retrieve the access rights the current user has on a folder.
*
* @param string $folder The folder to retrieve the user ACL for.
*
* @return string The user rights.
*/
public function getMyAcl($folder)
{
return Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->getMyRights($this->encodePath($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)
{
Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->setACL($this->encodePath($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)
{
Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->deleteACL($this->encodePath($folder), $user)
);
}
/**
* Retrieves the specified annotation for the complete list of folders.
*
* @param string $annotation The name of the annotation to retrieve.
*
* @return array An associative array combining the folder names as key with
* the corresponding annotation value.
*/
public function listAnnotation($annotation)
{
list($entry, $value) = $this->_getAnnotateMoreEntry($annotation);
$list = array();
$result = Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->getAnnotation($entry, $value, '*')
);
foreach ($result as $element) {
if (isset($element['ATTRIBUTES'][$value])) {
$list[$element['MAILBOX']] = $element['ATTRIBUTES'][$value];
}
}
return $this->decodeListKeys($list);
}
/**
* Fetches the annotation from a folder.
*
* @param string $folder The name of the folder.
* @param string $annotation The annotation to get.
*
* @return string The annotation value.
*/
public function getAnnotation($folder, $annotation)
{
list($entry, $type) = $this->_getAnnotateMoreEntry($annotation);
$result = Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->getAnnotation(
$entry, $type, $this->encodePath($folder)
)
);
foreach ($result as $element) {
if (isset($element['ATTRIBUTES'][$type])) {
return $element['ATTRIBUTES'][$type];
}
}
return '';
}
/**
* Sets the annotation on a folder.
*
* @param string $folder The name of the folder.
* @param string $annotation The annotation to set.
* @param array $value The values to set
*
* @return NULL
*/
public function setAnnotation($folder, $annotation, $value)
{
list($entry, $type) = $this->_getAnnotateMoreEntry($annotation);
Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->setAnnotation(
$entry, array($type => $value), $this->encodePath($folder)
)
);
}
/**
* Retrieve the namespace information for this connection.
*
* @return Horde_Kolab_Storage_Driver_Namespace The initialized namespace handler.
*/
public function getNamespace()
{
if ($this->getBackend()->hasCapability('NAMESPACE') === true) {
$namespaces = array();
foreach ($this->getBackend()->getNamespace() as $type => $elements) {
foreach ($elements as $namespace) {
switch ($type) {
case 'others':
$namespace['type'] = 'other';
break;
default:
$namespace['type'] = $type;
break;
}
$namespace['delimiter'] = $namespace['delimter'];
$namespaces[] = $namespace;
}
}
return new Horde_Kolab_Storage_Folder_Namespace_Imap(
$this->getAuth(),
$namespaces,
$this->getParam('namespaces', array())
);
}
return parent::getNamespace();
}
/**
* Opens the given folder.
*
* @param string $folder The folder to open
*
* @return NULL
*/
public function select($folder)
{
Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->selectMailbox($this->encodePath($folder))
);
}
/**
* Returns the status of the current folder.
*
* @param string $folder Check the status of this folder.
*
* @return array An array that contains 'uidvalidity', 'uidnext', and
* 'token'.
*/
public function status($folder)
{
$result = Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->getStatus($this->encodePath($folder))
);
return array(
'uidvalidity' => $result['UIDVALIDITY'],
'uidnext' => $result['UIDNEXT'],
'token' => false
);
}
/**
* 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)
{
$this->select($folder);
$uids = Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->search('UNDELETED', true)
);
if (!is_array($uids)) {
$uids = array();
}
return $uids;
}
/**
* Retrieves a complete message.
*
* @param string $folder The folder to fetch the messages from.
* @param array $uid The message UID.
*
* @return array The message encapsuled as an array that contains a
* Horde_Mime_Headers and a Horde_Mime_Part object.
*/
public function fetchComplete($folder, $uid)
{
$this->select($folder);
return array(
Horde_Mime_Headers::parseHeaders(
Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->getRawHeaders($uid, '', true)
)
),
Horde_Mime_Part::parseMessage(
Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->getBody($uid, true)
)
)
);
}
/**
* Retrieves the messages for the given message ids.
*
* @param string $folder The folder to fetch the messages from.
* @param array $uids The message UIDs.
*
* @return array An array of message structures parsed into Horde_Mime_Part
* instances.
*/
public function fetchStructure($folder, $uids)
{
$result = array();
$this->select($folder);
foreach ($uids as $uid) {
$structure = Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->getStructure($uid, true)
);
$ob = $this->_parseStructure($structure);
$ob->buildMimeIds();
$result[$uid]['structure'] = $ob;
}
return $result;
}
/**
* Retrieves a bodypart for the given message ID and mime part ID.
*
* @param string $folder The folder to fetch the messages from.
* @param array $uid The message UID.
* @param array $id The mime part ID.
*
* @return resource The body part, as a stream resource.
*/
public function fetchBodypart($folder, $uid, $id)
{
$this->select($folder);
return Horde_Stream_Wrapper_String::getStream(
Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->getBodyPart($uid, $id, true)
)
);
}
/**
* Appends a message to the given folder.
*
* @param string $folder The folder to append the message(s) to.
* @param resource $msg The message to append.
*
* @return mixed True or the UID of the new message in case the backend
* supports UIDPLUS.
*/
public function appendMessage($folder, $msg)
{
rewind($msg);
$this->select($folder);
return Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->appendMessage(stream_get_contents($msg))
);
}
/**
* Deletes messages from the specified folder.
*
* @param string $folder The folder to delete messages from.
* @param integer $uids IMAP message ids.
*
* @return NULL
*/
public function deleteMessages($folder, $uids)
{
$this->select($folder);
return Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->deleteMessages($uids, true)
);
}
/**
* Moves a message to a new folder.
*
* @param integer $uid IMAP message id.
* @param string $old_folder Source folder.
* @param string $new_folder Target folder.
*
* @return NULL
*/
public function moveMessage($uid, $old_folder, $new_folder)
{
$this->select($old_folder);
Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->copyMessage($uid, $new_folder)
);
$this->deleteMessages($old_folder, array($uid));
$this->expunge($old_folder);
}
/**
* Expunges messages in the current folder.
*
* @return mixed True or a PEAR error in case of an error.
*/
public function expunge($folder)
{
$this->select($folder);
return Horde_Kolab_Storage_Exception_Pear::catchError(
$this->getBackend()->expunge()
);
}
/**
* Parse the output from imap_fetchstructure() into a MIME Part object.
*
* @param object $data Data from imap_fetchstructure().
*
* @return Horde_Mime_Part A MIME Part object.
*/
protected function _parseStructure($data)
{
$ob = new Horde_Mime_Part();
$ob->setType(Horde_String::lower($data->type) . '/' . Horde_String::lower($data->subType));
// Optional for multipart-parts, required for all others
if (isset($data->parameters)) {
$params = array();
foreach ($data->parameters as $key => $value) {
$params[Horde_String::lower($key)] = $value;
}
$params = Horde_Mime::decodeParam('content-type', $params);
foreach ($params['params'] as $key => $value) {
$ob->setContentTypeParameter($key, $value);
}
}
// Optional entries. 'location' and 'language' not supported
if (isset($data->disposition)) {
$ob->setDisposition($data->disposition);
if (isset($data->dparameters)) {
$dparams = array();
foreach ($data->dparameters as $key => $value) {
$dparams[Horde_String::lower($key)] = $value;
}
$dparams = Horde_Mime::decodeParam('content-disposition', $dparams);
foreach ($dparams['params'] as $key => $value) {
$ob->setDispositionParameter($key, $value);
}
}
}
if ($ob->getPrimaryType() == 'multipart') {
// multipart/* specific entries
foreach ($data->subParts as $val) {
$ob->addPart($this->_parseStructure($val));
}
} else {
// Required options
if (isset($data->partID)) {
$ob->setContentId($data->partID);
}
$ob->setTransferEncoding(Horde_String::lower($data->encoding));
$ob->setBytes($data->bytes);
if ($ob->getType() == 'message/rfc822') {
$ob->addPart($this->_parseStructure(reset($data->subParts)));
}
}
return $ob;
}
}
|