Exemple #1
0
 /**
  * Loads aliases with mailbox.
  *
  * Selects aliases where address not equal to goto, and goto not equals to
  * mailbox username, but goto has mailbox username. If admin is not super
  * then it checks if admin have have linked with domain.
  *
  * @param \Entities\Mailbox $mailbox Mailbox for alias filtering.
  * @param \Entities\Admin   $admin   Admin for checking privileges.
  * @return \Entities\Alias[]
  */
 public function loadWithMailbox($mailbox, $admin)
 {
     $qb = $this->getEntityManager()->createQueryBuilder()->select('a')->from('\\Entities\\Alias', 'a')->where('a.address != a.goto')->andWhere('a.goto != ?1')->andWhere('a.goto like ?2')->setParameter(1, $mailbox->getUsername())->setParameter(2, '%' . $mailbox->getUsername() . '%');
     if (!$admin->isSuper()) {
         $qb->leftJoin('a.Domain', 'd')->leftJoin('d.Admins', 'd2a')->andWhere('d2a = :admin')->setParameter('admin', $admin);
     }
     return $qb->getQuery()->getResult();
 }
Exemple #2
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;
 }
 /**
  * Sends email with settings
  *
  * Send Email with settings for $this->_mailbox.
  * If cc is set When additional email is set, then it sends additional emails to cc.
  * If password is set, then password is shown in email.
  * if isWelcome is set to true, adding welcome subject and welcome text to email.
  *
  * @param bool $cc Additional email.
  * @param string $password Password to send for mailbox owner
  * @param bool $isWelcome Defines email is welcome email or not.
  * @return bool
  */
 private function _sendSettingsEmail($cc = false, $password = '', $isWelcome = false, $email = false)
 {
     $mailer = $this->getMailer();
     if ($isWelcome) {
         $mailer->setSubject(sprintf(_("Welcome to your new mailbox on %s"), $this->getMailbox()->getDomain()->getDomain()));
     } else {
         $mailer->setSubject(sprintf(_("Settings for your mailbox on %s"), $this->getMailbox()->getDomain()->getDomain()));
     }
     $mailer->setFrom($this->_options['server']['email']['address'], $this->_options['server']['email']['name']);
     if (!$email) {
         $mailer->addTo($this->getMailbox()->getUsername(), $this->getMailbox()->getName());
     } else {
         $mailer->addTo($email);
     }
     if ($cc) {
         $mailer->addCc($cc);
     }
     $this->view->mailbox = $this->getMailbox();
     $this->view->welcome = $isWelcome;
     $this->view->password = $password;
     $settings = $this->_options['server'];
     foreach ($settings as $tech => $params) {
         foreach ($params as $k => $v) {
             $settings[$tech][$k] = \Entities\Mailbox::substitute($this->getMailbox()->getUsername(), $v);
         }
     }
     $this->view->settings = $settings;
     $this->notify('mailbox', 'sendSettingsEmail', 'preSetBody', $this);
     $mailer->setBodyText($this->view->render('mailbox/email/settings.phtml'));
     try {
         $mailer->send();
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
 /**
  * Restore archived files and unserialize mailbox. Removes archive entry
  */
 public function cliRestorePendingsAction()
 {
     $archives = $this->getD2EM()->getRepository("\\Entities\\Archive")->findBy(['status' => \Entities\Archive::STATUS_PENDING_RESTORE]);
     if (!count($archives) && $this->getParam('verbose')) {
         echo "No pending archives for restoration found.\n";
         return;
     }
     foreach ($archives as $archive) {
         //Locking archive by setting it status to restoring
         if (!$this->_archiveStateChange($archive, \Entities\Archive::STATUS_RESTORING, \Entities\Archive::STATUS_PENDING_RESTORE)) {
             continue;
         }
         $data = unserialize($archive->getData());
         if (!isset($data['mailbox']['params']) || !isset($data['mailbox']['className'])) {
             $this->getLogger()->alert("Bad archive parameters for {$data['mailbox']['params']['username']}");
             continue;
         }
         $mparams = $data['mailbox']['params'];
         $homedir = $mparams['homedir'];
         $maildir = \Entities\Mailbox::cleanMaildir($mparams['maildir']);
         if ($this->getParam('verbose')) {
             echo "\nRestoring archive for {$data['mailbox']['params']['username']}... ";
         }
         if ($archive->getHomedirFile()) {
             if (!$this->_untarDir($archive->getHomedirFile(), $homedir)) {
                 $this->getLogger()->notice("ArchiveController::cliRestorePendingsAction - could not untar homedir for {$data['mailbox']['params']['username']}");
                 continue;
             }
             unlink($archive->getHomedirFile());
             if ($maildir != $homedir && !$this->_untarDir($archive->getMaildirFile(), $maildir)) {
                 $this->getLogger()->notice("ArchiveController::cliRestorePendingsAction - could not untar maildir for {$data['mailbox']['params']['username']}");
                 continue;
             }
             unlink($archive->getMaildirFile());
         }
         if ($this->getParam('verbose')) {
             echo "DONE\n";
         }
         $data = $this->_unserialzeMailbox($archive->getData());
         $this->notify('archive', 'restorePendings', 'preFlushRestore', $this);
         $this->getD2EM()->flush();
         $this->notify('archive', 'restorePendings', 'postFlushRestore', $this, $data['mailbox']);
         $this->_notifyAdmin($archive->getArchivedBy(), "archive/email/archive-restored.txt", "Mailbox restored", $data['mailbox']->getUsername());
         $this->getD2EM()->remove($this->getD2EM()->getRepository("\\Entities\\Archive")->find($archive->getId()));
         $this->getD2EM()->flush();
         $this->notify('archive', 'restorePendings', 'restored', $this, $data['mailbox']);
         if ($this->getParam('verbose')) {
             echo "\n";
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function _getPreferences()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, '_getPreferences', array());
     return parent::_getPreferences();
 }