From f43c051a83ab6a7cc9d9c456f3231fe8fe696d20 Mon Sep 17 00:00:00 2001 From: caminotravelcenter Date: Mon, 16 Mar 2026 13:31:30 +0100 Subject: [PATCH] fix: preserve and fallback message folder path after reconnect --- src/Client.php | 8 ++++++++ src/Message.php | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 5eb26ff2..5281184c 100755 --- a/src/Client.php +++ b/src/Client.php @@ -400,13 +400,21 @@ public function isConnected(): bool { * @throws ResponseException */ public function checkConnection(): bool { + $active_folder = $this->active_folder; try { if (!$this->isConnected()) { $this->connect(); + if ($active_folder !== null) { + $this->openFolder($active_folder, true); + } return true; } } catch (\Throwable) { $this->connect(); + if ($active_folder !== null) { + $this->openFolder($active_folder, true); + } + return true; } return false; } diff --git a/src/Message.php b/src/Message.php index 9d15a7b8..df939d87 100755 --- a/src/Message.php +++ b/src/Message.php @@ -232,7 +232,7 @@ public function __construct(int $uid, ?int $msglist, Client $client, ?int $fetch $this->events["message"] = $client->getDefaultEvents("message"); $this->events["flag"] = $client->getDefaultEvents("flag"); - $this->folder_path = $client->getFolderPath(); + $this->setFolderPath($client->getFolderPath()); $this->setSequence($sequence); $this->setFetchOption($fetch_options); @@ -1470,6 +1470,15 @@ public function getFolderPath(): string { * @return Message */ public function setFolderPath($folder_path): Message { + if (!is_string($folder_path) || $folder_path === '') { + $folder_path = $this->client?->getFolderPath(); + } + if (!is_string($folder_path) || $folder_path === '') { + $folder_path = (string)$this->config->get('options.common_folders.inbox', 'INBOX'); + } + if ($folder_path === '') { + $folder_path = 'INBOX'; + } $this->folder_path = $folder_path; return $this;