interface Horde_Kolab_Storage_Driver
{
/**
+ * Create the backend driver.
+ *
+ * @return mixed The backend driver.
+ */
+ public function createBackend();
+
+ /**
+ * Returns the actual backend driver.
+ *
+ * If there is no driver set the driver should be constructed within this
+ * method.
+ *
+ * @return mixed The backend driver.
+ */
+ public function getBackend();
+
+ /**
+ * Set the backend driver.
+ *
+ * @param mixed $backend The driver that should be used.
+ *
+ * @return NULL
+ */
+ public function setBackend($backend);
+
+ /**
* Return the id of the user currently authenticated.
*
* @return string The id of the user that opened the connection.
protected $_namespace;
/**
+ * The backend to use.
+ *
+ * @var mixed
+ */
+ private $_backend;
+
+ /**
* Constructor.
*
* @param Horde_Kolab_Storage_Factory $factory A factory for helper objects.
$params = array()
) {
$this->_factory = $factory;
+ if (isset($params['backend'])) {
+ $this->setBackend($params['backend']);
+ }
$this->_params = $params;
}
/**
+ * Returns the actual backend driver.
+ *
+ * If there is no driver set the driver should be constructed within this
+ * method.
+ *
+ * @return mixed The backend driver.
+ */
+ public function getBackend()
+ {
+ if ($this->_backend === null) {
+ $this->_backend = $this->createBackend();
+ }
+ return $this->_backend;
+ }
+
+ /**
+ * Set the backend driver.
+ *
+ * @param mixed $backend The driver that should be used.
+ *
+ * @return NULL
+ */
+ public function setBackend($backend)
+ {
+ $this->_backend = $backend;
+ }
+
+ /**
+ * Return all parameter settings for this connection.
+ *
+ * @return array The parameters.
+ */
+ public function getParams()
+ {
+ return $this->_params;
+ }
+
+ /**
* Return a parameter setting for this connection.
*
* @param string $key The parameter key.
}
/**
+ * Return the id of the user currently authenticated.
+ *
+ * @return string The id of the user that opened the IMAP connection.
+ */
+ public function getAuth()
+ {
+ return $this->getParam('username');
+ }
+
+ /**
+ * Return the unique connection id.
+ *
+ * @return string The connection id.
+ */
+ public function getId()
+ {
+ return $this->getAuth() . '@'
+ . $this->getParam('host') . ':'
+ . $this->getParam('port');
+ }
+
+ /**
* Return the factory.
*
* @return Horde_Kolab_Storage_Factory The factory.
extends Horde_Kolab_Storage_Driver_Base
{
/**
- * IMAP resource.
- *
- * @var resource
- */
- private $_imap;
-
- /**
* Server name.
*
* @var string
private $_base_mbox;
/**
- * Lazy connect to the IMAP server.
+ * Create the backend driver.
*
- * @return resource The IMAP connection.
- *
- * @throws Horde_Kolab_Storage_Exception In case the connection failed.
+ * @return mixed The backend driver.
*/
- private function _getImap()
+ public function createBackend()
{
- if (!isset($this->_imap)) {
- $result = @imap_open(
- $this->_getBaseMbox(),
- $this->getParam('username'),
- $this->getParam('password'),
- OP_HALFOPEN
+ $result = @imap_open(
+ $this->_getBaseMbox(),
+ $this->getParam('username'),
+ $this->getParam('password'),
+ OP_HALFOPEN
+ );
+ if (!$result) {
+ throw new Horde_Kolab_Storage_Exception(
+ sprintf(
+ Horde_Kolab_Storage_Translation::t(
+ "Connecting to server %s failed. Error: %s"
+ ),
+ $this->_getHost(),
+ @imap_last_error()
+ )
);
- if (!$result) {
- throw new Horde_Kolab_Storage_Exception(
- sprintf(
- Horde_Kolab_Storage_Translation::t(
- "Connecting to server %s failed. Error: %s"
- ),
- $this->_getHost(),
- @imap_last_error()
- )
- );
- }
- $this->_imap = $result;
}
- return $this->_imap;
}
/**
}
/**
- * Return the id of the user currently authenticated.
- *
- * @return string The id of the user that opened the IMAP connection.
- */
- public function getAuth()
- {
- return $this->getParam('username');
- }
-
- /**
- * Return the unique connection id.
- *
- * @return string The connection id.
- */
- public function getId()
- {
- return $this->getAuth() . '@' . $this->getParam('host');
- }
-
- /**
* Return the root mailbox of the current user.
*
* @return string The id of the user that opened the IMAP connection.
{
$folders = array();
- $result = @imap_list($this->_getImap(), $this->_getBaseMbox(), '*');
+ $result = @imap_list($this->getBackend(), $this->_getBaseMbox(), '*');
if (!$result) {
throw new Horde_Kolab_Storage_Exception(
sprintf(
list($entry, $value) = $this->_getAnnotateMoreEntry($annotation);
$list = array();
foreach ($this->getMailboxes() as $mailbox) {
- $result = imap_getannotation($this->_getImap(), $mailbox, $entry, $value);
+ $result = imap_getannotation($this->getBackend(), $mailbox, $entry, $value);
if (isset($result[$value])) {
$list[$mailbox] = $result[$value];
}
}
/**
+ * Create the backend driver.
+ *
+ * @return mixed The backend driver.
+ */
+ public function createBackend()
+ {
+ return $this->_driver->createBackend();
+ }
+
+ /**
+ * Returns the actual backend driver.
+ *
+ * If there is no driver set the driver should be constructed within this
+ * method.
+ *
+ * @return mixed The backend driver.
+ */
+ public function getBackend()
+ {
+ return $this->_driver->getBackend();
+ }
+
+ /**
+ * Set the backend driver.
+ *
+ * @param mixed $backend The driver that should be used.
+ *
+ * @return NULL
+ */
+ public function setBackend($backend)
+ {
+ $this->_driver->setBackend($backend);
+ }
+
+ /**
* Return the id of the user currently authenticated.
*
* @return string The id of the user that opened the connection.
}
/**
+ * Create the backend driver.
+ *
+ * @return mixed The backend driver.
+ */
+ public function createBackend()
+ {
+ $this->_logger->info(
+ sprintf('Driver "%s": Creating backend.', $this->getDriverName())
+ );
+ $result = $this->_driver->createBackend();
+ $this->_logger->info(
+ sprintf(
+ 'Driver "%s": Backend successfully created', $this->getDriverName()
+ )
+ );
+ return $result;
+ }
+
+ /**
* Retrieves a list of mailboxes from the server.
*
* @return array The list of mailboxes.
}
/**
+ * Create the backend driver.
+ *
+ * @return mixed The backend driver.
+ */
+ public function createBackend()
+ {
+ $this->_timer->push();
+ $result = parent::createBackend();
+ $this->_logger->info(
+ sprintf(
+ 'REQUEST OUT IMAP: %s ms [construct]',
+ floor($this->_timer->pop() * 1000)
+ )
+ );
+ return $result;
+ }
+
+ /**
* Retrieves a list of mailboxes from the server.
*
* @return array The list of mailboxes.
extends Horde_Kolab_Storage_Driver_Base
{
/**
- * The IMAP connection
+ * Create the backend driver.
*
- * @var Horde_Imap_Client
+ * @return mixed The backend driver.
*/
- private $_imap;
-
- /**
- * Constructor.
- *
- * @param Horde_Imap_Client_Base $imap The IMAP connection handler.
- * @param Horde_Kolab_Storage_Factory $factory A factory for helper objects.
- * @param array $params Connection parameters.
- */
- public function __construct(
- Horde_Imap_Client_Base $imap,
- Horde_Kolab_Storage_Factory $factory,
- $params = array()
- ) {
- $this->_imap = $imap;
- parent::__construct($factory, $params);
- }
-
- /**
- * Return the id of the user currently authenticated.
- *
- * @return string The id of the user that opened the IMAP connection.
- */
- public function getAuth()
+ public function createBackend()
{
- return $this->_imap->getParam('username');
- }
-
- /**
- * Return the unique connection id.
- *
- * @return string The connection id.
- */
- public function getId()
- {
- return $this->getAuth() . '@'
- . $this->_imap->getParam('hostspec') . ':'
- . $this->_imap->getParam('port');
+ $config = $this->getParams();
+ $config['hostspec'] = $config['host'];
+ unset($config['host']);
+ //$config['debug'] = '/tmp/imap.log';
+ if ($config['driver'] = 'horde') {
+ return new Horde_Imap_Client_Socket($config);
+ } else {
+ return new Horde_Imap_Client_Cclient($config);
+ }
}
/**
*/
public function getMailboxes()
{
- return $this->_imap->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array('flat' => true));
+ return $this->getBackend()->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array('flat' => true));
}
/**
*/
public function listAnnotation($annotation)
{
- $result = $this->_imap->getMetadata('*', $annotation);
+ $result = $this->getBackend()->getMetadata('*', $annotation);
$data = array();
foreach ($result as $folder => $annotations) {
if (isset($annotations[$annotation])) {
*/
public function select($folder)
{
- $this->_imap->openMailbox($folder, Horde_Imap_Client::OPEN_AUTO);
+ $this->getBackend()->openMailbox($folder, Horde_Imap_Client::OPEN_AUTO);
return true;
}
*/
public function status($folder)
{
- return $this->_imap->status($folder,
+ return $this->getBackend()->status($folder,
Horde_Imap_Client::STATUS_UIDNEXT
| Horde_Imap_Client::STATUS_UIDVALIDITY);
}
{
$search_query = new Horde_Imap_Client_Search_Query();
$search_query->flag('DELETED', false);
- $uidsearch = $this->_imap->search($folder, $search_query);
+ $uidsearch = $this->getBackend()->search($folder, $search_query);
$uids = $uidsearch['match'];
return $uids;
}
*/
public function create($folder)
{
- return $this->_imap->createMailbox($folder);
+ return $this->getBackend()->createMailbox($folder);
}
/**
*/
public function delete($folder)
{
- return $this->_imap->deleteMailbox($folder);
+ return $this->getBackend()->deleteMailbox($folder);
}
/**
*/
public function rename($old, $new)
{
- return $this->_imap->renameMailbox($old, $new);
+ return $this->getBackend()->renameMailbox($old, $new);
}
/**
*/
public function appendMessage($mailbox, $msg)
{
- return $this->_imap->append($mailbox, array(array('data' => $msg)));
+ return $this->getBackend()->append($mailbox, array(array('data' => $msg)));
}
/**
if (!is_array($uids)) {
$uids = array($uids);
}
- return $this->_imap->store($mailbox, array('add' => array('\\deleted'), 'ids' => $uids));
+ return $this->getBackend()->store($mailbox, array('add' => array('\\deleted'), 'ids' => $uids));
}
/**
public function moveMessage($old_folder, $uid, $new_folder)
{
$options = array('ids' => array($uid), 'move' => true);
- return $this->_imap->copy($old_folder, $new_folder, $options);
+ return $this->getBackend()->copy($old_folder, $new_folder, $options);
}
/**
*/
public function expunge($mailbox)
{
- return $this->_imap->expunge($mailbox);
+ return $this->getBackend()->expunge($mailbox);
}
/**
)
)
);
- $result = $this->_imap->fetch($mailbox, $criteria, $options);
+ $result = $this->getBackend()->fetch($mailbox, $criteria, $options);
return $result[$uid]['headertext'][0];
}
)
)
);
- $result = $this->_imap->fetch($mailbox, $criteria, $options);
+ $result = $this->getBackend()->fetch($mailbox, $criteria, $options);
return $result[$uid]['bodytext'][0];
}
public function getAcl(Horde_Kolab_Storage_Folder $folder)
{
//@todo: Separate driver class
- if ($this->_imap->queryCapability('ACL') === true) {
+ if ($this->getBackend()->queryCapability('ACL') === true) {
if ($folder->getOwner() == $this->getAuth()) {
try {
return $this->_getAcl($folder->getPath());
*/
private function _getAcl($folder)
{
- $acl = $this->_imap->getACL($folder);
+ $acl = $this->getBackend()->getACL($folder);
$result = array();
foreach ($acl as $user => $rights) {
$result[$user] = join('', $rights);
*/
private function _getMyAcl($folder)
{
- return $this->_imap->getMyACLRights($folder);
+ return $this->getBackend()->getMyACLRights($folder);
}
/**
public function setAcl($folder, $user, $acl)
{
//@todo: Separate driver class
- if ($this->_imap->queryCapability('ACL') === true) {
- $this->_imap->setACL($folder, $user, array('rights' => $acl));
+ if ($this->getBackend()->queryCapability('ACL') === true) {
+ $this->getBackend()->setACL($folder, $user, array('rights' => $acl));
}
}
public function deleteAcl($folder, $user)
{
//@todo: Separate driver class
- if ($this->_imap->queryCapability('ACL') === true) {
- $this->_imap->setACL($folder, $user, array('remove' => true));
+ if ($this->getBackend()->queryCapability('ACL') === true) {
+ $this->getBackend()->setACL($folder, $user, array('remove' => true));
}
}
public function getAnnotation($entry, $mailbox_name)
{
try {
- $result = $this->_imap->getMetadata($mailbox_name, $entry);
+ $result = $this->getBackend()->getMetadata($mailbox_name, $entry);
} catch (Exception $e) {
return '';
}
*/
public function setAnnotation($entry, $value, $mailbox_name)
{
- return $this->_imap->setMetadata($mailbox_name,
+ return $this->getBackend()->setMetadata($mailbox_name,
array($entry => $value));
}
public function getNamespace()
{
if ($this->_namespace === null
- && $this->_imap->queryCapability('NAMESPACE') === true) {
+ && $this->getBackend()->queryCapability('NAMESPACE') === true) {
$c = array();
$configuration = $this->getParam('namespaces', array());
- foreach ($this->_imap->getNamespaces() as $namespace) {
+ foreach ($this->getBackend()->getNamespaces() as $namespace) {
if (in_array($namespace['name'], array_keys($configuration))) {
$namespace = array_merge($namespace, $configuration[$namespace['name']]);
}
}
/**
- * Return the id of the user currently authenticated.
+ * Create the backend driver.
*
- * @return string The id of the user that opened the IMAP connection.
+ * @return mixed The backend driver.
*/
- public function getAuth()
+ public function createBackend()
{
- return $this->getParam('username');
}
/**
extends Horde_Kolab_Storage_Driver_Base
{
/**
- * The IMAP client.
+ * Create the backend driver.
*
- * @var Net_IMAP
+ * @return mixed The backend driver.
*/
- private $_imap;
-
- /**
- * Constructor.
- *
- * @param Net_IMAP $imap The IMAP connection handler.
- * @param Horde_Kolab_Storage_Factory $factory A factory for helper objects.
- * @param array $params Connection parameters.
- */
- public function __construct(
- Net_IMAP $imap,
- Horde_Kolab_Storage_Factory $factory,
- $params = array()
- ) {
- $this->_imap = $imap;
- parent::__construct($factory, $params);
- }
-
- /**
- * Return the id of the user currently authenticated.
- *
- * @return string The id of the user that opened the IMAP connection.
- */
- public function getAuth()
- {
- return $this->getParam('username');
- }
-
- /**
- * Return the unique connection id.
- *
- * @return string The connection id.
- */
- public function getId()
+ public function createBackend()
{
- return $this->getAuth() . '@'
- . $this->getParam('host') . ':'
- . $this->getParam('port');
+ $config = $this->getParams();
+ $client = new Net_IMAP($config['host'], $config['port']);
+ Horde_Kolab_Storage_Exception_Pear::catchError(
+ $client->login($config['username'], $config['password'])
+ );
+ return $client;
}
/**
*/
public function getMailboxes()
{
- return $this->_imap->getMailboxes();
+ return $this->getBackend()->getMailboxes();
}
/**
{
list($entry, $value) = $this->_getAnnotateMoreEntry($annotation);
$list = array();
- $result = $this->_imap->getAnnotation($entry, $value, '*');
+ $result = $this->getBackend()->getAnnotation($entry, $value, '*');
foreach ($result as $element) {
if (isset($element['ATTRIBUTES'][$value])) {
$list[$element['MAILBOX']] = $element['ATTRIBUTES'][$value];
*/
public function select($folder)
{
- $this->_imap->openMailbox($folder, Horde_Imap_Client::OPEN_AUTO);
+ $this->getBackend()->openMailbox($folder, Horde_Imap_Client::OPEN_AUTO);
return true;
}
*/
public function status($folder)
{
- return $this->_imap->status($folder,
+ return $this->getBackend()->status($folder,
Horde_Imap_Client::STATUS_UIDNEXT
| Horde_Imap_Client::STATUS_UIDVALIDITY);
}
{
$search_query = new Horde_Imap_Client_Search_Query();
$search_query->flag('DELETED', false);
- $uidsearch = $this->_imap->search($folder, $search_query);
+ $uidsearch = $this->getBackend()->search($folder, $search_query);
$uids = $uidsearch['match'];
return $uids;
}
*/
public function create($folder)
{
- return $this->_imap->createMailbox($folder);
+ return $this->getBackend()->createMailbox($folder);
}
/**
*/
public function delete($folder)
{
- return $this->_imap->deleteMailbox($folder);
+ return $this->getBackend()->deleteMailbox($folder);
}
/**
*/
public function rename($old, $new)
{
- return $this->_imap->renameMailbox($old, $new);
+ return $this->getBackend()->renameMailbox($old, $new);
}
/**
*/
public function appendMessage($mailbox, $msg)
{
- return $this->_imap->append($mailbox, array(array('data' => $msg)));
+ return $this->getBackend()->append($mailbox, array(array('data' => $msg)));
}
/**
if (!is_array($uids)) {
$uids = array($uids);
}
- return $this->_imap->store($mailbox, array('add' => array('\\deleted'), 'ids' => $uids));
+ return $this->getBackend()->store($mailbox, array('add' => array('\\deleted'), 'ids' => $uids));
}
/**
public function moveMessage($old_folder, $uid, $new_folder)
{
$options = array('ids' => array($uid), 'move' => true);
- return $this->_imap->copy($old_folder, $new_folder, $options);
+ return $this->getBackend()->copy($old_folder, $new_folder, $options);
}
/**
*/
public function expunge($mailbox)
{
- return $this->_imap->expunge($mailbox);
+ return $this->getBackend()->expunge($mailbox);
}
/**
)
)
);
- $result = $this->_imap->fetch($mailbox, $criteria, $options);
+ $result = $this->getBackend()->fetch($mailbox, $criteria, $options);
return $result[$uid]['headertext'][0];
}
)
)
);
- $result = $this->_imap->fetch($mailbox, $criteria, $options);
+ $result = $this->getBackend()->fetch($mailbox, $criteria, $options);
return $result[$uid]['bodytext'][0];
}
public function getAcl(Horde_Kolab_Storage_Folder $folder)
{
//@todo: Separate driver class
- if ($this->_imap->queryCapability('ACL') === true) {
+ if ($this->getBackend()->queryCapability('ACL') === true) {
if ($folder->getOwner() == $this->getAuth()) {
try {
return $this->_getAcl($folder->getName());
*/
private function _getAcl($folder)
{
- $acl = $this->_imap->getACL($folder);
+ $acl = $this->getBackend()->getACL($folder);
$result = array();
foreach ($acl as $user => $rights) {
$result[$user] = join('', $rights);
*/
private function _getMyAcl($folder)
{
- return $this->_imap->getMyACLRights($folder);
+ return $this->getBackend()->getMyACLRights($folder);
}
/**
public function setAcl($folder, $user, $acl)
{
//@todo: Separate driver class
- if ($this->_imap->queryCapability('ACL') === true) {
- $this->_imap->setACL($folder, $user, array('rights' => $acl));
+ if ($this->getBackend()->queryCapability('ACL') === true) {
+ $this->getBackend()->setACL($folder, $user, array('rights' => $acl));
}
}
public function deleteAcl($folder, $user)
{
//@todo: Separate driver class
- if ($this->_imap->queryCapability('ACL') === true) {
- $this->_imap->setACL($folder, $user, array('remove' => true));
+ if ($this->getBackend()->queryCapability('ACL') === true) {
+ $this->getBackend()->setACL($folder, $user, array('remove' => true));
}
}
public function getAnnotation($entry, $mailbox_name)
{
try {
- $result = $this->_imap->getMetadata($mailbox_name, $entry);
+ $result = $this->getBackend()->getMetadata($mailbox_name, $entry);
} catch (Exception $e) {
return '';
}
*/
public function setAnnotation($entry, $value, $mailbox_name)
{
- return $this->_imap->setMetadata($mailbox_name,
+ return $this->getBackend()->setMetadata($mailbox_name,
array($entry => $value));
}
*/
public function getNamespace()
{
- if ($this->_imap->hasCapability('NAMESPACE') === true) {
+ if ($this->getBackend()->hasCapability('NAMESPACE') === true) {
$namespaces = array();
- foreach ($this->_imap->getNamespace() as $type => $elements) {
+ foreach ($this->getBackend()->getNamespace() as $type => $elements) {
foreach ($elements as $namespace) {
switch ($type) {
case 'personal':
extends Horde_Kolab_Storage_Driver_Base
{
/**
- * The IMAP client.
+ * Create the backend driver.
*
- * @var rcube_imap_generic
+ * @return mixed The backend driver.
*/
- private $_imap;
-
- /**
- * Constructor.
- *
- * @param rcube_imap_generic $imap The IMAP connection handler.
- * @param Horde_Kolab_Storage_Factory $factory A factory for helper objects.
- * @param array $params Connection parameters.
- */
- public function __construct(
- rcube_imap_generic $imap,
- Horde_Kolab_Storage_Factory $factory,
- $params = array()
- ) {
- $this->_imap = $imap;
- parent::__construct($factory, $params);
- }
-
- /**
- * Return the id of the user currently authenticated.
- *
- * @return string The id of the user that opened the IMAP connection.
- */
- public function getAuth()
+ public function createBackend()
{
- return $this->getParam('username');
- }
-
- /**
- * Return the unique connection id.
- *
- * @return string The connection id.
- */
- public function getId()
- {
- return $this->getAuth() . '@'
- . $this->getParam('host') . ':'
- . $this->getParam('port');
+ $config = $this->getParams();
+ $client = new rcube_imap_generic();
+ //$client->setDebug(true);
+ $client->connect(
+ $config['host'], $config['username'], $config['password'],
+ array(
+ 'debug_mode' => false,
+ 'ssl_mode' => false,
+ 'port' => $config['port'],
+ 'timeout' => 0,
+ 'force_caps' => false,
+ )
+ );
+ return $client;
}
/**
*/
public function getMailboxes()
{
- return $this->_imap->listMailboxes('', '*');
+ return $this->getBackend()->listMailboxes('', '*');
}
/**
public function listAnnotation($annotation)
{
list($entry, $value) = $this->_getAnnotateMoreEntry($annotation);
- $result = $this->_imap->getAnnotation('*', $entry, $value);
+ $result = $this->getBackend()->getAnnotation('*', $entry, $value);
if (empty($result)) {
return array();
}
*/
public function select($folder)
{
- $this->_imap->openMailbox($folder, Horde_Imap_Client::OPEN_AUTO);
+ $this->getBackend()->openMailbox($folder, Horde_Imap_Client::OPEN_AUTO);
return true;
}
*/
public function status($folder)
{
- return $this->_imap->status($folder,
+ return $this->getBackend()->status($folder,
Horde_Imap_Client::STATUS_UIDNEXT
| Horde_Imap_Client::STATUS_UIDVALIDITY);
}
{
$search_query = new Horde_Imap_Client_Search_Query();
$search_query->flag('DELETED', false);
- $uidsearch = $this->_imap->search($folder, $search_query);
+ $uidsearch = $this->getBackend()->search($folder, $search_query);
$uids = $uidsearch['match'];
return $uids;
}
*/
public function create($folder)
{
- return $this->_imap->createMailbox($folder);
+ return $this->getBackend()->createMailbox($folder);
}
/**
*/
public function delete($folder)
{
- return $this->_imap->deleteMailbox($folder);
+ return $this->getBackend()->deleteMailbox($folder);
}
/**
*/
public function rename($old, $new)
{
- return $this->_imap->renameMailbox($old, $new);
+ return $this->getBackend()->renameMailbox($old, $new);
}
/**
*/
public function appendMessage($mailbox, $msg)
{
- return $this->_imap->append($mailbox, array(array('data' => $msg)));
+ return $this->getBackend()->append($mailbox, array(array('data' => $msg)));
}
/**
if (!is_array($uids)) {
$uids = array($uids);
}
- return $this->_imap->store($mailbox, array('add' => array('\\deleted'), 'ids' => $uids));
+ return $this->getBackend()->store($mailbox, array('add' => array('\\deleted'), 'ids' => $uids));
}
/**
public function moveMessage($old_folder, $uid, $new_folder)
{
$options = array('ids' => array($uid), 'move' => true);
- return $this->_imap->copy($old_folder, $new_folder, $options);
+ return $this->getBackend()->copy($old_folder, $new_folder, $options);
}
/**
*/
public function expunge($mailbox)
{
- return $this->_imap->expunge($mailbox);
+ return $this->getBackend()->expunge($mailbox);
}
/**
)
)
);
- $result = $this->_imap->fetch($mailbox, $criteria, $options);
+ $result = $this->getBackend()->fetch($mailbox, $criteria, $options);
return $result[$uid]['headertext'][0];
}
)
)
);
- $result = $this->_imap->fetch($mailbox, $criteria, $options);
+ $result = $this->getBackend()->fetch($mailbox, $criteria, $options);
return $result[$uid]['bodytext'][0];
}
public function getAcl(Horde_Kolab_Storage_Folder $folder)
{
//@todo: Separate driver class
- if ($this->_imap->queryCapability('ACL') === true) {
+ if ($this->getBackend()->queryCapability('ACL') === true) {
if ($folder->getOwner() == $this->getAuth()) {
try {
return $this->_getAcl($folder->getName());
*/
private function _getAcl($folder)
{
- $acl = $this->_imap->getACL($folder);
+ $acl = $this->getBackend()->getACL($folder);
$result = array();
foreach ($acl as $user => $rights) {
$result[$user] = join('', $rights);
*/
private function _getMyAcl($folder)
{
- return $this->_imap->getMyACLRights($folder);
+ return $this->getBackend()->getMyACLRights($folder);
}
/**
public function setAcl($folder, $user, $acl)
{
//@todo: Separate driver class
- if ($this->_imap->queryCapability('ACL') === true) {
- $this->_imap->setACL($folder, $user, array('rights' => $acl));
+ if ($this->getBackend()->queryCapability('ACL') === true) {
+ $this->getBackend()->setACL($folder, $user, array('rights' => $acl));
}
}
public function deleteAcl($folder, $user)
{
//@todo: Separate driver class
- if ($this->_imap->queryCapability('ACL') === true) {
- $this->_imap->setACL($folder, $user, array('remove' => true));
+ if ($this->getBackend()->queryCapability('ACL') === true) {
+ $this->getBackend()->setACL($folder, $user, array('remove' => true));
}
}
public function getAnnotation($entry, $mailbox_name)
{
try {
- $result = $this->_imap->getMetadata($mailbox_name, $entry);
+ $result = $this->getBackend()->getMetadata($mailbox_name, $entry);
} catch (Exception $e) {
return '';
}
*/
public function setAnnotation($entry, $value, $mailbox_name)
{
- return $this->_imap->setMetadata($mailbox_name,
+ return $this->getBackend()->setMetadata($mailbox_name,
array($entry => $value));
}
*/
public function getNamespace()
{
- if ($this->_imap->hasCapability('NAMESPACE') === true) {
+ if ($this->getBackend()->hasCapability('NAMESPACE') === true) {
$namespaces = array();
- foreach ($this->_imap->getNamespace() as $type => $elements) {
+ foreach ($this->getBackend()->getNamespace() as $type => $elements) {
foreach ($elements as $namespace) {
switch ($type) {
case 'personal':
$driver = new Horde_Kolab_Storage_Driver_Mock($this, $config);
break;
case 'horde':
- $config['hostspec'] = $config['host'];
- unset($config['host']);
- //$config['debug'] = '/tmp/imap.log';
- $driver = new Horde_Kolab_Storage_Driver_Imap(
- new Horde_Imap_Client_Socket(
- $config
- ),
- $this
- );
- break;
case 'horde-php':
- $config['hostspec'] = $config['host'];
- unset($config['host']);
- $driver = new Horde_Kolab_Storage_Driver_Imap(
- new Horde_Imap_Client_Cclient(
- $config
- ),
- $this
- );
+ $driver = new Horde_Kolab_Storage_Driver_Imap($this, $config);
break;
case 'php':
$driver = new Horde_Kolab_Storage_Driver_Cclient($this, $config);
break;
case 'pear':
- $client = new Net_IMAP($config['host'], $config['port']);
- Horde_Kolab_Storage_Exception_Pear::catchError(
- $client->login($config['username'], $config['password'])
- );
- $driver = new Horde_Kolab_Storage_Driver_Pear(
- $client, $this, $config
- );
+ $driver = new Horde_Kolab_Storage_Driver_Pear($this, $config);
break;
case 'roundcube':
- $client = new rcube_imap_generic();
- //$client->setDebug(true);
- $client->connect(
- $config['host'], $config['username'], $config['password'],
- array(
- 'debug_mode' => false,
- 'ssl_mode' => false,
- 'port' => $config['port'],
- 'timeout' => 0,
- 'force_caps' => false,
- )
- );
- $driver = new Horde_Kolab_Storage_Driver_Rcube(
- $client, $this, $config
- );
+ $driver = new Horde_Kolab_Storage_Driver_Rcube($this, $config);
break;
default:
throw new Horde_Kolab_Storage_Exception(
);
}
if (!empty($params['timelog'])) {
- $params['timelog']->info(
- sprintf(
- 'REQUEST OUT IMAP: %s ms [construct]',
- floor($timer->pop() * 1000)
- )
- );
$driver = new Horde_Kolab_Storage_Driver_Decorator_Timer(
$driver, $timer, $params['timelog']
);
$this->_storage = $this->getMock('Horde_Kolab_Storage', array(), array(), '', false, false);
$this->_imap = $this->getMock('Horde_Imap_Client_Socket', array(), array(), '', false, false);
$this->_connection = new Horde_Kolab_Storage_Driver_Imap(
- $this->_imap,
- new Horde_Kolab_Storage_Factory()
+ new Horde_Kolab_Storage_Factory(),
+ array('backend' => $this->_imap, 'username' => 'user')
);
$this->_imap->expects($this->any())
->method('getNamespaces')
->method('getMyACLRights')
->with('INBOX')
->will($this->returnValue('lr'));
- $this->_imap->expects($this->any())
- ->method('getParam')
- ->with('username')
- ->will($this->returnValue('user'));
$folder = $this->_getFolder('INBOX');
$this->assertEquals(array('user' => 'lr'), $folder->getAcl());
}
->will($this->returnValue(array('INBOX')));
$this->_imap->expects($this->once())
->method('getMyACLRights')
- ->with('user/test')
+ ->with('user/user')
->will($this->returnValue('lr'));
- $this->_imap->expects($this->any())
- ->method('getParam')
- ->with('username')
- ->will($this->returnValue('test'));
- $folder = $this->_getFolder('user/test');
- $this->assertEquals(array('test' => 'lr'), $folder->getAcl());
+ $folder = $this->_getFolder('user/user');
+ $this->assertEquals(array('user' => 'lr'), $folder->getAcl());
}
public function testGetaclRetrievesAllFolderAclOnForeignFolderWithAdminRights()
->will($this->returnValue(array('INBOX')));
$this->_imap->expects($this->once())
->method('getMyACLRights')
- ->with('user/test')
+ ->with('user/user')
->will($this->returnValue('lra'));
$this->_imap->expects($this->once())
->method('getAcl')
- ->with('user/test')
- ->will($this->returnValue(array('test' => 'lra')));
- $this->_imap->expects($this->any())
- ->method('getParam')
- ->with('username')
- ->will($this->returnValue('test'));
- $folder = $this->_getFolder('user/test');
- $this->assertEquals(array('test' => 'lra'), $folder->getAcl());
+ ->with('user/user')
+ ->will($this->returnValue(array('user' => 'lra')));
+ $folder = $this->_getFolder('user/user');
+ $this->assertEquals(array('user' => 'lra'), $folder->getAcl());
}
public function testSetacletsFolderAcl()
$this->_imap->expects($this->once())
->method('listMailboxes')
->will($this->returnValue(array('INBOX')));
- $this->_imap->expects($this->any())
- ->method('getParam')
- ->with('username')
- ->will($this->returnValue('user'));
$folder = $this->_getFolder('INBOX');
$this->assertEquals(array('user' => 'lrid'), $folder->getAcl());
}
public function testGetNamespaceReturnsNamespaceHandler()
{
$driver = new Horde_Kolab_Storage_Driver_Imap(
- $this->_getNamespaceMock(),
new Horde_Kolab_Storage_Factory(),
- array()
+ array('backend' => $this->_getNamespaceMock())
);
$this->assertType(
'Horde_Kolab_Storage_Folder_Namespace',
public function testGetNamespaceReturnsExpectedNamespaces()
{
$driver = new Horde_Kolab_Storage_Driver_Imap(
- $this->_getNamespaceMock(),
new Horde_Kolab_Storage_Factory(),
- array()
+ array('backend' => $this->_getNamespaceMock())
);
$namespaces = array();
foreach ($driver->getNamespace() as $namespace) {
public function testGetNamespaceReturnsNamespaceHandler()
{
$driver = new Horde_Kolab_Storage_Driver_Pear(
- $this->_getNamespaceMock(),
new Horde_Kolab_Storage_Factory(),
- array()
+ array('backend' => $this->_getNamespaceMock())
);
$this->assertType(
'Horde_Kolab_Storage_Folder_Namespace',
public function testGetNamespaceReturnsExpectedNamespaces()
{
$driver = new Horde_Kolab_Storage_Driver_Pear(
- $this->_getNamespaceMock(),
new Horde_Kolab_Storage_Factory(),
- array()
+ array('backend' => $this->_getNamespaceMock())
);
$namespaces = array();
foreach ($driver->getNamespace() as $namespace) {
);
}
- public function testTimedDriverConstruction()
- {
- $factory = new Horde_Kolab_Storage_Factory();
- $logger = $this->getMockLogger();
- $factory->createDriverFromParams(
- array(
- 'driver' => 'mock',
- 'logger' => $logger,
- 'timelog' => $logger,
- )
- );
- $this->assertLogRegExp('/REQUEST OUT IMAP:.*construct.*/');
- }
-
public function testCreateTypeReturnsType()
{
$factory = new Horde_Kolab_Storage_Factory();