From c9271a8a6f89132433bc03f329c9747674a0c8af Mon Sep 17 00:00:00 2001 From: Gordon Zhao Date: Sat, 17 Dec 2022 20:52:27 +1000 Subject: [PATCH 1/4] https://github.com/Webklex/php-imap/issues/291 --- src/Connection/Protocols/ImapProtocol.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Connection/Protocols/ImapProtocol.php b/src/Connection/Protocols/ImapProtocol.php index e81c96e9..c7472826 100644 --- a/src/Connection/Protocols/ImapProtocol.php +++ b/src/Connection/Protocols/ImapProtocol.php @@ -110,15 +110,12 @@ protected function enableStartTls(){ * @throws RuntimeException */ public function nextLine(): string { - $line = ""; - while (($next_char = fread($this->stream, 1)) !== false && $next_char !== "\n") { - $line .= $next_char; + $line = fgets($this->stream); + if ($line === false) { + throw new RuntimeException('no response'); } - if ($line === "" && $next_char === false) { - throw new RuntimeException('empty response'); - } - if ($this->debug) echo "<< ".$line."\n"; - return $line . "\n"; + if ($this->debug) echo "<< ".$line; + return $line; } /** From c78c793a249d6b19d8f4d1f979cd4f9a1caedac4 Mon Sep 17 00:00:00 2001 From: Gordon Zhao Date: Sat, 17 Dec 2022 22:29:27 +1000 Subject: [PATCH 2/4] logout function $this->stream is null --- src/Connection/Protocols/ImapProtocol.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Connection/Protocols/ImapProtocol.php b/src/Connection/Protocols/ImapProtocol.php index c7472826..49aa7ac9 100644 --- a/src/Connection/Protocols/ImapProtocol.php +++ b/src/Connection/Protocols/ImapProtocol.php @@ -467,16 +467,16 @@ public function authenticate(string $user, string $token): bool { * @throws RuntimeException */ public function logout(): array { - if (!$this->stream) { - throw new RuntimeException('not connected'); + $result = []; + if ($this->stream) { + try { + $result = $this->requestAndResponse('LOGOUT', [], true); + } catch (Exception $e) {} + fclose($this->stream); + $this->stream = null; + $this->uid_cache = null; } - $result = $this->requestAndResponse('LOGOUT', [], true); - - fclose($this->stream); - $this->stream = null; - $this->uid_cache = null; - return $result; } From 650118b2c6506fc57af1a6d1ffa6767483564301 Mon Sep 17 00:00:00 2001 From: Gordon Zhao Date: Sun, 8 Jan 2023 01:27:49 +1000 Subject: [PATCH 3/4] https://github.com/Webklex/php-imap/issues/352 --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 5af56423..a9099803 100755 --- a/src/Client.php +++ b/src/Client.php @@ -647,7 +647,7 @@ public function getQuotaRoot(string $quota_root = 'INBOX'): array { * @throws ConnectionFailedException * @throws Exceptions\RuntimeException */ - public function expunge(): bool { + public function expunge(): array { $this->checkConnection(); return $this->connection->expunge(); } From 1d363799b4f373e8e7df10aedb9f9e7bebb0be70 Mon Sep 17 00:00:00 2001 From: Gordon Zhao Date: Mon, 20 Nov 2023 20:42:02 +1000 Subject: [PATCH 4/4] https://github.com/Webklex/php-imap/pull/372 --- src/Message.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message.php b/src/Message.php index 4137db9a..35062266 100755 --- a/src/Message.php +++ b/src/Message.php @@ -589,7 +589,7 @@ protected function fetchAttachment(Part $part) { $oAttachment = new Attachment($this, $part); if ($oAttachment->getName() !== null && $oAttachment->getSize() > 0) { - if ($oAttachment->getId() !== null) { + if ($oAttachment->getId() !== null && $this->attachments->offsetExists($oAttachment->getId())) { $this->attachments->put($oAttachment->getId(), $oAttachment); } else { $this->attachments->push($oAttachment);