generated from Nodarx/template
refactor: use custom imap client
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
28
lib/Client/Command/Result/CapabilityResult.php
Normal file
28
lib/Client/Command/Result/CapabilityResult.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Command\Result;
|
||||
|
||||
final class CapabilityResult
|
||||
{
|
||||
/**
|
||||
* @param list<string> $capabilities
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly array $capabilities,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function capabilities(): array
|
||||
{
|
||||
return $this->capabilities;
|
||||
}
|
||||
|
||||
public function has(string $capability): bool
|
||||
{
|
||||
return in_array(strtoupper($capability), $this->capabilities, true);
|
||||
}
|
||||
}
|
||||
28
lib/Client/Command/Result/CommandStatusResult.php
Normal file
28
lib/Client/Command/Result/CommandStatusResult.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Command\Result;
|
||||
|
||||
final class CommandStatusResult
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $status,
|
||||
private readonly string $text,
|
||||
) {}
|
||||
|
||||
public function status(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function text(): string
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
public function isOk(): bool
|
||||
{
|
||||
return $this->status === 'OK';
|
||||
}
|
||||
}
|
||||
152
lib/Client/Command/Result/MessageTransferResult.php
Normal file
152
lib/Client/Command/Result/MessageTransferResult.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Command\Result;
|
||||
|
||||
final class MessageTransferResult
|
||||
{
|
||||
/**
|
||||
* @param list<array{source:string, name:string, arguments:list<string>, text:string}> $responseCodes
|
||||
* @param ?array{uidValidity:string, sourceUids:string, destinationUids:string} $copyUid
|
||||
* @param list<int> $expunged
|
||||
* @param list<array{earlier:bool, knownUids:string}> $vanished
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly string $status,
|
||||
private readonly string $text,
|
||||
private readonly array $responseCodes = [],
|
||||
private readonly ?array $copyUid = null,
|
||||
private readonly bool $tryCreate = false,
|
||||
private readonly ?string $highestModSeq = null,
|
||||
private readonly array $expunged = [],
|
||||
private readonly array $vanished = [],
|
||||
) {}
|
||||
|
||||
public function status(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function text(): string
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
public function isOk(): bool
|
||||
{
|
||||
return $this->status === 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{source:string, name:string, arguments:list<string>, text:string}>
|
||||
*/
|
||||
public function responseCodes(): array
|
||||
{
|
||||
return $this->responseCodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?array{uidValidity:string, sourceUids:string, destinationUids:string}
|
||||
*/
|
||||
public function copyUid(): ?array
|
||||
{
|
||||
return $this->copyUid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string,string>
|
||||
*/
|
||||
public function copyUidMap(): array
|
||||
{
|
||||
if ($this->copyUid === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$sourceUids = $this->expandUidSet($this->copyUid['sourceUids']);
|
||||
$destinationUids = $this->expandUidSet($this->copyUid['destinationUids']);
|
||||
|
||||
if (count($sourceUids) !== count($destinationUids)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$mapping = [];
|
||||
foreach ($sourceUids as $index => $sourceUid) {
|
||||
$mapping[$sourceUid] = $destinationUids[$index];
|
||||
}
|
||||
|
||||
return $mapping;
|
||||
}
|
||||
|
||||
public function tryCreate(): bool
|
||||
{
|
||||
return $this->tryCreate;
|
||||
}
|
||||
|
||||
public function highestModSeq(): ?string
|
||||
{
|
||||
return $this->highestModSeq;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<int>
|
||||
*/
|
||||
public function expunged(): array
|
||||
{
|
||||
return $this->expunged;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{earlier:bool, knownUids:string}>
|
||||
*/
|
||||
public function vanished(): array
|
||||
{
|
||||
return $this->vanished;
|
||||
}
|
||||
|
||||
public function hasResponseCode(string $name): bool
|
||||
{
|
||||
$name = strtoupper(trim($name));
|
||||
|
||||
foreach ($this->responseCodes as $responseCode) {
|
||||
if ($responseCode['name'] === $name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function expandUidSet(string $value): array
|
||||
{
|
||||
$expanded = [];
|
||||
|
||||
foreach (explode(',', $value) as $segment) {
|
||||
$segment = trim($segment);
|
||||
if ($segment === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!str_contains($segment, ':')) {
|
||||
$expanded[] = $segment;
|
||||
continue;
|
||||
}
|
||||
|
||||
[$start, $end] = array_map('trim', explode(':', $segment, 2));
|
||||
|
||||
if (!ctype_digit($start) || !ctype_digit($end)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$range = range((int) $start, (int) $end, (int) $start <= (int) $end ? 1 : -1);
|
||||
foreach ($range as $uid) {
|
||||
$expanded[] = (string) $uid;
|
||||
}
|
||||
}
|
||||
|
||||
return $expanded;
|
||||
}
|
||||
}
|
||||
36
lib/Client/Command/Result/SearchResult.php
Normal file
36
lib/Client/Command/Result/SearchResult.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Command\Result;
|
||||
|
||||
use KTXM\ProviderImap\Client\IdentifierMode;
|
||||
|
||||
final class SearchResult
|
||||
{
|
||||
/**
|
||||
* @param list<int> $matches
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly array $matches,
|
||||
private readonly IdentifierMode $identifierMode,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return list<int>
|
||||
*/
|
||||
public function matches(): array
|
||||
{
|
||||
return $this->matches;
|
||||
}
|
||||
|
||||
public function identifierMode(): IdentifierMode
|
||||
{
|
||||
return $this->identifierMode;
|
||||
}
|
||||
|
||||
public function isUidSearch(): bool
|
||||
{
|
||||
return $this->identifierMode === IdentifierMode::Uid;
|
||||
}
|
||||
}
|
||||
36
lib/Client/Command/Result/SortResult.php
Normal file
36
lib/Client/Command/Result/SortResult.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Command\Result;
|
||||
|
||||
use KTXM\ProviderImap\Client\IdentifierMode;
|
||||
|
||||
final class SortResult
|
||||
{
|
||||
/**
|
||||
* @param list<int> $matches
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly array $matches,
|
||||
private readonly IdentifierMode $identifierMode,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return list<int>
|
||||
*/
|
||||
public function matches(): array
|
||||
{
|
||||
return $this->matches;
|
||||
}
|
||||
|
||||
public function identifierMode(): IdentifierMode
|
||||
{
|
||||
return $this->identifierMode;
|
||||
}
|
||||
|
||||
public function isUidSort(): bool
|
||||
{
|
||||
return $this->identifierMode === IdentifierMode::Uid;
|
||||
}
|
||||
}
|
||||
54
lib/Client/Command/Result/StatusResult.php
Normal file
54
lib/Client/Command/Result/StatusResult.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Command\Result;
|
||||
|
||||
final class StatusResult
|
||||
{
|
||||
/**
|
||||
* @param array<string, int> $items
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly string $mailbox,
|
||||
private readonly array $items,
|
||||
) {}
|
||||
|
||||
public function mailbox(): string
|
||||
{
|
||||
return $this->mailbox;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function items(): array
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
public function value(string $item, int $default = 0): int
|
||||
{
|
||||
return $this->items[strtoupper(trim($item))] ?? $default;
|
||||
}
|
||||
|
||||
public function messages(): int
|
||||
{
|
||||
return $this->value('MESSAGES');
|
||||
}
|
||||
|
||||
public function unseen(): int
|
||||
{
|
||||
return $this->value('UNSEEN');
|
||||
}
|
||||
|
||||
public function read(): int
|
||||
{
|
||||
return max(0, $this->messages() - $this->unseen());
|
||||
}
|
||||
|
||||
public function state(): int
|
||||
{
|
||||
return $this->value('UIDVALIDITY');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user