/**
  * {@inheritdoc}
  */
 public function filter($rawValue, $operator)
 {
     if (is_array($rawValue)) {
         return array_map(function ($val) {
             return $this->emailAddressHelper->extractPureEmailAddress($val);
         }, $rawValue);
     } else {
         return $this->emailAddressHelper->extractPureEmailAddress($rawValue);
     }
 }
 /**
  * Create EmailAddress entity object
  *
  * @param string $email The email address, for example: john@example.com or "John Smith" <*****@*****.**>
  *
  * @return EmailAddress
  */
 public function address($email)
 {
     $pureEmail = $this->emailAddressHelper->extractPureEmailAddress($email);
     $result = $this->batch->getAddress($pureEmail);
     if ($result === null) {
         $result = $this->emailAddressManager->newEmailAddress()->setEmail($pureEmail);
         $this->batch->addAddress($result);
     }
     return $result;
 }
 /**
  * @param string $name
  * @param Organization|null $organization
  *
  * @return Recipient
  */
 public function createRecipientFromEmail($name, Organization $organization = null)
 {
     $em = $this->registry->getManager();
     $email = $this->addressHelper->extractPureEmailAddress($name);
     $owner = $this->emailOwnerProvider->findEmailOwner($em, $email);
     if (!$owner || !$this->isObjectAllowedForOrganization($owner, $organization)) {
         return null;
     }
     $metadata = $em->getClassMetadata(ClassUtils::getClass($owner));
     return new Recipient($email, $name, $this->createRecipientEntity($owner, $metadata));
 }
 /**
  * {@inheritdoc}
  *
  * @param string|array $value
  * @param Constraint $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     if (is_scalar($value)) {
         $value = [$value];
     }
     $emailValidator = new EmailValidator();
     $emailValidator->initialize($this->context);
     foreach ($value as $fullEmailAddress) {
         $email = $this->emailAddressHelper->extractPureEmailAddress($fullEmailAddress);
         if (!$email) {
             continue;
         }
         $emailValidator->validate($email, $constraint);
         if ($this->context->getViolations()->count()) {
             foreach ($this->context->getViolations() as $violation) {
                 /** @var ConstraintViolation $violation */
                 if ($violation->getPropertyPath() == $this->context->getPropertyPath()) {
                     return;
                 }
             }
         }
     }
 }
Beispiel #5
0
 /**
  * Converts emails addresses to a form acceptable to \Swift_Mime_Message class
  *
  * @param string|string[] $addresses Examples of correct email addresses: john@example.com, <*****@*****.**>,
  *                                   John Smith <*****@*****.**> or "John Smith" <*****@*****.**>
  *
  * @return array
  * @throws \InvalidArgumentException
  */
 protected function getAddresses($addresses)
 {
     $result = [];
     if (is_string($addresses)) {
         $addresses = [$addresses];
     }
     if (!is_array($addresses) && !$addresses instanceof \Iterator) {
         throw new \InvalidArgumentException('The $addresses argument must be a string or a list of strings (array or Iterator)');
     }
     foreach ($addresses as $address) {
         $name = $this->emailAddressHelper->extractEmailAddressName($address);
         if (empty($name)) {
             $result[] = $this->emailAddressHelper->extractPureEmailAddress($address);
         } else {
             $result[$this->emailAddressHelper->extractPureEmailAddress($address)] = $name;
         }
     }
     return $result;
 }
 /**
  * @dataProvider emailAddressProvider
  */
 public function testExtractPureEmailAddress($fullEmailAddress, $pureEmailAddress, $name)
 {
     $this->assertEquals($pureEmailAddress, $this->helper->extractPureEmailAddress($fullEmailAddress));
 }
Beispiel #7
0
 /**
  * Gets the email address
  *
  * @param string $email
  * @return string The email address or empty string if the address is not found
  */
 public function getEmailAddress($email)
 {
     $result = $this->emailAddressHelper->extractPureEmailAddress($email);
     return null !== $result ? $result : '';
 }
 /**
  * @param string $email
  *
  * @return string
  */
 protected function normalizeEmailAddress($email)
 {
     return strtolower($this->emailAddressHelper->extractPureEmailAddress($email));
 }
 /**
  * @param EmailHeader $email
  * @param             $folderType
  * @param             $organization
  *
  * @return bool
  * @throws \Doctrine\ORM\NonUniqueResultException
  * todo CRM-2480 temporary solution for determination of emails` organization
  */
 protected function checkOrganization(EmailHeader $email, $folderType, $organization)
 {
     $helper = new EmailAddressHelper();
     $repo = $this->em->getRepository('OroCRMContactBundle:ContactEmail');
     $qb = $repo->createQueryBuilder('ce');
     if ($folderType === FolderType::SENT) {
         $emailList = array_merge($email->getToRecipients(), $email->getCcRecipients(), $email->getBccRecipients());
     } else {
         $emailList = [$email->getFrom()];
     }
     foreach ($emailList as &$emailAddress) {
         $emailAddress = strtolower($helper->extractPureEmailAddress($emailAddress));
     }
     $query = $qb->where($qb->expr()->in('ce.email', $emailList))->getQuery();
     $result = $query->getResult();
     if ($result) {
         foreach ($result as $contactEmail) {
             if ($contactEmail->getOwner()->getOrganization()->getId() === $organization->getId()) {
                 return true;
             }
         }
     }
     return false;
 }