Download attachments

This commit is contained in:
2022-11-29 11:12:06 -03:00
parent c53eb4c7a6
commit f8500e061c
21 changed files with 242 additions and 27 deletions

View File

@ -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
{