make SMTP socket I/O more robust against overlong or multi-line replies and timeouts#37
Open
splitbrain wants to merge 1 commit into
Open
make SMTP socket I/O more robust against overlong or multi-line replies and timeouts#37splitbrain wants to merge 1 commit into
splitbrain wants to merge 1 commit into
Conversation
getCode() now reads each reply line with a length-independent readLine() and reassembles a multi-line reply (RFC 5321 §4.2.1) into a single resultStack entry. The previous reader used fgets($smtp, 515): it truncated any line over 514 bytes and left the tail buffered, and detected end-of-reply from a byte at a fixed offset. Both desynced the stream, so an error could be reported against the wrong command even when the message was actually delivered. Recording one reassembled reply per command also realigns resultStack with commandStack, so CodeException reports the whole reply rather than just its final line. Also add a configurable socket timeout (Mailer/SMTP::setTimeout) applied to both connect and reads, report read timeouts distinctly, and fail loudly on a write error in pushStack. Add unit tests for the reply parser (single/multi-line, long >buffer lines, back-to-back replies, error cases) driven by an in-memory stream.
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.
This is an attempt to (hopefully) fix issues reported for the DokuWiki smtp plugin based on this library:
Technically its two separate things (timeout and proper line reading) but their code was interwoven so I committed it as one thing.