/** * 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; }
/** * 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; }
/** * Notifies administrator. * * Send notification email for admin about archive created or restore state change. * * @param \Entities\Admin $admin Admin to notify * @param string $viescript Path to tar file * @param string $subject Destination file * @param string $musername Archived / restored mailbox username * @return void */ private function _notifyAdmin($admin, $viewScript, $subject, $musername) { if (!$admin) { $this->getLogger()->debug("ArchiveController: Admin was not found admin notification failed. "); return false; } $mailer = $this->getMailer(); $mailer->setFrom($this->_options['identity']['autobot']['email'], $this->_options['identity']['autobot']['name'])->addTo($admin->getUsername(), "ViMbAdmin Administrator")->setSubject($this->_options['identity']['sitename'] . " - " . $subject); $this->view->mailbox = $musername; $mailer->setBodyText($this->view->render($viewScript)); $mailer->send(); }
/** * {@inheritDoc} */ public function _getPreferences() { $this->__initializer__ && $this->__initializer__->__invoke($this, '_getPreferences', array()); return parent::_getPreferences(); }
/** * Finds all domains which are not assigned with admin. * * Finds all domains and iterate through then making an array of 'id' => 'domain' * If domain inactive domain name will be append by '(inactive)' then we iterate * through admin domains and removing all array elements which id is already in admin domains list. * * @param \Entities\Admin $admin Admin to look for not assign domains * @retun array */ public function getNotAssignedForAdmin($admin) { $domainNames = []; foreach ($this->findAll() as $domain) { $domainNames[$domain->getId()] = $domain->getActive() ? $domain->getDomain() : $domain->getDomain() . " (inactive)"; } foreach ($admin->getDomains() as $domain) { if (isset($domainNames[$domain->getId()])) { unset($domainNames[$domain->getId()]); } } return $domainNames; }
/** * 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(); }