Skip to content

SMTP module: Fix response code and Cyrillic character handling issues #277

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

butschster
Copy link
Member

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. [SMTP] Two response codes returned for end of data command #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

- Fix double "250" response issue when handling end of data command
- Add proper state management for SMTP sessions
- Improve handling of multi-byte characters (e.g. Cyrillic) in message body
- Fix protocol state issues that caused "Expected 354 but got 250" errors
- Reset message state after successful data transmission
@butschster butschster self-assigned this Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request module [Smtp]
Projects
Status: Done
1 participant