mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
Do not throw errors when invalid setTo email is provided
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
3b084e5fbc
commit
fd036f774f
2 changed files with 25 additions and 10 deletions
|
|
@ -78,14 +78,18 @@ class Message implements IMessage {
|
|||
$convertedAddresses = [];
|
||||
|
||||
foreach ($addresses as $email => $readableName) {
|
||||
if (!is_numeric($email)) {
|
||||
[$name, $domain] = explode('@', $email, 2);
|
||||
$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
|
||||
$convertedAddresses[$name.'@'.$domain] = $readableName;
|
||||
$parsableEmail = is_numeric($email) ? $readableName : $email;
|
||||
if (strpos($parsableEmail, '@') === false) {
|
||||
$convertedAddresses[$parsableEmail] = $readableName;
|
||||
continue;
|
||||
}
|
||||
|
||||
[$name, $domain] = explode('@', $parsableEmail, 2);
|
||||
$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
|
||||
if (is_numeric($email)) {
|
||||
$convertedAddresses[] = $name . '@' . $domain;
|
||||
} else {
|
||||
[$name, $domain] = explode('@', $readableName, 2);
|
||||
$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
|
||||
$convertedAddresses[$email] = $name.'@'.$domain;
|
||||
$convertedAddresses[$name . '@' . $domain] = $readableName;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,12 +102,23 @@ class MessageTest extends TestCase {
|
|||
$this->assertSame('lukas@owncloud.com', $this->message->getReplyTo());
|
||||
}
|
||||
|
||||
public function testSetTo() {
|
||||
/** @dataProvider dataSetTo */
|
||||
public function testSetTo(array $to, array $expected) {
|
||||
$this->swiftMessage
|
||||
->expects($this->once())
|
||||
->method('setTo')
|
||||
->with(['lukas@owncloud.com']);
|
||||
$this->message->setTo(['lukas@owncloud.com']);
|
||||
->with($expected);
|
||||
$this->message->setTo($to);
|
||||
}
|
||||
|
||||
public function dataSetTo(): array {
|
||||
return [
|
||||
[['robot@example.com'], ['robot@example.com']],
|
||||
[['robot'], ['robot' => 'robot']],
|
||||
[['robot' => 'robot display name'], ['robot' => 'robot display name']],
|
||||
[['example@🤖.com'], ['example@xn--yp9h.com']],
|
||||
[['example@🤖.com' => 'A robot'], ['example@xn--yp9h.com' => 'A robot']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue