public function testContentGetterAndSetter() { $content = $this->getMock('Oro\\Bundle\\EmailBundle\\Entity\\EmailAttachmentContent'); $entity = new EmailAttachment(); $entity->setContent($content); $this->assertTrue($content === $entity->getContent()); }
/** * @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; }
/** * 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; }
/** * @param EmailAttachment $attachment * @return bool */ protected function supportsAttachment(EmailAttachment $attachment) { return $attachment->getContent()->getContentTransferEncoding() === 'base64' && strpos($attachment->getContentType(), 'image/') === 0; }