-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix idn emails not working in shares #30600
Conversation
Fix #30595 Signed-off-by: Carl Schwan <carl@carlschwan.eu>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use OCP\Mail\Mailer::validateMailAddress
that already has the IDN check.
server/lib/private/Mail/Mailer.php
Lines 216 to 249 in 796764a
/** | |
* Checks if an e-mail address is valid | |
* | |
* @param string $email Email address to be validated | |
* @return bool True if the mail address is valid, false otherwise | |
*/ | |
public function validateMailAddress(string $email): bool { | |
if ($email === '') { | |
// Shortcut: empty addresses are never valid | |
return false; | |
} | |
$validator = new EmailValidator(); | |
$validation = new RFCValidation(); | |
return $validator->isValid($this->convertEmail($email), $validation); | |
} | |
/** | |
* SwiftMailer does currently not work with IDN domains, this function therefore converts the domains | |
* | |
* FIXME: Remove this once SwiftMailer supports IDN | |
* | |
* @param string $email | |
* @return string Converted mail address if `idn_to_ascii` exists | |
*/ | |
protected function convertEmail(string $email): string { | |
if (!function_exists('idn_to_ascii') || !defined('INTL_IDNA_VARIANT_UTS46') || strpos($email, '@') === false) { | |
return $email; | |
} | |
[$name, $domain] = explode('@', $email, 2); | |
$domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46); | |
return $name.'@'.$domain; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
if possible for this code path would be good to add unit tests with an IDN address |
a666594
to
50da844
Compare
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
50da844
to
7ecb65f
Compare
7711339
to
acf3bec
Compare
acf3bec
to
ed80527
Compare
I'm looking into the php unit failures, strange that is works locally for me :/ |
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
ed80527
to
fffc19f
Compare
I found why the tests seemed to work locally and fixed them :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
/backport to stable23 |
/backport to stable22 |
/backport to stable21 |
Fix #30595
Signed-off-by: Carl Schwan carl@carlschwan.eu