server icon indicating copy to clipboard operation
server copied to clipboard

SMTP module: Fix response code and Cyrillic character handling issues

Open butschster opened this issue 9 months ago • 0 comments

Two issues were identified with the SMTP server:

  1. When terminating the DATA command with the end-of-data marker (a single period), the server incorrectly sent two "250" response codes in sequence, causing errors with some clients during concurrent email sending. #274

  2. When sending emails with Cyrillic content, especially with larger volumes of text, clients would receive an error: Expected response code "354" but got code "250". This was due to improper handling of multi-byte characters and SMTP state management.

Changes Made

1. In Service.php:

  • Fixed the response handling for data termination to only send one "250" response
  • Properly reset message state when a new DATA command is received
  • Reset the waitBody flag when a message is successfully processed
  • Improved handling of the SMTP protocol state machine

2. In Message.php:

  • Updated string handling functions to use multi-byte aware methods (mb_substr, mb_strlen)
  • Improved the end-of-stream detection to handle multi-byte characters properly
  • Enhanced the getBody method to safely handle message termination

Testing

  • Tested concurrent email sending to verify only one response code is sent
  • Verified that emails with varying amounts of Cyrillic text can be sent without error
  • Confirmed protocol compliance by checking response codes at each step of the SMTP transaction

butschster avatar Apr 12 '25 21:04 butschster