31 lines
913 B
PHP
31 lines
913 B
PHP
<?php
|
|
namespace ProVM\Common\Service\Remote;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
use Ddeboer\Imap\ConnectionInterface;
|
|
use Ddeboer\Imap\MessageInterface;
|
|
use Ddeboer\Imap\Message\AttachmentInterface;
|
|
use ProVM\Common\Exception\Attachment\NotFound;
|
|
|
|
class Attachments extends Base
|
|
{
|
|
public function __construct(ConnectionInterface $connection, LoggerInterface $logger)
|
|
{
|
|
$this->setConnection($connection)
|
|
->setLogger($logger);
|
|
}
|
|
|
|
public function getAttachments(MessageInterface $message): array
|
|
{
|
|
return $message->getAttachments();
|
|
}
|
|
public function get(MessageInterface $message, string $filename): AttachmentInterface
|
|
{
|
|
foreach ($message->getAttachments() as $attachment) {
|
|
if ($attachment->getFilename() === $filename) {
|
|
return $attachment;
|
|
}
|
|
}
|
|
throw new NotFound($message, $filename);
|
|
}
|
|
} |