Fix: TypeError when Message::make() is called after an implicit reconnect#621
Open
k00ni wants to merge 6 commits into
Open
Fix: TypeError when Message::make() is called after an implicit reconnect#621k00ni wants to merge 6 commits into
k00ni wants to merge 6 commits into
Conversation
Refactor setFolderPath method to accept nullable string and handle default values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disclaimer: This fix is similar to #615 from @braito4 but with slightly different changes.
We had the following error in our logs recently:
🤖 Because I am not familiar with the IMAP specification I asked Claude Code to analyze the problem and provide me a solution. It came up with a minimal set of changes. I checked them manually.
Problem
When the IMAP connection drops during a message fetch and the library reconnects internally,
Message::make()throws a fatalTypeError:Client::connect()always callsdisconnect()first.disconnect()resetsactive_foldertonull. WhengetConnection()triggers an implicit reconnect mid-fetch (e.g. insideQuery::fetch()),active_folderisnullby the timeMessage::make()runs.make()then passesnulltosetFolderPath(), which PHP 8 rejects because$folder_pathis declared asstring.Fix
Two changes, each addressing a different layer of the problem:
1.
Client::checkConnection()— root cause fixSave
active_folderbefore reconnecting and reopen it afterwards, so the selected mailbox is never lost across a reconnect.2.
Message.php— type safety + reliable fallbacksetFolderPath()accepts?stringinstead of an untyped parameter, which eliminates theTypeError.make(),setClient()is moved beforesetFolderPath()so that the client-based fallback insidesetFolderPath()can actually reach$this->client->getFolderPath(). Without this reordering the fallback is dead code and every unresolvable folder silently defaults to'INBOX'.Tests
Two tests were provided to show the problem and demonstrate that the fix works.