Add support for complex address strings in back-compatibility mode

Created on 29 March 2023, about 1 year ago
Updated 5 July 2023, 12 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 about 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 about 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)

Production build 0.69.0 2024