feat: initial version

Signed-off-by: Sebastian Krupinski <root@LAPTOP-7DVOR6NC>
This commit was merged in pull request #1.
This commit is contained in:
Sebastian Krupinski
2026-02-20 16:41:19 -05:00
committed by Sebastian Krupinski
parent a313767846
commit e51c65bf19
139 changed files with 11256 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace Gricob\IMAP\Protocol;
use Generator;
use Gricob\IMAP\Protocol\Command\Command;
use Gricob\IMAP\Protocol\Command\Continuable;
use Gricob\IMAP\Protocol\Response\Line\Line;
use Gricob\IMAP\Protocol\Response\Line\Status\Status;
use Gricob\IMAP\Protocol\Response\Response;
use Gricob\IMAP\Transport\Connection;
use RuntimeException;
final readonly class CommandInteraction implements ContinuationHandler
{
public function __construct(
private Connection $connection,
private ResponseHandler $responseHandler,
private string $tag,
private Command $command,
) {
}
public function interact(): Response
{
$request = sprintf(
"%s %s\r\n",
$this->tag,
$this->command,
);
$this->connection->send($request);
$streamResponse = $this->connection->receive();
return $this->responseHandler->handle($this->tag, $streamResponse, $this);
}
/**
* Like interact() but yields each untagged Line immediately as it arrives.
* The terminal Status is the generator's return value.
*
* @return Generator<int, Line, mixed, Status>
*/
public function streamInteract(): Generator
{
$request = sprintf(
"%s %s\r\n",
$this->tag,
$this->command,
);
$this->connection->send($request);
$streamResponse = $this->connection->receive();
yield from $this->responseHandler->stream($this->tag, $streamResponse, $this);
}
public function continue(): void
{
if (!$this->command instanceof Continuable) {
throw new RuntimeException(
sprintf('Command %s does not support continuable interaction', $this->command->command())
);
}
$this->connection->send($this->command->continue()."\r\n");
}
}