fix: imap idle writter with nil connection #777
Merged
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.
There's an intermittent panic that occurs because an IDLE writer was registered with a
niltextproto.Conn; when SMTP appends a message,Folder.Appendnotifies IDLE writers andWriteNumMessagesdereferencesw.tpc, causing a nil-pointer panic. It only fails sometimes because the notification depends on timing, if no IDLE session is active or the writer has already been removed, no call happens. The fix is to construct idleWriter with the active connection (newIdleWriter(tpc *textproto.Conn)) so updates write through the IMAP connection.This pull request refactors the handling of the
idleWriterin the IMAP IDLE implementation to improve code clarity and correctness. The main updates include introducing a constructor foridleWriter, updating its instantiation, and fixing the format of the EXPUNGE response.Refactoring and correctness improvements:
newIdleWriterconstructor function foridleWriterto encapsulate initialization logic and replaced the previous direct instantiation with this constructor in thehandleIdlemethod. [1] [2]WriteExpungeto include the required*prefix, ensuring compliance with the IMAP protocol.