setMaxQuota(sfConfig::get('app_domain_default_mailbox_quota')); $this->setMaxAddressCount(sfConfig::get('app_mailbox_max_address_count')); } public function getImapName() { return "user.".$this->getName(); } public function getExistsOnImapServer() { $this->requireIMAPAdminConnection(); $exists = $this->imap->getlist($this->getImapName(), '%'); if(is_array($exists) && (count($exists)!=0)) { return true; } return false; } protected function requireIMAPAdminConnection() { if(!$this->imap) $this->imap = IMAPManager::getAdminConnection(); } protected $quota = null; protected function updateIMAPQuota() { $this->requireIMAPAdminConnection(); $quota = $this->imap->getquota("user.".$this->getName()); if($quota) $this->quota = $quota; } public function getQuota() { if($this->quota == null) $this->updateIMAPQuota(); return $this->quota; } public function save($con = null) { // create or update resources on IMAP server if($this->isNew()) { $this->requireIMAPAdminConnection(); // mailbox $this->imap->create($this->getImapName()); // acl $this->imap->setacl($this->getImapName(), IMAPManager::getAdminUsername(), $this->imap->getAvailableACL()); // quota $this->imap->setquota($this->getImapName(), $this->getMaxQuota()); // default folders } else // update { // mailbox name changed? if($this->isColumnModified(MailboxPeer::NAME)) { $this->requireIMAPAdminConnection(); $oldmailbox = MailboxPeer::retrieveByPk($this->getId()); if($oldmailbox->getName() != $this->getName()) { // requires "allowusermoves: 1" in /etc/imapd.conf // mailbox $this->imap->rename($oldmailbox->getImapName(), $this->getImapName()); } } // quota changed? if($this->isColumnModified(MailboxPeer::MAX_QUOTA)) { $this->requireIMAPAdminConnection(); $this->imap->setquota($this->getImapName(), $this->getMaxQuota()); } } return parent::save($con); } public function delete($con = null) { // remove resources on IMAP server if(!$this->isNew()) { $this->requireIMAPAdminConnection(); // grant all rights to admin to be able to delete mailbox $this->imap->setacl($this->getImapName(), IMAPManager::getAdminUsername(), $this->imap->getAvailableACL()); // mailbox $this->imap->delete($this->getImapName()); } return parent::delete($con); } // TODO: extract password logic into own library public function isPasswordEqual($password) { // check crypt type $server_settings = sfConfig::get('app_server_default'); $crypt_type = $server_settings['pam']['crypt']; switch($crypt_type) { case 0: // plain return ($password == $this->getPassword()); case 1: // crypt return (crypt($password, substr($this->getPassword(), 0, 2)) == $this->getPassword()); case 2: // md5 return (md5($password) == $this->getPassword()); case 3: // sha1 return (sha1($password) == $this->getPassword()); break; } return false; } public function setPassword($password) { if($password=='') return false; // check crypt type $server_settings = sfConfig::get('app_server_default'); $crypt_type = $server_settings['pam']['crypt']; switch($crypt_type) { case 0: // plain break; case 1: // crypt $password = crypt($password, substr($password, 0, 8)); break; case 2: // md5 $password = md5($password); break; case 3: // sha1 $password = sha1($password); break; } return parent::setPassword($password); } public function setNewPassword($password) { return $this->setPassword($password); } public function getAddressCount() { return $this->countAddresss(); } public function __toString() { return $this->getName(); } }