Skip to content

make SMTP socket I/O more robust against overlong or multi-line replies and timeouts#37

Open
splitbrain wants to merge 1 commit into
masterfrom
timeout-read
Open

make SMTP socket I/O more robust against overlong or multi-line replies and timeouts#37
splitbrain wants to merge 1 commit into
masterfrom
timeout-read

Conversation

@splitbrain

Copy link
Copy Markdown
Collaborator

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.

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.
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.

1 participant