Download attachments
This commit is contained in:
@ -7,6 +7,7 @@ use Psr\Http\Message\ServerRequestInterface;
|
||||
use ProVM\Common\Implement\Controller\Json;
|
||||
use ProVM\Common\Service\Attachments as Service;
|
||||
use ProVM\Emails\Model\Attachment;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Attachments
|
||||
{
|
||||
@ -51,4 +52,13 @@ class Attachments
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service $service, LoggerInterface $logger, int $attachment_id): ResponseInterface
|
||||
{
|
||||
$attachment = $service->getRepository()->fetchById($attachment_id);
|
||||
|
||||
$response->withHeader('Content-Type', 'application/pdf');
|
||||
$response->withHeader('Content-Disposition', "'attachment;filename='{$attachment->getFullFilename()}'");
|
||||
$response->getBody()->write($service->getFile($attachment_id));
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -3,9 +3,11 @@ namespace ProVM\Common\Service;
|
||||
|
||||
use Ddeboer\Imap\Message\AttachmentInterface;
|
||||
use Ddeboer\Imap\MessageInterface;
|
||||
use Nyholm\Psr7\Stream;
|
||||
use ProVM\Common\Exception\Message\NoAttachments;
|
||||
use ProVM\Emails\Model\Message;
|
||||
use ProVM\Emails\Repository\Attachment;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Safe\Exceptions\FilesystemException;
|
||||
|
||||
@ -84,6 +86,22 @@ class Attachments extends Base
|
||||
$remote_message = $this->getMessages()->getRemoteMessage($message->getUID());
|
||||
return $this->getRemoteService()->get($remote_message, $relative_filename);
|
||||
}
|
||||
public function getFile(int $attachment_id): string
|
||||
{
|
||||
$attachment = $this->getRepository()->fetchById($attachment_id);
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->getFolder(),
|
||||
$attachment->getFullFilename()
|
||||
]);
|
||||
if ($attachment->isDecrypted()) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->getFolder(),
|
||||
'decrypted',
|
||||
$attachment->getFullFilename()
|
||||
]);
|
||||
}
|
||||
return \Safe\file_get_contents($filename);
|
||||
}
|
||||
|
||||
public function getAll(): array
|
||||
{
|
||||
|
Reference in New Issue
Block a user