Exemple #1
0
 /**
  *
  * @param Account $account
  * @param \GO\Base\Mail\EmailRecipients $recipients
  * @return \GO\Email\Model\Alias|false 
  */
 private function _findAliasFromRecipients($account, \GO\Base\Mail\EmailRecipients $recipients, $alias_id = 0, $allAvailableAliases = false)
 {
     $alias = false;
     $defaultAlias = false;
     $findParams = \GO\Base\Db\FindParams::newInstance()->select('t.*')->joinModel(array('model' => 'GO\\Email\\Model\\AccountSort', 'foreignField' => 'account_id', 'localField' => 'account_id', 'type' => 'LEFT'))->permissionLevel(Acl::CREATE_PERMISSION)->ignoreAdminGroup()->order('order', 'DESC');
     //find the right sender alias
     $stmt = !$allAvailableAliases && $account && $account->checkPermissionLevel(Acl::CREATE_PERMISSION) ? $account->aliases : \GO\Email\Model\Alias::model()->find($findParams);
     while ($possibleAlias = $stmt->fetch()) {
         if (!$defaultAlias) {
             $defaultAlias = $possibleAlias;
         }
         if ($recipients->hasRecipient($possibleAlias->email)) {
             $alias = $possibleAlias;
             break;
         }
     }
     if (!$alias) {
         $alias = empty($alias_id) ? $defaultAlias : \GO\Email\Model\Alias::model()->findByPk($alias_id);
     }
     return $alias;
 }