/** * @param array $from * * @return string */ protected function buildFullEmailAddress(array $from) { foreach ($from as $email => $name) { return $this->emailAddressHelper->buildFullEmailAddress($email, $name); } throw new \InvalidArgumentException('Sender email and name is empty'); }
/** * {@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); } }
/** * @param string $emailAddress * @param string|null $ownerClass * @param mixed|null $ownerId */ protected function preciseFullEmailAddress(&$emailAddress, $ownerClass = null, $ownerId = null) { if (!$this->emailAddressHelper->isFullEmailAddress($emailAddress)) { if (!empty($ownerClass) && !empty($ownerId)) { $owner = $this->entityRoutingHelper->getEntity($ownerClass, $ownerId); if ($owner) { $ownerName = $this->nameFormatter->format($owner); if (!empty($ownerName)) { $emailAddress = $this->emailAddressHelper->buildFullEmailAddress($emailAddress, $ownerName); return; } } } $repo = $this->emailAddressManager->getEmailAddressRepository($this->em); $emailAddressObj = $repo->findOneBy(array('email' => $emailAddress)); if ($emailAddressObj) { $owner = $emailAddressObj->getOwner(); if ($owner) { $ownerName = $this->nameFormatter->format($owner); if (!empty($ownerName)) { $emailAddress = $this->emailAddressHelper->buildFullEmailAddress($emailAddress, $ownerName); } } } } }
/** * Get email address prepared for sending. * * @param mixed $context * @param string|array $data * * @return string */ protected function getEmailAddress($context, $data) { $name = null; $emailAddress = $this->contextAccessor->getValue($context, $data); if (is_array($data)) { $emailAddress = $this->contextAccessor->getValue($context, $data['email']); if (array_key_exists('name', $data)) { $data['name'] = $this->contextAccessor->getValue($context, $data['name']); if (is_object($data['name'])) { $name = $this->entityNameResolver->getName($data['name']); } else { $name = $data['name']; } } } return $this->emailAddressHelper->buildFullEmailAddress($emailAddress, $name); }
/** * @param object|null $owner * @param string $email * * @return string */ protected function formatEmail($owner, $email) { if (!$owner) { return $email; } $ownerName = $this->nameFormatter->format($owner); return $this->emailAddressHelper->buildFullEmailAddress($email, $ownerName); }
/** * 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; } } } } }
/** * 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; }
/** * @param User $user * * @return string */ public function buildFullEmailAddress(User $user) { return $this->emailAddressHelper->buildFullEmailAddress($user->getEmail(), $this->entityNameResolver->getName($user)); }
/** * @dataProvider extractEmailAddressLastNameProvider */ public function testExtractEmailAddressLastName($emailAddress, $expected) { $this->assertEquals($expected, $this->helper->extractEmailAddressLastName($emailAddress)); }
/** * 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; }
/** * @dataProvider isFullEmailAddressProvider */ public function testIsFullEmailAddress($emailAddress, $isFull) { $this->assertEquals($isFull, $this->helper->isFullEmailAddress($emailAddress)); }