refactor: use custom imap client

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-05-08 00:16:43 -04:00
parent a728aeb11c
commit a8764747fd
179 changed files with 6782 additions and 5907 deletions

View File

@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace KTXM\ProviderImap\Client\Protocol;
use KTXM\ProviderImap\Client\Transport\ConnectionInterface;
use Psr\Log\LoggerInterface;
final class ProtocolWriter
{
public function __construct(
private readonly ConnectionInterface $connection,
private readonly ?LoggerInterface $logger = null,
) {}
public function write(string $tag, RequestFrame $frame): void
{
$wire = $frame->toWire($tag);
$this->logger?->debug('IMAP command sent: {raw}', [
'tag' => $tag,
'command' => strtok($frame->commandLine(), ' ') ?: $frame->commandLine(),
'raw' => $this->sanitizeWire($wire),
]);
$this->connection->write($wire);
}
private function sanitizeWire(string $wire): string
{
$trimmed = rtrim($wire, "\r\n");
if (preg_match('/^(\S+\s+LOGIN\s+".*?"\s+)".*"$/i', $trimmed, $matches)) {
return $matches[1] . '"[REDACTED]"';
}
if (preg_match('/^(\S+\s+AUTHENTICATE\s+\S+)(?:\s+.+)?$/i', $trimmed, $matches)) {
return $matches[1] . ' [REDACTED]';
}
return $trimmed;
}
}