/**
* Add a set of authentication credentials.
*
* @param string $userId The userId to add.
* @param array $credentials The credentials to add.
*
* @throw Horde_Auth_Exception
*/
public function addUser($userId, $credentials)
{
if (!empty($this->_params['domain_field']) && $this->_params['domain_field'] != 'none') {
list($name, $domain) = explode('@', $userId);
$query = sprintf('INSERT INTO %s (%s, %s, %s) VALUES (?, ?, ?)', $this->_params['table'], $this->_params['username_field'], $this->_params['domain_field'], $this->_params['password_field']);
$values = array($name, $domain, Horde_Auth::getCryptedPassword($credentials['password'], '', $this->_params['encryption'], $this->_params['show_encryption']));
$query2 = 'INSERT INTO virtual (alias, dest, username, status) VALUES (?, ?, ?, 1)';
$values2 = array($userId, $userId, $name);
try {
$this->_db->insert($query, $values);
$this->_db->insert($query2, $values2);
} catch (Horde_Db_Exception $e) {
throw new Horde_Auth_Exception($e);
}
} else {
parent::addUser($userId, $credentials);
}
$mailbox = $this->_params['userhierarchy'];
try {
$this->_imap->createMailbox($mailbox);
$this->_imap->setACL($mailbox, $this->_params['cyradmin'], array('rights' => 'lrswipcda'));
if (isset($this->_params['quota']) && $this->_params['quota'] >= 0) {
$this->_imap->setQuota($mailbox, array('storage' => $this->_params['quota']));
}
} catch (Horde_Imap_Client_Exception $e) {
throw new Horde_Auth_Exception($e);
}
foreach ($this->_params['folders'] as $val) {
try {
$this->_imap->createMailbox($val);
$this->_imap->setACL($val, $this->_params['cyradmin'], array('rights' => 'lrswipcda'));
} catch (Horde_Imap_Client_Exception $e) {
}
}
}