Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for failed call to Laminas\Mail\Storage\Imap->close() on invalid server response #266

Closed
wants to merge 1 commit into from
Closed

Conversation

PEyacher
Copy link
Contributor

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

Sometimes IMAP mail servers do not respond with valid tagged lines when issuing a logout as done in Laminas\Mail\Protocol\Imap::logout(). This may lead to a failure in nextTaggedLine() as shown below, as the response does not contain any empty spaces and the explode does not work as expected:

Undefined array key 1 in vendor/laminas/laminas-mail/src/Protocol/Imap.php on line 173

#0 vendor/laminas/laminas-mail/src/Protocol/Imap.php(289): Laminas\Mail\Protocol\Imap->nextTaggedLine()
#1 vendor/laminas/laminas-mail/src/Protocol/Imap.php(312): Laminas\Mail\Protocol\Imap->readLine()
#2 vendor/laminas/laminas-mail/src/Protocol/Imap.php(377): Laminas\Mail\Protocol\Imap->readResponse()
#3 vendor/laminas/laminas-mail/src/Protocol/Imap.php(445): Laminas\Mail\Protocol\Imap->requestAndResponse()
#4 vendor/laminas/laminas-mail/src/Storage/Imap.php(257): Laminas\Mail\Protocol\Imap->logout()

This results in the socket not being closed inside logout(), which in turn, leads to another exception when Protocol\Imap::__destruct() is called upon destruction, as it again attempts to issue a logout with the server because the socket variable is still set. The bugfix provided includes a check inside nextTaggedLine() to verify that the read line can be used as expected, otherwise a RuntimeException is thrown. Furthermore, logout() has been altered to always close the socket even if an uncaught exception occurs.

…server response

Signed-off-by: Pascal Eyacher <p.eyacher@teleport.ch>
@Slamdunk
Copy link
Contributor

Hi, can you post a real world example of an invalid tagged line please?

@PEyacher
Copy link
Contributor Author

PEyacher commented Aug 29, 2024

Hi, we've seen empty responses as well just single OKs. I am aware that these responses are an issue with the server, but we have stumbled upon these in the real world.

@arhimede
Copy link
Member

arhimede commented Sep 3, 2024

This library is discontinued.
You should switch to some other libraries in order to handle emails.

@PEyacher
Copy link
Contributor Author

PEyacher commented Sep 3, 2024

@arhimede Thank you for this information. I have opened another pull request here in order to make this information known to people that are not regularly checking the laminas website for these kind of changes.

@froschdesign
Copy link
Member

@Slamdunk
It is your decision to accept or close the pull request.

@PEyacher PEyacher closed this by deleting the head repository Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants