refactor: re-organize files

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-09-25 11:32:25 -04:00
parent 3fdb7b7a2e
commit 9a86292bcf
47 changed files with 244 additions and 228 deletions
+9 -6
View File
@@ -4,11 +4,14 @@ declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
use KTXM\ProviderImap\Client\Command\CapabilityCommand;
use KTXM\ProviderImap\Client\Command\CommandInterface;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\Command\LoginCommand;
use KTXM\ProviderImap\Client\Command\StartTlsCommand;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
use KTXM\ProviderImap\Client\Protocol\Command\CapabilityCommand;
use KTXM\ProviderImap\Client\Protocol\Command\CommandInterface;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
use KTXM\ProviderImap\Client\Protocol\Command\LoginCommand;
use KTXM\ProviderImap\Client\Protocol\Command\StartTlsCommand;
use KTXM\ProviderImap\Client\Protocol\CommandExecutor;
use KTXM\ProviderImap\Client\Protocol\ProtocolReader;
use KTXM\ProviderImap\Client\Protocol\ProtocolWriter;
@@ -87,7 +90,7 @@ final class Client implements ClientInterface
return $this->executor->perform($command, $this->session);
}
public function download(FetchTarget $target, string $section, int $chunkSize = 8192): \Generator
public function download(MessageTarget $target, string $section, int $chunkSize = 8192): \Generator
{
if ($this->session === null || $this->executor === null) {
throw new ImapException('IMAP client is not connected.');
+3 -3
View File
@@ -4,8 +4,8 @@ declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
use KTXM\ProviderImap\Client\Command\CommandInterface;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\Protocol\Command\CommandInterface;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
interface ClientInterface
{
@@ -28,5 +28,5 @@ interface ClientInterface
*
* @return \Generator<string> raw (transfer-encoded) bytes from the socket
*/
public function download(FetchTarget $target, string $section, int $chunkSize = 8192): \Generator;
public function download(MessageTarget $target, string $section, int $chunkSize = 8192): \Generator;
}
-16
View File
@@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
enum IdentifierMode
{
case Sequence;
case Uid;
public function toCommand(): string
{
return $this === self::Uid ? 'UID FETCH' : 'FETCH';
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
use KTXM\ProviderImap\Client\Command\Result\StatusResult;
use KTXM\ProviderImap\Client\Result\StatusResult;
final class Mailbox
{
@@ -2,15 +2,15 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\ContinuationResponse;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* APPEND a raw RFC822 message to a mailbox (RFC 3501 §6.3.11).
@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
namespace KTXM\ProviderImap\Client\Protocol\Command\Argument;
final class FetchOptions
{
@@ -2,7 +2,9 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
namespace KTXM\ProviderImap\Client\Protocol\Command\Argument;
use KTXM\ProviderImap\Client\ImapException;
final class ListReturnOptions
{
@@ -2,7 +2,9 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
namespace KTXM\ProviderImap\Client\Protocol\Command\Argument;
use KTXM\ProviderImap\Client\ImapException;
final class ListSelectionOptions
{
@@ -2,9 +2,12 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
namespace KTXM\ProviderImap\Client\Protocol\Command\Argument;
final class FetchTarget
use KTXM\ProviderImap\Client\Protocol\SequenceSet;
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
final class MessageTarget
{
private function __construct(
private readonly SequenceSet $sequenceSet,
@@ -36,11 +39,6 @@ final class FetchTarget
return $this->identifierMode;
}
public function toCommand(): string
{
return $this->identifierMode->toCommand();
}
private static function coerceSequenceSet(int|string|SequenceSet $target): SequenceSet
{
return match (true) {
@@ -2,7 +2,9 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
namespace KTXM\ProviderImap\Client\Protocol\Command\Argument;
use KTXM\ProviderImap\Client\Protocol\SequenceSet;
use DateTimeInterface;
use InvalidArgumentException;
@@ -2,16 +2,16 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\CapabilityResult;
use KTXM\ProviderImap\Client\Result\CapabilityResult;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\Response\UntaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<CapabilityResult>
@@ -2,12 +2,12 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @template TResult
@@ -2,14 +2,14 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\MessageTransferResult;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\Result\MessageTransferResult;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SequenceSet;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SequenceSet;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
/**
* @implements CommandInterface<MessageTransferResult>
@@ -19,7 +19,7 @@ final class CopyCommand implements CommandInterface
private readonly MessageTransferCommand $command;
public function __construct(
FetchTarget|string|SequenceSet|null $target = null,
MessageTarget|string|SequenceSet|null $target = null,
string $destinationMailbox = '',
) {
$this->command = new MessageTransferCommand('COPY', $target, $destinationMailbox);
@@ -2,15 +2,15 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<CommandStatusResult>
@@ -2,15 +2,15 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<CommandStatusResult>
@@ -2,18 +2,18 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\IdentifierMode;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\Response\UntaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SequenceSet;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SequenceSet;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<list<int>>
@@ -22,7 +22,7 @@ final class ExpungeCommand implements CommandInterface
{
private readonly ?SequenceSet $sequenceSet;
public function __construct(FetchTarget|string|SequenceSet|null $target = null)
public function __construct(MessageTarget|string|SequenceSet|null $target = null)
{
if ($target === null) {
$this->sequenceSet = null;
@@ -31,9 +31,9 @@ final class ExpungeCommand implements CommandInterface
}
$resolvedTarget = match (true) {
$target instanceof FetchTarget => $target,
$target instanceof SequenceSet => FetchTarget::sequence($target),
is_string($target) => FetchTarget::sequence($target),
$target instanceof MessageTarget => $target,
$target instanceof SequenceSet => MessageTarget::sequence($target),
is_string($target) => MessageTarget::sequence($target),
default => null,
};
@@ -2,34 +2,37 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
use KTXM\ProviderImap\Client\Protocol\Parser\FetchResponseParser;
use Generator;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\FetchOptions;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\FetchOptions;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Message;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SequenceSet;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SequenceSet;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<Generator<int, Message>>
*/
final class FetchManyCommand implements CommandInterface
{
private readonly FetchTarget $target;
private readonly MessageTarget $target;
private readonly FetchOptions $options;
public function __construct(FetchTarget|string|SequenceSet|null $target = null, ?FetchOptions $options = null)
public function __construct(MessageTarget|string|SequenceSet|null $target = null, ?FetchOptions $options = null)
{
$this->target = match (true) {
$target instanceof FetchTarget => $target,
$target instanceof SequenceSet => FetchTarget::sequence($target),
is_string($target) => FetchTarget::sequence($target),
default => FetchTarget::all(),
$target instanceof MessageTarget => $target,
$target instanceof SequenceSet => MessageTarget::sequence($target),
is_string($target) => MessageTarget::sequence($target),
default => MessageTarget::all(),
};
$this->options = $options ?? FetchOptions::default();
}
@@ -50,7 +53,7 @@ final class FetchManyCommand implements CommandInterface
return new RequestFrame(sprintf(
'%s %s (%s)',
$this->target->toCommand(),
$this->target->identifierMode() === IdentifierMode::Uid ? 'UID FETCH' : 'FETCH',
$this->target->sequenceSet()->toCommand(),
$this->options->toCommand(),
));
@@ -2,30 +2,33 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\FetchOptions;
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
use KTXM\ProviderImap\Client\Protocol\Parser\FetchResponseParser;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\FetchOptions;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Message;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<Message>
*/
final class FetchOneCommand implements CommandInterface
{
private readonly FetchTarget $target;
private readonly MessageTarget $target;
private readonly FetchOptions $options;
public function __construct(FetchTarget|int|string $target, ?FetchOptions $options = null)
public function __construct(MessageTarget|int|string $target, ?FetchOptions $options = null)
{
$this->target = $target instanceof FetchTarget
$this->target = $target instanceof MessageTarget
? $target
: FetchTarget::sequence($target);
: MessageTarget::sequence($target);
$this->options = $options ?? FetchOptions::default();
}
@@ -45,7 +48,7 @@ final class FetchOneCommand implements CommandInterface
return new RequestFrame(sprintf(
'%s %s (%s)',
$this->target->toCommand(),
$this->target->identifierMode() === IdentifierMode::Uid ? 'UID FETCH' : 'FETCH',
$this->target->sequenceSet()->toCommand(),
$this->options->toCommand(),
));
@@ -2,19 +2,20 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Protocol\Parser\StatusResponseParser;
use Generator;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\ListReturnOptions;
use KTXM\ProviderImap\Client\ListSelectionOptions;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\ListReturnOptions;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\ListSelectionOptions;
use KTXM\ProviderImap\Client\Mailbox;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\Response\UntaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<Generator<int, Mailbox>>
@@ -2,15 +2,15 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<CommandStatusResult>
@@ -2,15 +2,15 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<CommandStatusResult>
@@ -2,19 +2,19 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\MessageTransferResult;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\IdentifierMode;
use KTXM\ProviderImap\Client\Result\MessageTransferResult;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\Response\UntaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SequenceSet;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SequenceSet;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<MessageTransferResult>
@@ -27,14 +27,14 @@ final class MessageTransferCommand implements CommandInterface
public function __construct(
string $operation,
FetchTarget|string|SequenceSet|null $target = null,
MessageTarget|string|SequenceSet|null $target = null,
private readonly string $destinationMailbox = '',
) {
$resolvedTarget = match (true) {
$target instanceof FetchTarget => $target,
$target instanceof SequenceSet => FetchTarget::sequence($target),
is_string($target) => FetchTarget::sequence($target),
default => FetchTarget::all(),
$target instanceof MessageTarget => $target,
$target instanceof SequenceSet => MessageTarget::sequence($target),
is_string($target) => MessageTarget::sequence($target),
default => MessageTarget::all(),
};
$this->operation = strtoupper(trim($operation));
@@ -2,14 +2,14 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\MessageTransferResult;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\Result\MessageTransferResult;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SequenceSet;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SequenceSet;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
/**
* @implements CommandInterface<MessageTransferResult>
@@ -19,7 +19,7 @@ final class MoveCommand implements CommandInterface
private readonly MessageTransferCommand $command;
public function __construct(
FetchTarget|string|SequenceSet|null $target = null,
MessageTarget|string|SequenceSet|null $target = null,
string $destinationMailbox = '',
) {
$this->command = new MessageTransferCommand('MOVE', $target, $destinationMailbox);
@@ -2,15 +2,15 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<CommandStatusResult>
@@ -2,15 +2,15 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<CommandStatusResult>
@@ -2,18 +2,18 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\SearchResult;
use KTXM\ProviderImap\Client\IdentifierMode;
use KTXM\ProviderImap\Client\Result\SearchResult;
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\SearchCriteriaBuilder;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\SearchCriteriaBuilder;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\Response\UntaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<SearchResult>
@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Mailbox;
@@ -10,8 +10,8 @@ use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\Response\UntaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<Mailbox>
@@ -2,18 +2,18 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\SortResult;
use KTXM\ProviderImap\Client\IdentifierMode;
use KTXM\ProviderImap\Client\Result\SortResult;
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\Response\UntaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SearchCriteriaBuilder;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\SearchCriteriaBuilder;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<SortResult>
@@ -2,15 +2,15 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<CommandStatusResult>
@@ -2,16 +2,17 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\StatusResult;
use KTXM\ProviderImap\Client\Protocol\Parser\StatusResponseParser;
use KTXM\ProviderImap\Client\Result\StatusResult;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\Response\UntaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<StatusResult>
@@ -2,18 +2,18 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Command;
use KTXM\ProviderImap\Client\Command\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\IdentifierMode;
use KTXM\ProviderImap\Client\Result\CommandStatusResult;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
use KTXM\ProviderImap\Client\SequenceSet;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SequenceSet;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
/**
* @implements CommandInterface<CommandStatusResult>
@@ -27,16 +27,16 @@ final class StoreCommand implements CommandInterface
* @param list<string> $flags
*/
public function __construct(
FetchTarget|string|SequenceSet|null $target = null,
MessageTarget|string|SequenceSet|null $target = null,
private array $flags = [],
private string $action = '',
private bool $silent = true,
) {
$resolvedTarget = match (true) {
$target instanceof FetchTarget => $target,
$target instanceof SequenceSet => FetchTarget::sequence($target),
is_string($target) => FetchTarget::sequence($target),
default => FetchTarget::all(),
$target instanceof MessageTarget => $target,
$target instanceof SequenceSet => MessageTarget::sequence($target),
is_string($target) => MessageTarget::sequence($target),
default => MessageTarget::all(),
};
$normalizedAction = trim($this->action);
+5 -5
View File
@@ -5,14 +5,14 @@ declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Protocol;
use Generator;
use KTXM\ProviderImap\Client\Command\CommandInterface;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\Protocol\Command\CommandInterface;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\Response\UntaggedResponse;
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
use KTXM\ProviderImap\Client\SessionContext;
use KTXM\ProviderImap\Client\SessionState;
use KTXM\ProviderImap\Client\Protocol\SessionContext;
use KTXM\ProviderImap\Client\Protocol\SessionState;
use Psr\Log\LoggerInterface;
final class CommandExecutor
@@ -62,7 +62,7 @@ final class CommandExecutor
*
* @return \Generator<string> raw (transfer-encoded) bytes from the socket
*/
public function download(FetchTarget $target, string $section, int $chunkSize, SessionContext $context): \Generator
public function download(MessageTarget $target, string $section, int $chunkSize, SessionContext $context): \Generator
{
$this->assertState([SessionState::Selected], $context->state(), 'FETCH (download)');
+11
View File
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Protocol;
enum IdentifierMode
{
case Sequence;
case Uid;
}
@@ -2,12 +2,12 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Parser;
use Generator;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Message;
use KTXM\ProviderImap\Client\MessageParser;
use KTXM\ProviderImap\Client\Protocol\Parser\MessageParser;
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
use KTXM\ProviderImap\Client\Protocol\Response\UntaggedResponse;
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
@@ -2,8 +2,12 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
namespace KTXM\ProviderImap\Client\Protocol\Parser;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\Message;
use KTXM\ProviderImap\Client\MessageAddress;
use KTXM\ProviderImap\Client\MessagePart;
use DateTimeInterface;
final class MessageParser
@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command;
namespace KTXM\ProviderImap\Client\Protocol\Parser;
use KTXM\ProviderImap\Client\ImapException;
@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
namespace KTXM\ProviderImap\Client\Protocol;
use InvalidArgumentException;
@@ -2,7 +2,9 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
namespace KTXM\ProviderImap\Client\Protocol;
use KTXM\ProviderImap\Client\ConnectionConfig;
use KTXM\ProviderImap\Client\Protocol\Response\GreetingResponse;
use KTXM\ProviderImap\Client\Transport\ConnectionInterface;
@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client;
namespace KTXM\ProviderImap\Client\Protocol;
enum SessionState: string
{
@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command\Result;
namespace KTXM\ProviderImap\Client\Result;
final class CapabilityResult
{
@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command\Result;
namespace KTXM\ProviderImap\Client\Result;
final class CommandStatusResult
{
@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command\Result;
namespace KTXM\ProviderImap\Client\Result;
final class MessageTransferResult
{
@@ -2,9 +2,9 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command\Result;
namespace KTXM\ProviderImap\Client\Result;
use KTXM\ProviderImap\Client\IdentifierMode;
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
final class SearchResult
{
@@ -2,9 +2,9 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command\Result;
namespace KTXM\ProviderImap\Client\Result;
use KTXM\ProviderImap\Client\IdentifierMode;
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
final class SortResult
{
@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Command\Result;
namespace KTXM\ProviderImap\Client\Result;
final class StatusResult
{
+5 -5
View File
@@ -10,11 +10,11 @@ declare(strict_types=1);
namespace KTXM\ProviderImap\Console;
use KTXC\Context\TenantContext;
use KTXM\ProviderImap\Client\Command\SelectCommand;
use KTXM\ProviderImap\Client\FetchOptions;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\Protocol\Command\SelectCommand;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\FetchOptions;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
use KTXM\ProviderImap\Client\Message;
use KTXM\ProviderImap\Client\SequenceSet;
use KTXM\ProviderImap\Client\Protocol\SequenceSet;
use KTXM\ProviderImap\Providers\Provider;
use KTXM\ProviderImap\Providers\Service;
use KTXM\ProviderImap\Service\Remote\RemoteMailService;
@@ -209,7 +209,7 @@ class TestCommand extends Command
try {
foreach ($mailboxService->messageList(
$mailboxName,
FetchTarget::sequence(SequenceSet::range($startSequence, $totalMessages)),
MessageTarget::sequence(SequenceSet::range($startSequence, $totalMessages)),
FetchOptions::message(),
) as $message) {
$messageRows[] = [
+35 -35
View File
@@ -13,32 +13,32 @@ use DateTimeImmutable;
use Generator;
use KTXC\Logger\PlainFileLogger;
use KTXM\ProviderImap\Client\Client as ImapClient;
use KTXM\ProviderImap\Client\Command\AppendCommand;
use KTXM\ProviderImap\Client\Command\FetchManyCommand;
use KTXM\ProviderImap\Client\Command\FetchOneCommand;
use KTXM\ProviderImap\Client\Command\ExpungeCommand;
use KTXM\ProviderImap\Client\Command\ListCommand;
use KTXM\ProviderImap\Client\Command\SearchCommand;
use KTXM\ProviderImap\Client\Command\SelectCommand;
use KTXM\ProviderImap\Client\Command\SortCommand;
use KTXM\ProviderImap\Client\Command\StatusCommand;
use KTXM\ProviderImap\Client\Command\StoreCommand;
use KTXM\ProviderImap\Client\Command\CopyCommand;
use KTXM\ProviderImap\Client\Command\CreateCommand;
use KTXM\ProviderImap\Client\Command\RenameCommand;
use KTXM\ProviderImap\Client\Command\DeleteCommand;
use KTXM\ProviderImap\Client\FetchTarget;
use KTXM\ProviderImap\Client\FetchOptions;
use KTXM\ProviderImap\Client\IdentifierMode;
use KTXM\ProviderImap\Client\Protocol\Command\AppendCommand;
use KTXM\ProviderImap\Client\Protocol\Command\FetchManyCommand;
use KTXM\ProviderImap\Client\Protocol\Command\FetchOneCommand;
use KTXM\ProviderImap\Client\Protocol\Command\ExpungeCommand;
use KTXM\ProviderImap\Client\Protocol\Command\ListCommand;
use KTXM\ProviderImap\Client\Protocol\Command\SearchCommand;
use KTXM\ProviderImap\Client\Protocol\Command\SelectCommand;
use KTXM\ProviderImap\Client\Protocol\Command\SortCommand;
use KTXM\ProviderImap\Client\Protocol\Command\StatusCommand;
use KTXM\ProviderImap\Client\Protocol\Command\StoreCommand;
use KTXM\ProviderImap\Client\Protocol\Command\CopyCommand;
use KTXM\ProviderImap\Client\Protocol\Command\CreateCommand;
use KTXM\ProviderImap\Client\Protocol\Command\RenameCommand;
use KTXM\ProviderImap\Client\Protocol\Command\DeleteCommand;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\MessageTarget;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\FetchOptions;
use KTXM\ProviderImap\Client\Protocol\IdentifierMode;
use KTXM\ProviderImap\Client\ImapException;
use KTXM\ProviderImap\Client\ListReturnOptions;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\ListReturnOptions;
use KTXM\ProviderImap\Client\Mailbox;
use KTXM\ProviderImap\Client\Message;
use KTXM\ProviderImap\Client\MessageAddress;
use KTXM\ProviderImap\Client\MessagePart;
use KTXM\ProviderImap\Client\Command\MoveCommand;
use KTXM\ProviderImap\Client\SearchCriteriaBuilder;
use KTXM\ProviderImap\Client\SequenceSet;
use KTXM\ProviderImap\Client\Protocol\Command\MoveCommand;
use KTXM\ProviderImap\Client\Protocol\Command\Argument\SearchCriteriaBuilder;
use KTXM\ProviderImap\Client\Protocol\SequenceSet;
use KTXF\Mail\Collection\CollectionRoles;
use KTXF\Resource\Filter\IFilter;
use KTXF\Resource\Filter\FilterComparisonOperator;
@@ -327,7 +327,7 @@ class RemoteMailService
}
yield from $this->imapClient()->perform(new FetchManyCommand(
FetchTarget::all(),
MessageTarget::all(),
$options,
));
@@ -360,7 +360,7 @@ class RemoteMailService
$this->imapClient()->perform(new SelectCommand($collection, true));
$request = new FetchManyCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
MessageTarget::uid(SequenceSet::items(...array_values($uids))),
$options,
);
@@ -392,7 +392,7 @@ class RemoteMailService
} else {
// Fetch BODYSTRUCTURE first to determine metadata (no body bytes transferred)
$message = $this->imapClient()->perform(new FetchOneCommand(
FetchTarget::uid(SequenceSet::items($uid)),
MessageTarget::uid(SequenceSet::items($uid)),
FetchOptions::of('BODYSTRUCTURE'),
));
$bodyStructure = $message->bodyStructure();
@@ -407,7 +407,7 @@ class RemoteMailService
// Start download stream
$stream = $this->decodeStream(
$this->imapClient()->download(FetchTarget::uid(SequenceSet::items($uid)), $partId ?? ''),
$this->imapClient()->download(MessageTarget::uid(SequenceSet::items($uid)), $partId ?? ''),
$encoding
);
@@ -543,7 +543,7 @@ class RemoteMailService
$this->imapClient()->perform(new SelectCommand($collection, false));
$this->imapClient()->perform(new StoreCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
MessageTarget::uid(SequenceSet::items(...array_values($uids))),
$flags,
$action,
));
@@ -558,7 +558,7 @@ class RemoteMailService
return [];
}
$target = FetchTarget::uid(SequenceSet::items(...array_values($uids)));
$target = MessageTarget::uid(SequenceSet::items(...array_values($uids)));
$this->imapClient()->perform(new SelectCommand($collection, false));
$this->imapClient()->perform(new StoreCommand($target, ['\\Deleted'], '+'));
@@ -581,7 +581,7 @@ class RemoteMailService
if (!empty($flagsToAdd)) {
$this->imapClient()->perform(new StoreCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
MessageTarget::uid(SequenceSet::items(...array_values($uids))),
$flagsToAdd,
'+',
));
@@ -589,7 +589,7 @@ class RemoteMailService
if (!empty($flagsToRemove)) {
$this->imapClient()->perform(new StoreCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
MessageTarget::uid(SequenceSet::items(...array_values($uids))),
$flagsToRemove,
'-',
));
@@ -608,23 +608,23 @@ class RemoteMailService
if ($rfc6851) {
$this->imapClient()->perform(new SelectCommand($sourceCollection, false));
$response = $this->imapClient()->perform(new MoveCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
MessageTarget::uid(SequenceSet::items(...array_values($uids))),
$targetCollection,
));
} else {
$this->imapClient()->perform(new SelectCommand($sourceCollection, false));
$response = $this->imapClient()->perform(new CopyCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
MessageTarget::uid(SequenceSet::items(...array_values($uids))),
$targetCollection,
));
if ($response->isOk()) {
$this->imapClient()->perform(new StoreCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
MessageTarget::uid(SequenceSet::items(...array_values($uids))),
['\\Deleted'],
'+',
));
$this->imapClient()->perform(new ExpungeCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
MessageTarget::uid(SequenceSet::items(...array_values($uids))),
));
}
}
@@ -656,7 +656,7 @@ class RemoteMailService
$this->imapClient()->perform(new SelectCommand($sourceCollection, false));
$response = $this->imapClient()->perform(new CopyCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
MessageTarget::uid(SequenceSet::items(...array_values($uids))),
$targetCollection,
));
@@ -881,7 +881,7 @@ class RemoteMailService
}
$messages = iterator_to_array($this->imapClient()->perform(new FetchManyCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
MessageTarget::uid(SequenceSet::items(...array_values($uids))),
$options,
)));