generated from Nodarx/template
refactor: use custom imap client
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
44
lib/Client/Protocol/ProtocolWriter.php
Normal file
44
lib/Client/Protocol/ProtocolWriter.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user