/**
  * Get a response for download the given email attachment
  *
  * @Route("/attachment/{id}", name="oro_email_attachment", requirements={"id"="\d+"})
  * @AclAncestor("oro_email_view")
  */
 public function attachmentAction(EmailAttachment $entity)
 {
     $response = new Response();
     $response->headers->set('Content-Type', $entity->getContentType());
     $response->headers->set('Content-Disposition', sprintf('attachment; filename="%s"', $entity->getFileName()));
     $response->headers->set('Pragma', 'no-cache');
     $response->headers->set('Expires', '0');
     $content = ContentDecoder::decode($entity->getContent()->getValue(), $entity->getContent()->getContentTransferEncoding());
     $response->setContent($content);
     return $response;
 }
Esempio n. 2
0
 public function testFileNameGetterAndSetter()
 {
     $entity = new EmailAttachment();
     $entity->setFileName('test');
     $this->assertEquals('test', $entity->getFileName());
 }
 /**
  * @param EmailAttachment $emailAttachment
  *
  * @return File|null
  */
 protected function copyEmailAttachmentToFileSystem(EmailAttachment $emailAttachment)
 {
     $file = new File();
     $file->setExtension($emailAttachment->getExtension());
     $file->setOriginalFilename($emailAttachment->getFileName());
     $file->setMimeType($emailAttachment->getContentType());
     $file->setFilename(uniqid() . '.' . $file->getExtension());
     $content = ContentDecoder::decode($emailAttachment->getContent()->getContent(), $emailAttachment->getContent()->getContentTransferEncoding());
     $this->filesystem->write($file->getFilename(), $content);
     $f = new ComponentFile($this->getAttachmentFullPath($file->getFilename()));
     $file->setFile($f);
     $file->setFileSize($f->getSize());
     $file->setUploaded(false);
     $file->setOwner($this->securityFacadeLink->getService()->getLoggedUser());
     return $file;
 }