Files
provider_imap/lib/Client/Mailbox.php
2026-05-08 00:16:43 -04:00

102 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
use KTXM\ProviderImap\Client\Command\Result\StatusResult;
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 $state = null,
private readonly int $recent = 0,
private readonly array $flags = [],
private readonly bool $readOnly = true,
) {}
public function fromStatus(StatusResult $status): self
{
return new self(
$this->name,
$this->delimiter,
$this->attributes,
$status->messages() ?? $this->messages,
$status->unseen() ?? $this->unread,
$status->state() ?? $this->state,
$this->recent,
$this->flags,
$this->readOnly,
);
}
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 state(): ?int
{
return $this->state;
}
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);
}
}