/**
  * @param AttachmentOro $attachmentOro
  *
  * @return AttachmentEntity
  */
 public function oroToEntity(AttachmentOro $attachmentOro)
 {
     $emailAttachmentEntity = new AttachmentEntity();
     $emailAttachmentEntity->setFileName($attachmentOro->getFile()->getFilename());
     $emailAttachmentContent = new EmailAttachmentContent();
     $emailAttachmentContent->setContent(base64_encode($this->filesystem->get($attachmentOro->getFile()->getFilename())->getContent()));
     $emailAttachmentContent->setContentTransferEncoding('base64');
     $emailAttachmentContent->setEmailAttachment($emailAttachmentEntity);
     $emailAttachmentEntity->setContent($emailAttachmentContent);
     $emailAttachmentEntity->setContentType($attachmentOro->getFile()->getMimeType());
     $emailAttachmentEntity->setFile($attachmentOro->getFile());
     $emailAttachmentEntity->setFileName($attachmentOro->getFile()->getOriginalFilename());
     return $emailAttachmentEntity;
 }
 /**
  * @Route("/createpdf", name="ibnab_pmanger_email_createpdf")
  * @AclAncestor("ibnab_pmanger_email_createpdf")
  * @Template("OroEmailBundle:Email:update.html.twig")
  */
 public function createPDFAction()
 {
     $emailModel = $this->get('oro_email.email.model.builder')->createEmailModel();
     $attachmentId = $this->get('request')->get('attachmentId');
     $attachment = $this->getDoctrine()->getRepository('OroAttachmentBundle:Attachment')->findOneBy(array('id' => $attachmentId));
     $emailAttachment = new EmailAttachment();
     $modelEmailAttachment = new ModelEmailAttachment();
     $emailAttachment->setFile($attachment->getFile());
     $emailAttachment->setFileName($attachment->getFile()->getFileName());
     $emailAttachmentContent = new EmailAttachmentContent();
     $emailAttachment->setContentType($attachment->getFile()->getMimeType());
     $emailAttachment->setContent($emailAttachmentContent);
     $modelEmailAttachment->setType(ModelEmailAttachment::TYPE_ATTACHMENT);
     $modelEmailAttachment->setFileSize($attachment->getFile()->getFileSize());
     $modelEmailAttachment->setModified($attachment->getFile()->getUpdatedAt());
     $modelEmailAttachment->setId($attachment->getId());
     $modelEmailAttachment->setEmailAttachment($emailAttachment);
     //$emailModel->addAttachment($modelEmailAttachment);
     $emailModel->setAttachmentsAvailable([$modelEmailAttachment]);
     return $this->process($emailModel);
 }
 public function testFileNameGetterAndSetter()
 {
     $entity = new EmailAttachment();
     $entity->setFileName('test');
     $this->assertEquals('test', $entity->getFileName());
 }
Exemple #4
0
 /**
  * Process inline images. Convert it to embedded attachments and update message body.
  *
  * @param \Swift_Message $message
  * @param EmailModel     $model
  */
 protected function processEmbeddedImages(\Swift_Message $message, EmailModel $model)
 {
     if ($model->getType() === 'html') {
         $guesser = ExtensionGuesser::getInstance();
         $body = $message->getBody();
         $body = preg_replace_callback('/<img(.*)src(\\s*)=(\\s*)["\'](.*)["\']/U', function ($matches) use($message, $guesser, $model) {
             if (count($matches) === 5) {
                 // 1st match contains any data between '<img' and 'src' parts (e.g. 'width=100')
                 $imgConfig = $matches[1];
                 // 4th match contains src attribute value
                 $srcData = $matches[4];
                 if (strpos($srcData, 'data:image') === 0) {
                     list($mime, $content) = explode(';', $srcData);
                     list($encoding, $file) = explode(',', $content);
                     $mime = str_replace('data:', '', $mime);
                     $fileName = sprintf('%s.%s', uniqid(), $guesser->guess($mime));
                     $swiftAttachment = \Swift_Image::newInstance(ContentDecoder::decode($file, $encoding), $fileName, $mime);
                     /** @var $message \Swift_Message */
                     $id = $message->embed($swiftAttachment);
                     $attachmentContent = new EmailAttachmentContent();
                     $attachmentContent->setContent($file);
                     $attachmentContent->setContentTransferEncoding($encoding);
                     $emailAttachment = new EmailAttachment();
                     $emailAttachment->setEmbeddedContentId($swiftAttachment->getId());
                     $emailAttachment->setFileName($fileName);
                     $emailAttachment->setContentType($mime);
                     $attachmentContent->setEmailAttachment($emailAttachment);
                     $emailAttachment->setContent($attachmentContent);
                     $emailAttachmentModel = new EmailAttachmentModel();
                     $emailAttachmentModel->setEmailAttachment($emailAttachment);
                     $model->addAttachment($emailAttachmentModel);
                     return sprintf('<img%ssrc="%s"', $imgConfig, $id);
                 }
             }
         }, $body);
         $message->setBody($body, 'text/html');
     }
 }
 /**
  * Create EmailAttachment entity object
  *
  * @param string $fileName The attachment file name
  * @param string $contentType The attachment content type. It may be any MIME type
  * @return EmailAttachment
  */
 public function attachment($fileName, $contentType)
 {
     $result = new EmailAttachment();
     $result->setFileName($fileName)->setContentType($contentType);
     return $result;
 }