Source for file kolab.php
Documentation is available at kolab.php
/** We need the Kolab Storage library for accessing the server. */
require_once 'Horde/Kolab/Storage/List.php';
* VFS implementation for a Kolab IMAP server.
* $Horde: framework/VFS/lib/VFS/kolab.php,v 1.1.2.3 2009/01/06 15:23:47 jan Exp $
* Copyright 2002-2009 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.
* @author Gunnar Wrobel <wrobel@pardus.de>
* Variable holding the connection to the Kolab storage system.
* Cache for the list of folders.
* Retrieves a file from the VFS.
* @param string $path The pathname to the file.
* @param string $name The filename to retrieve.
* @return string The file data.
function read($path, $name)
list ($app, $uid) = $this->_getAppUid ($path);
$handler = &$this->_getAppHandler ($app, $uid);
if (is_a($handler, 'PEAR_Error')) {
$object = $handler->getObject ($uid);
if (isset ($object['_attachments'][$name])) {
return $handler->getAttachment ($object['_attachments'][$name]['key']);
$session = &Horde_Kolab_Session ::singleton ();
$imap = &$session->getImap ();
$result = $imap->select (substr($path,1 ));
if (is_a($result, 'PEAR_Error')) {
return $this->_getFile ($imap, $file[0 ], $file[1 ]);
* Stores a file in the VFS.
* @param string $path The path to store the file in.
* @param string $name The filename to use.
* @param string $tmpFile The temporary file containing the data to
* @param boolean $autocreate Automatically create directories?
* @return mixed True on success or a PEAR_Error object on failure.
function write($path, $name, $tmpFile, $autocreate = false )
list ($app, $uid) = $this->_getAppUid ($path);
$handler = &$this->_getAppHandler ($app, $uid);
if (is_a($handler, 'PEAR_Error')) {
$object = $handler->getObject ($uid);
$object['_attachments'][$name]['path'] = $tmpFile;
if (empty ($object['link-attachment'])) {
$object['link-attachment'] = array ($name);
$object['link-attachment'][] = $name;
return $handler->save ($object, $uid);
if (is_a($result, 'PEAR_Error')) {
return PEAR ::raiseError (_("Not supported."));
* Deletes a file from the VFS.
* @param string $path The path to delete the file from.
* @param string $name The filename to delete.
* @return mixed True on success or a PEAR_Error object on failure.
list ($app, $uid) = $this->_getAppUid ($path);
$handler = &$this->_getAppHandler ($app, $uid);
if (is_a($handler, 'PEAR_Error')) {
$object = $handler->getObject ($uid);
if (!isset ($object['_attachments'][$name])) {
return PEAR ::raiseError (_("Unable to delete VFS file."));
unset ($object['_attachments'][$name]);
return $handler->save ($object, $uid);
return PEAR ::raiseError (_("Not supported."));
* Creates a folder on the VFS.
* @param string $path The parent folder.
* @param string $name The name of the new folder.
* @return mixed True on success or a PEAR_Error object on failure.
$list = Kolab_List ::singleton ();
$folder = $this->_getFolder ($path, $name);
$object = $list->getNewFolder ();
$object->setName ($folder);
$result = $object->save (array ('type' => 'h-file'));
if (is_a($result, 'PEAR_Error')) {
* Deletes a folder from the VFS.
* @param string $path The parent folder.
* @param string $name The name of the folder to delete.
* @param boolean $recursive Force a recursive delete?
* @return mixed True on success or a PEAR_Error object on failure.
if (is_a($result, 'PEAR_Error')) {
$list = $this->listFolder($path . '/' . $name, null , false );
if (is_a($list, 'PEAR_Error')) {
return PEAR ::raiseError (sprintf(_("Unable to delete %s, the directory is not empty"),
list ($app, $uid) = $this->_getAppUid ($path . '/' . $name);
* Objects provide no real folders and we don't delete them.
$folders = $this->_getFolders ();
if (is_a($folders, 'PEAR_Error')) {
$folder = $this->_getFolder ($path, $name);
if (!empty ($folders['/' . $folder])) {
$result = $folders['/' . $folder]->delete ();
if (is_a($result, 'PEAR_Error')) {
return PEAR ::raiseError (sprintf('No such folder %s!', '/' . $folder));
* Recursively remove all files and subfolders from the given
* @param string $path The path of the folder to empty.
* @return mixed True on success or a PEAR_Error object on failure.
// Get and delete the subfolders.
$list = $this->listFolder($path, null , false , true );
if (is_a($list, 'PEAR_Error')) {
foreach ($list as $folder) {
$result = $this->deleteFolder($path, $folder['name'], true );
if (is_a($result, 'PEAR_Error')) {
// Only files are left, get and delete them.
if (is_a($list, 'PEAR_Error')) {
foreach ($list as $file) {
$result = $this->deleteFile($path, $file['name']);
if (is_a($result, 'PEAR_Error')) {
* Returns an an unsorted file list of the specified directory.
* @param string $path The path of the directory.
* @param mixed $filter String/hash to filter file/dirname on.
* @param boolean $dotfiles Show dotfiles?
* @param boolean $dironly Show only directories?
* @return array File list on success or PEAR_Error on failure.
function _listFolder ($path = '', $filter = null , $dotfiles = true ,
list ($app, $uid) = $this->_getAppUid ($path);
* Objects dont support directories.
$handler = &$this->_getAppHandler ($app, $uid);
if (is_a($handler, 'PEAR_Error')) {
$object = $handler->getObject ($uid);
if (is_a($object, 'PEAR_Error')) {
$filenames = isset ($object['_attachments']) ? array_keys($object['_attachments']) : array ();
$filenames = $this->_getAppUids ($app);
$owner = Auth ::getAuth ();
foreach($filenames as $filename) {
$file['type'] = '**none';
$file['name'] = $filename;
$file['perms'] = 'rwxrwx---';
$files[$file['name']] = $file;
$owner = Auth ::getAuth ();
$folders = $this->listFolders($path, $filter, $dotfiles);
if (is_a($folders, 'PEAR_Error')) {
$list = $this->_getFolders ();
foreach ($folders as $folder) {
$file['name'] = $folder['abbrev'];
$file['perms'] = 'rwxrwx---';
$files[$file['name']] = $file;
&& !empty ($list[$path])) {
$session = &Horde_Kolab_Session ::singleton ();
$imap = &$session->getImap ();
$result = $imap->select (substr($path, 1 ));
if (is_a($result, 'PEAR_Error')) {
$uids = $imap->getUids ();
if (is_a($uids, 'PEAR_Error')) {
foreach ($uids as $uid) {
$mFiles = $this->_parseMessage ($imap, $uid);
if (is_a($mFiles, 'PEAR_Error')) {
function _parseMessage ($imap, $uid)
$result = $imap->getMessageHeader ($uid);
if (is_a($result, 'PEAR_Error')) {
$body = $imap->getMessageBody ($uid);
if (is_a($body, 'PEAR_Error')) {
$raw_message = $raw_headers . $body;
$mime_message = &MIME_Structure ::parseTextMIMEMessage ($raw_message);
$parts = $mime_message->contentTypeMap ();
$owner = Auth ::getAuth ();
foreach ($parts as $part_id => $disposition) {
$part = $mime_message->getPart ($part_id);
$filename = $part->getDispositionParameter ('filename');
$file['type'] = '**file';
$file['size'] = $part->getSize ();
$file['name'] = $uid . '/' . $filename;
$file['perms'] = 'rwxrwx---';
$files[$file['name']] = $file;
function _getFile ($imap, $uid, $filename)
$result = $imap->getMessageHeader ($uid);
if (is_a($result, 'PEAR_Error')) {
$body = $imap->getMessageBody ($uid);
if (is_a($body, 'PEAR_Error')) {
$raw_message = $raw_headers . $body;
$mime_message = &MIME_Structure ::parseTextMIMEMessage ($raw_message);
$parts = $mime_message->contentTypeMap ();
$owner = Auth ::getAuth ();
foreach ($parts as $part_id => $disposition) {
$part = $mime_message->getPart ($part_id);
$f= $part->getDispositionParameter ('filename');
if ($f && $f == $filename ) {
return $part->transferDecode ();
* Returns a sorted list of folders in the specified directory.
* @param string $path The path of the directory to get the
* @param mixed $filter Hash of items to filter based on folderlist.
* @param boolean $dotfolders Include dotfolders?
* @return mixed Folder list on success or a PEAR_Error object on failure.
function listFolders($path = '', $filter = null , $dotfolders = true )
if (substr($path, -1 ) != '/') {
if ($dotfolders && $path != '/') {
$aFolder['abbrev'] = '..';
$aFolder['label'] = '..';
$aFolders[$aFolder['val']] = $aFolder;
$folders = $this->_getFolders ();
if (substr($folder, 0 , $base_len) == $path) {
$name = substr($folder, $base_len);
$aFolder['val'] = $folder;
$aFolder['abbrev'] = $name;
$aFolder['label'] = $folder;
$aFolders[$aFolder['val']] = $aFolder;
function _getFolder ($path, $name)
$folder = $path . '/' . $name;
while (substr($folder, 0 , 1 ) == '/') {
while (substr($folder, -1 ) == '/') {
$folder = substr($folder, 0 , -1 );
if (!isset ($this->_folders)) {
$list = Kolab_List ::singleton ();
if (!empty ($this->_params['all_folders'])) {
$folders = $list->getFolders ();
$folders = $list->getByType ('h-file');
if (is_a($folders, 'PEAR_Error')) {
foreach ($folders as $folder) {
$vfs_folders['/' . $folder->name ] = &$folder;
if (!isset ($vfs_folders[$dir])) {
$vfs_folders[$dir] = null;
$this->_folders = $vfs_folders;
function _getAppUid ($path)
&& substr($path, 0 , strlen(TURBA_VFS_PATH )) == TURBA_VFS_PATH ) {
return array ('turba', substr($path, strlen(TURBA_VFS_PATH ) + 1 ));
return array (false , false );
function &_getAppHandler ($app, $uid)
$sources = $registry->call ('contacts/sources',
array ('writeable' => true ));
$fields[$source] = array ('__uid');
$result = $registry->call ('contacts/search',
if (!isset ($result[$uid])) {
return PEAR ::raiseError ('No such contact!');
$list = Kolab_List ::singleton ();
$share = &$list->getByShare ($result[$uid][0 ]['source'], 'contact');
if (is_a($share, 'PEAR_Error')) {
return $share->getData ();
function _getAppUids ($app)
$sources = $registry->call ('contacts/sources',
array ('writeable' => true ));
$result = $registry->call ('contacts/search',
foreach ($result[''] as $contact) {
if (isset ($contact['__uid'])) {
$uids[] = $contact['__uid'];
* Connecting is not required for this driver.
Documentation generated on Mon, 11 Mar 2019 15:34:54 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|