/**
  * @dataProvider replaceDataProvider
  * @param       $bodyTemplate
  * @param array $attachments
  */
 public function testReplace($bodyTemplate, array $attachments)
 {
     $email = new Email();
     $emailBody = new EmailBody();
     $replacements = [];
     $contentIds = [];
     foreach ($attachments as $attachmentData) {
         $attachment = new EmailAttachment();
         $emailAttachmentContent = new EmailAttachmentContent();
         $emailAttachmentContent->setContent($attachmentData['content'])->setContentTransferEncoding($attachmentData['transfer_encoding']);
         $attachment->setEmbeddedContentId($attachmentData['content_id'])->setContentType($attachmentData['type'])->setContent($emailAttachmentContent);
         $emailBody->addAttachment($attachment);
         $cid = 'cid:' . $attachmentData['content_id'];
         $contentIds[] = $cid;
         if ($attachmentData['replace']) {
             $replacements[] = sprintf('data:%s;base64,%s', $attachmentData['type'], $attachmentData['content']);
         } else {
             $replacements[] = $cid;
         }
     }
     $emailBody->setBodyContent(vsprintf($bodyTemplate, $contentIds));
     $email->setEmailBody($emailBody);
     $event = new EmailBodyLoaded($email);
     $this->listener->replace($event);
     $this->assertEquals($email, $event->getEmail());
     $this->assertEquals(vsprintf($bodyTemplate, $replacements), $event->getEmail()->getEmailBody()->getBodyContent());
 }
 /**
  * Adds an email attachment
  *
  * @param string $fileName
  * @param string $content
  * @param string $contentType
  * @param string $contentTransferEncoding
  * @throws \LogicException
  */
 public function addEmailAttachment($fileName, $content, $contentType, $contentTransferEncoding)
 {
     if ($this->emailBody === null) {
         throw new \LogicException('Call setEmailBody first.');
     }
     $emailAttachment = new EmailAttachment();
     $emailAttachmentContent = new EmailAttachmentContent();
     $emailAttachmentContent->setEmailAttachment($emailAttachment)->setContentTransferEncoding($contentTransferEncoding)->setValue($content);
     $emailAttachment->setFileName($fileName)->setContentType($contentType)->setContent($emailAttachmentContent);
     $this->emailBody->addAttachment($emailAttachment);
 }
Пример #3
0
 protected function createEmailBody($emailId)
 {
     $email = new Email();
     $emailRef = new ReflectionClass(get_class($email));
     $id = $emailRef->getProperty('id');
     $id->setAccessible(true);
     $id->setValue($email, $emailId);
     $id->setAccessible(false);
     $emailBody = new EmailBody();
     $emailBody->setEmail($email);
     return $emailBody;
 }
Пример #4
0
 /**
  * Adds an email attachment
  *
  * @param string      $fileName
  * @param string      $content
  * @param string      $contentType
  * @param string      $contentTransferEncoding
  * @param null|string $embeddedContentId
  * @param null|int    $contentSize
  *
  * @throws \LogicException
  */
 public function addEmailAttachment($fileName, $content, $contentType, $contentTransferEncoding, $embeddedContentId = null, $contentSize = null)
 {
     if ($this->emailBody === null) {
         throw new \LogicException('Call setEmailBody first.');
     }
     if (!$this->allowSaveAttachment($this->checkContentSizeValue($content, $contentSize, $contentTransferEncoding))) {
         return;
     }
     $emailAttachment = new EmailAttachment();
     $emailAttachmentContent = new EmailAttachmentContent();
     $emailAttachmentContent->setEmailAttachment($emailAttachment)->setContentTransferEncoding($contentTransferEncoding)->setContent($content);
     $emailAttachment->setFileName($fileName)->setContentType($contentType)->setContent($emailAttachmentContent)->setEmbeddedContentId($embeddedContentId);
     $this->emailBody->addAttachment($emailAttachment);
 }
Пример #5
0
 public function inapplicableEmailsProvider()
 {
     $date = new \DateTime('now', new \DateTimeZone('UTC'));
     $oldEmailDate = new \DateTime('now', new \DateTimeZone('UTC'));
     $oldEmailDate->sub(\DateInterval::createFromDateString('2 day'));
     $applicableSubjectsAndBodies = [['not empty subject', 'This is email body with offer, sale and won words.', $date], [null, 'This email has nothing.', $date], [null, 'This is email body with sale and won words.', $oldEmailDate]];
     $data = array_map(function ($subjectAndBody) {
         list($subject, $bodyContent, $sentAt) = $subjectAndBody;
         $body = new EmailBody();
         $body->setBodyContent($bodyContent);
         $email = new Email();
         $email->setSubject($subject);
         $email->setEmailBody($body);
         $email->setSentAt($sentAt);
         return [$email];
     }, $applicableSubjectsAndBodies);
     return $data;
 }
Пример #6
0
 public function testBeforeSave()
 {
     $entity = new EmailBody();
     $entity->beforeSave();
     $createdAt = new \DateTime('now', new \DateTimeZone('UTC'));
     $this->assertEquals(false, $entity->getBodyIsText());
     $this->assertEquals(false, $entity->getHasAttachments());
     $this->assertEquals(false, $entity->getPersistent());
     $this->assertGreaterThanOrEqual($createdAt, $entity->getCreated());
 }
Пример #7
0
 /**
  * Set email body
  *
  * @param EmailBody $emailBody
  *
  * @return Email
  */
 public function setEmailBody(EmailBody $emailBody)
 {
     $emailBody->setEmail($this);
     $this->emailBody = $emailBody;
     return $this;
 }
 /**
  * Get the given email body content
  *
  * @Route("/body/{id}", name="oro_email_body", requirements={"id"="\d+"})
  * @AclAncestor("oro_email_view")
  */
 public function bodyAction(EmailBody $entity)
 {
     return new Response($entity->getContent());
 }
Пример #9
0
 /**
  * Set email body
  *
  * @param EmailBody $emailBody
  *
  * @return Email
  */
 public function setEmailBody(EmailBody $emailBody)
 {
     if ($this->emailBody->count() > 0) {
         $this->emailBody->clear();
     }
     $emailBody->setHeader($this);
     $this->emailBody->add($emailBody);
     return $this;
 }
 /**
  * Create EmailBody entity object
  *
  * @param string $content The body content
  * @param bool $isHtml Indicate whether the body content is HTML or TEXT
  * @param bool $persistent Indicate whether this email body can be removed by the email cache manager or not
  *                         Set false for external email, and false for system email, for example sent by BAP
  * @return EmailBody
  */
 public function body($content, $isHtml, $persistent = false)
 {
     $result = new EmailBody();
     $result->setContent($content)->setBodyIsText(!$isHtml)->setPersistent($persistent);
     return $result;
 }