Full implemantation
This commit is contained in:
45
api/common/Service/Remote/Mailboxes.php
Normal file
45
api/common/Service/Remote/Mailboxes.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user