Add support for complex address strings in back-compatibility mode

Created on 29 March 2023, over 1 year ago
Updated 2 September 2024, 3 months ago

Problem/Motivation

In Legacy Mode using a comma in a display name will cause an error.
Error sending email: Email ""Lastname" does not comply with addr-spec of RFC 2822.

Steps to reproduce

Try sending a mail to a recipient with a display name containing a comma.

Drupal::service('plugin.manager.mail')->mail('webform', 'key', '"Lastname, Firstname" <firstname.lastname@example.com>', 'en');

Proposed resolution

MailHelper splits address parts using explode. This should be improved by matching comma seperated parts taking quoted strings into account.

✨ Feature request
Status

Active

Version

1.2

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany hosterholz

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

Comments & Activities

  • Issue created by @hosterholz
  • Status changed to Needs review over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom adamps

    Yes you are right. It is a known and documented restriction on MailerHelperInterface::parseAddress(), so I would prefer to call it a feature requestπŸ˜ƒ.

    Since #3254085: Sending mails to multiple email addresses does not work via BC β†’ , nearly a year ago, I've changed my views - back-compatibility mode is likely to stay around for many years, even "forever". So yes I am happy to fix this. We should use library code rather than re-inventing. I wonder about Mail_RFC822 in package pear/mail, see docs.

    Thanks very much for the test. Setting to "Needs Review" so we can see that it failsπŸ˜ƒ.

  • πŸ‡©πŸ‡ͺGermany lmoeni

    In the meantime this patch solves the issue.

  • Status changed to Active over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom adamps

    Also see swiftmailer_parse_mailboxes(), which is even more complex and yet still probably not fully correct or complete with the evolving standards.

    Thanks the patch is useful for anyone who wants a solution in the meantime. I don't feel it's right to commit it, as it seems better to use library code.

  • πŸ‡¬πŸ‡§United Kingdom adamps

    In my testing of splitting addresses, str_getcsv() is an improvement on explode() however it's not 100%:
    - it works if the display name contains a comma
    - if fails if the display name contains a less-than (because it removes the quotes within each address)

  • πŸ‡¦πŸ‡ΉAustria DrColossos

    We had the same issue and the patch fixed the problem. As noted in #5, the str_getcsv() has an issue with "," in an address.

Production build 0.71.5 2024