Files
2026-10-05 20:34:02 -04:00

118 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
use KTXM\ProviderImap\Client\Result\MailboxStatusResult;
final class Mailbox
{
/**
* @param list<string> $attributes
* @param list<string> $flags
*/
public function __construct(
private readonly string $name,
private readonly ?string $delimiter,
private readonly array $attributes,
private readonly int $messages = 0,
private readonly int $unread = 0,
private readonly ?int $uidValidity = null,
private readonly int $recent = 0,
private readonly array $flags = [],
private readonly bool $readOnly = true,
private readonly ?int $uidNext = null,
private readonly ?int $highestModSeq = null,
) {}
public function fromStatus(MailboxStatusResult $status): self
{
$items = $status->items();
return new self(
$this->name,
$this->delimiter,
$this->attributes,
$items['MESSAGES'] ?? $this->messages,
$items['UNSEEN'] ?? $this->unread,
$items['UIDVALIDITY'] ?? $this->uidValidity,
$this->recent,
$this->flags,
$this->readOnly,
$items['UIDNEXT'] ?? $this->uidNext,
$items['HIGHESTMODSEQ'] ?? $this->highestModSeq,
);
}
public function name(): string
{
return $this->name;
}
public function delimiter(): ?string
{
return $this->delimiter;
}
/**
* @return list<string>
*/
public function attributes(): array
{
return $this->attributes;
}
public function uidValidity(): ?int
{
return $this->uidValidity;
}
public function uidNext(): ?int
{
return $this->uidNext;
}
public function highestModSeq(): ?int
{
return $this->highestModSeq;
}
public function messages(): int
{
return $this->messages;
}
public function unread(): int
{
return $this->unread;
}
public function read(): int
{
return max(0, $this->messages - $this->unread);
}
public function recent(): int
{
return $this->recent;
}
/**
* @return list<string>
*/
public function flags(): array
{
return $this->flags;
}
public function readOnly(): bool
{
return $this->readOnly;
}
public function isSelectable(): bool
{
return !in_array('\\NOSELECT', $this->attributes, true);
}
}