Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The current version does not correctly split up "from" headers that already contain an e-mail address, e.g. some name <address@example.com>
The following header will be generated: "some name <address@example.com>" <address@example.com>
, which is ugly, confusing and results in a higher likelihood of spam classification.
The attached patch correctly splits up such from headers and also validates the address, which is not done in the current version. It does this through a new method. It also cleans up a lot of the code that was previously hacky:
// e.g.
$reply = preg_replace('/>.*/', '', preg_replace('/.*</', '', $from));
// or
$toparts = explode(' <', $torecipient);
$toname = $toparts[0];
$toaddr = rtrim($toparts[1], '>');
// or
$replyToParts = explode('<', $value);
$replyToName = trim($replyToParts[0]);
$replyToName = trim($replyToName, '"');
$replyToAddr = rtrim($replyToParts[1], '>');
Comment | File | Size | Author |
---|---|---|---|
#12 | Screen shot 2016-01-30 at 10.36.04 PM.png | 35.97 KB | Anonymous (not verified) |
#10 | smtp-n2596413-10.patch | 6.07 KB | DamienMcKenna |
|
Comments
Comment #2
ivanstegic CreditAttribution: ivanstegic at TEN7 commentedI discovered this issue when a client's site stopped sending out emails because of a badly formed from string: there was no space between the name and the email address. This meant that the way angle brackets are handled in this module *requiring* a space broke things. The preg_match here is a better way of doing things, and I went ahead and fixed the side note you mentioned @sammuell at the bottom of #1. Here's a patch that cleans the code up, fixes my issue and probably related issues.
I added a new protected function to the class and perhaps this makes it more readable and consistent:
Comment #3
ivanstegic CreditAttribution: ivanstegic at TEN7 commentedRe-rolled the last patch with some improvements, most notably such that the method returns immediately if the supplied string is already a valid email address. Reduced number of variables being used too.
Comment #7
ivanstegic CreditAttribution: ivanstegic at TEN7 commentedOK, one more time!
Comment #8
ivanstegic CreditAttribution: ivanstegic at TEN7 commentedComment #9
ivanstegic CreditAttribution: ivanstegic at TEN7 commentedI think this needs to be submitted again to be retested?
Comment #10
DamienMcKennaRerolled.
Comment #11
DamienMcKennaOnce there are some more tests committed to the module it'll be easier to test to make sure this works as intended.
Comment #12
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer and commentedWorked great for me on this one. Terminal screenshot included.
Comment #13
ivanstegic CreditAttribution: ivanstegic at TEN7 commentedThe code changes here are almost identical to the issue in Drupal 8 which has already been committed #2627432: Clean up name and email address handling
Comment #14
wundo CreditAttribution: wundo at Chuva Inc. commentedComment #15
wundo CreditAttribution: wundo at Chuva Inc. commentedComment #16
wundo CreditAttribution: wundo at Chuva Inc. commentedComment #18
wundo CreditAttribution: wundo at Chuva Inc. commented