Commit 3873a93d authored by smk-ka's avatar smk-ka

#749506 by smk-ka: Fixed 'invalid address' error caused by MIME encoded e-mail...

#749506 by smk-ka: Fixed 'invalid address' error caused by MIME encoded e-mail addresses. Updated tests.
parent d7c9fbe7
......@@ -2,6 +2,8 @@
PHPMailer 6.x-3.x, xxxx-xx-xx
-----------------------------
#749506 by smk-ka: Fixed 'invalid address' error caused by MIME encoded e-mail
addresses. Updated tests.
by smk-ka: Improved installation and status report page error message in case
the PHPMailer library is missing.
by smk-ka: Improved integration with Mime Mail.
......
......@@ -132,7 +132,8 @@ function phpmailer_parse_address($string) {
$email = preg_replace('/\x01/e', '_phpmailer_stack()', trim($email));
// Check if it's a name-addr or a plain address (3.4).
if (preg_match($adr_rx, $email, $matches)) {
$parsed[] = array('mail' => $matches['address'], 'name' => $matches['name']);
// PHPMailer expects an unencoded display name.
$parsed[] = array('mail' => $matches['address'], 'name' => mime_header_decode(stripslashes($matches['name'])));
}
else {
$parsed[] = array('mail' => trim($email, '<>'), 'name' => '');
......
......@@ -22,39 +22,66 @@ class PHPMailerUnitTestCase extends DrupalUnitTestCase {
* Test e-mail address extraction using phpmailer_parse_address().
*/
function testAddressParser() {
// Set up various address formats as per RFC 5322.
// Set up various test addresses according to RFC 5322.
$addresses = array(
// addr-spec.
'user-1@domain.tld' => array(
array(
'mail' => 'user-1@domain.tld',
'name' => ''
),
// Invalid, but supported angle-addr without preceding display-name.
// Invalid but supported angle-addr without preceding display-name.
'<user-2@domain.tld>' => array(
'mail' => 'user-2@domain.tld',
'name' => ''
),
// name-addr using atom in display-name.
// Unquoted atom name-addr.
'John Doe <user-3@domain.tld>' => array(
'mail' => 'user-3@domain.tld',
'name' => 'John Doe'
),
// name-addr using quoted-string with comma in display-name.
'"John \"The Dude\" Doe (Foo, Bar)" <user-4@domain.tld>' => array(
// Quoted atom name-addr.
'"John Doe" <user-4@domain.tld>' => array(
'mail' => 'user-4@domain.tld',
'name' => 'John Doe'
),
// name-addr with a quoted-string in display-name.
array(
'mail' => 'user-5@domain.tld',
'name' => 'John "The Dude" Doe'
),
// name-addr with a quoted-string and comma in display-name.
array(
'mail' => 'user-6@domain.tld',
'name' => 'John "The Dude" Doe (Foo, Bar)'
),
// name-addr containing non-ASCII chars in display-name.
array(
'mail' => 'user-7@domain.tld',
'name' => 'Jöhn "The Düde" Döe'
),
);
$all = array();
// Validate each address format is correctly parsed.
foreach ($addresses as $string => $expected_result) {
$this->assertEqual(phpmailer_parse_address($string), array($expected_result), t('E-mail address @email could be extracted.', array('@email' => $expected_result['mail'])), 'PHPMailer');
foreach ($addresses as $test => $address) {
if (is_numeric($test)) {
if ($address['name'] != '') {
// Create a valid encoded email address.
$test = '"' . addslashes(mime_header_encode($address['name'])) . '" <' . $address['mail'] . '>';
}
else {
$test = $address['mail'];
}
}
$result = phpmailer_parse_address($test);
$this->assertEqual($result[0], $address, t('Successfully extracted %email, %name from %address.', array('%email' => $result[0]['mail'], '%name' => $result[0]['name'] ? $result[0]['name'] : '(blank)', '%address' => $test)), 'PHPMailer');
$all[] = $test;
}
// One final test with all addresses concatenated.
$string = implode(', ', array_keys($addresses));
$result = phpmailer_parse_address(implode(', ', $all));
$expected_result = array_values($addresses);
$this->assertEqual(phpmailer_parse_address($string), $expected_result, t('Concatenated e-mail addresses could be extracted.'), 'PHPMailer');
$this->assertEqual($result, $expected_result, t('All concatenated e-mail addresses could be extracted.'), 'PHPMailer');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment