Incorrect converting the comma-separated emails into Address class

Created on 9 November 2023, 8 months ago
Updated 7 December 2023, 7 months ago

Problem/Motivation

The SymfonyMailerAdjuster class uses string values to set all possible addresses:

  • setTo
  • setCc
  • setBcc

It means that when we have two comma-separated emails, e.g. several reroute emails, then will be created only one Address class instead of two. That class will contain two addresses which can cause sending errors for some email services.

Steps to reproduce

1. Configure SMTP transport plugin for mailgun (as example)
2. Try to redirect the mail to 2 or more emails
3. Actual: we receive an error Expected response code "250/251/252" but got code "501", with a message "501 Invalid command or cannot parse to address".
4. Expected: the mail must be sent without errors.

This happens cuz Address::convert requires a single string email address or an array of the email addresses.

Proposed resolution

Explode comma-separated emails before using the function from BaseEmailTrait (e.g. BaseEmailTrait::setTo())

πŸ› Bug report
Status

Fixed

Version

2.3

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @HitchShock
  • Assigned to quadrexdev
  • πŸ‡ΊπŸ‡¦Ukraine quadrexdev Lutsk

    I'll work on it

  • πŸ‡ΊπŸ‡¦Ukraine quadrexdev Lutsk

    Should be fixed by using reroute_email_extract_addresses() when setting cc/bcc/to recipients. Please review.

  • Issue was unassigned.
  • Status changed to Needs review 7 months ago
  • πŸ‡ΊπŸ‡¦Ukraine quadrexdev Lutsk

    Updating issue metadata

  • Status changed to Needs work 7 months ago
  • πŸ‡ΊπŸ‡¦Ukraine bohart Lutsk, Ukraine

    Hi @quadrexdev,
    thanks for your contribution!

    1) reroute_email_extract_addresses function is located in the module files as a legacy artifact.
    Let's move it as a method to RerouteEmailHandlerPluginBase (this is the only place where it is used).

    2) We should cover this bug with a test. There is MultipleRecipientsTest for hook_mail_alter implementation.
    This test should be added to reroute_email_symfony_mailer tests.

    Thanks!

  • Status changed to Needs review 7 months ago
  • πŸ‡ΊπŸ‡¦Ukraine quadrexdev Lutsk

    Thanks for your help @bohart!

    I guess now it's ready for the review.

    A summary of what was done:

    1. The reroute_email_extract_addresses function is moved as the extractEmailAddresses method in the new trait - RerouteEmailHelpers.
    2. All to/cc/bcc-related functions use the extractEmailAddresses method to process addresses.
    3. New test - SymfonyMailerMultipleRecipientsTest.
    4. Associative array keys are used for datasets in SymfonyMailerTestEmailFormTest (so it's easier to find problematic places in case the test fails).
    5. New test - InvalidAddressesTest.
    6. Updated tests that were failing because of spaces between e-mail addresses in the string. F.e - link.
    7. Added clearing of mail collector state due to the following error:

    1) Drupal\Tests\reroute_email_symfony_mailer\Functional\SymfonyMailerMultipleRecipientsTest::testMultipleRecipients
    All emails have been checked.
    Failed asserting that actual size 1 matches expected size 0.

    Explained here - link.

    I do believe it should be moved to the issues queue of Symfony mailer to add support for multiple e-mails in the collector state.

  • Status changed to Fixed 7 months ago
  • πŸ‡ΊπŸ‡¦Ukraine bohart Lutsk, Ukraine

    @quadrexdev, thanks for your contribution!
    Committed to 2.3.x dev branch. It will be a part of the next 2.3 series releases.

    We will also need to handle a new test InvalidAddressesTest for Symfony Mailer submodule,
    but it will be a part of πŸ“Œ SymfonyMailerTestEmailFormTest skipped 6 tests to run Active .

    Thanks!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024