feat: implement download

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-05-23 20:18:58 -04:00
parent 640e3aa811
commit 9cdebd82b8
15 changed files with 336 additions and 172 deletions

View File

@@ -135,6 +135,26 @@ final class SocketConnection implements ConnectionInterface
return $buffer;
}
public function readBytesChunked(int $length, int $chunkSize = 8192): \Generator
{
if ($length < 0) {
throw new ImapException('IMAP socket cannot read a negative number of bytes.');
}
$remaining = $length;
while ($remaining > 0) {
$chunk = fread($this->stream(), min($chunkSize, $remaining));
if ($chunk === false || $chunk === '') {
throw new ImapException('Failed to read literal payload from IMAP socket.');
}
$remaining -= strlen($chunk);
yield $chunk;
}
}
public function upgradeToTls(): void
{
$stream = $this->stream();