Beispiel #1
0
 /**
  * Load archives for archive list .
  *
  * If admin is super he gets all mailboxes.
  *
  * @param \Entities\Admin $admin Admin for filtering mailboxes.
  * @param \Entities\Domain $domain Domain for filtering mailboxes.
  * @return array
  */
 public function loadForArchiveList($admin, $domain = null)
 {
     $qb = $this->getEntityManager()->createQueryBuilder()->select('a.id as id , a.username as username, a.status as status, d.domain as domain')->from('\\Entities\\Archive', 'a')->join('a.Domain', 'd');
     if (!$admin->isSuper()) {
         $qb->join('d.Admins', 'd2a')->where('d2a = :admin')->setParameter('admin', $admin);
     }
     if ($domain) {
         $qb->andWhere('a.Domain = ?2')->setParameter(2, $domain);
     }
     return $qb->getQuery()->getArrayResult();
 }
 /**
  * Loads preferene values by attribute.
  *
  * Loads all prefrences value form all admin accessible mailboxes and return as array [ value1, value2, value3, ...].
  * Use cache for this method.
  *
  * @param string $attribute Attribute name
  * @param \Entities\Admin $admin Admin who request the list
  * @return array
  */
 public function loadPrefrenceValuesByAttribute($attribute, $admin)
 {
     $qb = $this->getEntityManager()->createQueryBuilder()->select('mp.value')->from('\\Entities\\MailboxPreference', 'mp')->where('mp.attribute = ?1')->setParameter(1, $attribute);
     if (!$admin->isSuper()) {
         $qb->join('mp.Mailbox', 'm')->join('m.Domain', 'd')->join('d.DomainToAdmin', 'd2a')->where('d2a.Admin = ?1')->setParameter(1, $admin);
     }
     $data = $qb->getQuery()->useResultCache(true, 3600, self::VALUES_CACHE_KEY . '_' . $admin->getId() . '_' . $attribute)->getScalarResult();
     $values = [];
     foreach ($data as $value) {
         if (!in_array($value['value'], $values)) {
             $values[] = $value['value'];
         }
     }
     return $values;
 }
Beispiel #3
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;
 }
 /**
  * {@inheritDoc}
  */
 public function isSuper()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'isSuper', array());
     return parent::isSuper();
 }
Beispiel #5
0
 /**
  * Load data for domains list
  *
  * Loads information for domains list.
  *
  * @param string          $filter 
  * @param \Entities\Admin $admin
  * @return array
  */
 public function filterForDomainList($filter, $admin)
 {
     $filter = str_replace("'", "", $filter);
     if (strpos($filter, "*") === 0) {
         $filter = '%' . substr($filter, 1);
     }
     $dql = "SELECT d.id AS id, d.domain AS name, d.alias_count AS aliases, d.mailbox_count AS mailboxes,\n                    d.max_aliases AS maxaliases, d.max_mailboxes AS maxmailboxes, SUM( m.maildir_size ) AS mailboxes_size,\n                    d.max_quota AS maxquota, d.quota AS quota, d.transport AS transport, d.backupmx AS backupmx,\n                    d.active AS active, d.created AS created\n                FROM \\Entities\\Domain d LEFT JOIN d.Mailboxes m \n                WHERE ( d.domain LIKE '{$filter}%' OR d.transport LIKE '{$filter}%'  OR d.created LIKE '{$filter}%' )";
     if (!$admin->isSuper()) {
         $dql .= " LEFT JOIN d.Admins d2a WHERE d2a = ?1";
     }
     $dql .= " GROUP BY d.id ORDER BY d.domain ASC";
     $q = $this->getEntityManager()->createQuery($dql);
     if (!$admin->isSuper()) {
         $q->setParameter(1, $admin);
     }
     return $q->getArrayResult();
 }
Beispiel #6
0
 /**
  * Return filtered alias data array
  *
  * Use filter to filter aliases by address or goto or domain. If filter
  * starts with * it will be replaced with % to meet sql requirements. At
  * the end % will be added to all strings. So filter 'man' will bicome
  * 'man%' and will look for man, manual and iffilter '*man' it wil bicome
  * '%man%' and will look for records like human, humanity, man, manual.
  *
  * @param string           $filter Flter for mailboxes
  * @param \Entities\Admin  $admin  Admin for filtering mailboxes.
  * @param \Entities\Domain $domain Domain for filtering mailboxes.
  * @param bool             $ima    Include mailbox aliases flag.
  * @return array
  */
 public function filterForAliasList($filter, $admin, $domain = null, $ima = false)
 {
     $filter = str_replace("'", "", $filter);
     if (strpos($filter, "*") === 0) {
         $filter = '%' . substr($filter, 1);
     }
     $qb = $this->getEntityManager()->createQueryBuilder()->select('a.id as id , a.address as address, a.goto as goto, a.active as active, d.domain as domain')->from('\\Entities\\Alias', 'a')->join('a.Domain', 'd')->where("( a.goto LIKE '{$filter}%' OR a.address LIKE '{$filter}%' OR d.domain LIKE '{$filter}%')");
     if (!$admin->isSuper()) {
         $qb->join('d.Admins', 'd2a')->andWhere('d2a = ?1')->setParameter(1, $admin);
     }
     if ($domain) {
         $qb->andWhere('a.Domain = ?2')->setParameter(2, $domain);
     }
     if (!$ima) {
         $qb->andWhere("a.address != a.goto");
     }
     return $qb->getQuery()->getArrayResult();
 }