Skip to content

Commit

Permalink
Merge pull request #12346 from michaelmcandrew/dev/mail/15
Browse files Browse the repository at this point in the history
dev/mail/15 deal better with spaces in from email address
  • Loading branch information
seamuslee001 authored Jul 13, 2018
2 parents 2344e6e + ccbfdc7 commit a2b25ec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
9 changes: 7 additions & 2 deletions CRM/Admin/Form/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ public function postProcess() {
$params['reset_default_for'] = array('filter' => "0, " . $params['filter']);
}

//make sure we should has to have space, CRM-6977
//make sure we only have a single space, CRM-6977 and dev/mail/15
if ($this->_gName == 'from_email_address') {
$params['label'] = str_replace('"<', '" <', $params['label']);
$params['label'] = $this->sanitizeFromEmailAddress($params['label']);
}
}

Expand Down Expand Up @@ -507,4 +507,9 @@ public function postProcess() {
}
}

public function sanitizeFromEmailAddress($email) {
preg_match("/^\"(.*)\" *<([^@>]*@[^@>]*)>$/", $email, $parts);
return "\"{$parts[1]}\" <$parts[2]>";
}

}
2 changes: 1 addition & 1 deletion ang/crmMailing/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// the available "From:" addrs. Records are like the underlying OptionValues -- but add "email"
// and "author".
angular.module('crmMailing').factory('crmFromAddresses', function ($q, crmApi) {
var emailRegex = /^"(.*)" <([^@>]*@[^@>]*)>$/;
var emailRegex = /^"(.*)" *<([^@>]*@[^@>]*)>$/;
var addrs = _.map(CRM.crmMailing.fromAddress, function (addr) {
var match = emailRegex.exec(addr.label);
return angular.extend({}, addr, {
Expand Down
18 changes: 18 additions & 0 deletions tests/phpunit/CRM/Core/OptionGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,22 @@ public function testsOptionGroupDataType($optionGroup, $expectedDataType) {
}
}


public function emailAddressTests() {
$tests[] = array('"Name"<email@example.com>', '"Name" <email@example.com>');
$tests[] = array('"Name" <email@example.com>', '"Name" <email@example.com>');
$tests[] = array('"Name" <email@example.com>', '"Name" <email@example.com>');
return $tests;
}


/**
* @dataProvider emailAddressTests
*/
public function testSanitizeFromEmailAddress($dirty, $clean) {
$form = new CRM_Admin_Form_Options();
$actual = $form->sanitizeFromEmailAddress($dirty);
$this->assertEquals($actual, $clean);
}

}

0 comments on commit a2b25ec

Please sign in to comment.