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], '>');
Comments
Comment #2
ivanstegic 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 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 commentedOK, one more time!
Comment #8
ivanstegic commentedComment #9
ivanstegic 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) commentedWorked great for me on this one. Terminal screenshot included.
Comment #13
ivanstegic 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 commentedComment #15
wundo commentedComment #16
wundo commentedComment #18
wundo commented