45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
namespace ProVM\Common\Service\Remote;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
use Ddeboer\Imap\ConnectionInterface;
|
|
use Ddeboer\Imap\MailboxInterface;
|
|
use ProVM\Common\Exception\Mailbox\Invalid;
|
|
|
|
/**
|
|
* Grab mailboxes from Email Provider
|
|
*/
|
|
class Mailboxes extends Base
|
|
{
|
|
public function __construct(ConnectionInterface $connection, LoggerInterface $logger)
|
|
{
|
|
$this->setConnection($connection)
|
|
->setLogger($logger);
|
|
}
|
|
|
|
protected array $mailboxes;
|
|
public function getAll(): array
|
|
{
|
|
if (!isset($this->mailboxes)) {
|
|
$this->mailboxes = $this->getConnection()->getMailboxes();
|
|
}
|
|
return $this->mailboxes;
|
|
}
|
|
|
|
/**
|
|
* @throws Invalid
|
|
*/
|
|
public function get(string $mailbox_name): MailboxInterface
|
|
{
|
|
if (!$this->getConnection()->hasMailbox($mailbox_name)) {
|
|
throw new Invalid($mailbox_name);
|
|
}
|
|
return $this->getConnection()->getMailbox($mailbox_name);
|
|
}
|
|
|
|
public function validate(string $mailbox_name, int $uidvalidity): bool
|
|
{
|
|
$mailbox = $this->get($mailbox_name);
|
|
return ($mailbox->getStatus()->uidvalidity === $uidvalidity);
|
|
}
|
|
} |