Exemplo n.º 1
0
 /**
  * Purges mailbox
  *
  * Remove all mailbox preferences.
  * Remove all mailbox aliases with their preferences and decrease alias count in domain.
  * Remove mailbox entry for multi alias with multi addresses.
  * Remove actual mailbox and decrease mailbox count i domain.
  * Returns false if privileges not allowed and true if removed.
  *
  * @param \Entities\Mailbox $mailbox Mailbox to purge
  * @param \Entities\Admin   $admin   Admin which purging mailbox for privilege validation.
  * @param bool $removeMailbox If true, also remove the Mailbox entity. If false, purge everything but this entity.
  * @return bool
  */
 public function purgeMailbox($mailbox, $admin, $removeMailbox = true)
 {
     if (!$admin->isSuper() && !$mailbox->getDomain()->getAdmins()->contains($admin)) {
         return false;
     }
     $aliases = $this->getEntityManager()->getRepository("\\Entities\\Alias")->loadForMailbox($mailbox, $admin, true);
     $inAliases = $this->getEntityManager()->getRepository("\\Entities\\Alias")->loadWithMailbox($mailbox, $admin);
     foreach ($mailbox->getPreferences() as $pref) {
         $this->getEntityManager()->remove($pref);
     }
     //this won't delete the alias entry where address == goto
     foreach ($aliases as $alias) {
         $this->_removeAlias($alias);
     }
     foreach ($inAliases as $alias) {
         $gotos = explode(',', $alias->getGoto());
         foreach ($gotos as $key => $goto) {
             $gotos[$key] = $goto = trim($goto);
             if ($goto == $mailbox->getUsername() || $goto == '') {
                 unset($gotos[$key]);
             }
         }
         if (sizeof($gotos) == 0) {
             $this->_removeAlias($alias);
         } else {
             $alias->setGoto(implode(',', $gotos));
         }
     }
     if ($removeMailbox) {
         $this->getEntityManager()->remove($mailbox);
     }
     $mailbox->getDomain()->decreaseMailboxCount();
     return true;
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function getDomain()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getDomain', array());
     return parent::getDomain();
 }