Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/mail/15 deal better with spaces in from email address #12346

Merged
merged 2 commits into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -508,4 +508,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);
}

}