From 460d06c1f9a0d43d0cb6124b9c0f351065b8fa03 Mon Sep 17 00:00:00 2001
From: Pascal Eyacher
Date: Thu, 29 Aug 2024 15:38:03 +0200
Subject: [PATCH] Fix for failed call to Laminas\Mail\Storage\Imap->close() on
invalid server response
Signed-off-by: Pascal Eyacher
---
src/Protocol/Imap.php | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/Protocol/Imap.php b/src/Protocol/Imap.php
index ce9f87da..34321a46 100644
--- a/src/Protocol/Imap.php
+++ b/src/Protocol/Imap.php
@@ -169,6 +169,10 @@ protected function nextTaggedLine(&$tag)
{
$line = $this->nextLine();
+ if (! str_contains($line, ' ')) {
+ throw new Exception\RuntimeException('Invalid response line received: ' . $line);
+ }
+
// separate tag from line
[$tag, $line] = explode(' ', $line, 2);
@@ -445,9 +449,10 @@ public function logout()
$result = $this->requestAndResponse('LOGOUT', [], true);
} catch (Exception\ExceptionInterface) {
// ignoring exception
+ } finally {
+ fclose($this->socket);
+ $this->socket = null;
}
- fclose($this->socket);
- $this->socket = null;
}
return $result;
}