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

Fix idn emails not working in shares #30600

Merged
merged 3 commits into from
Jan 13, 2022
Merged

Conversation

CarlSchwan
Copy link
Member

Fix #30595

Signed-off-by: Carl Schwan carl@carlschwan.eu

Fix #30595

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
@CarlSchwan CarlSchwan added the 3. to review Waiting for reviews label Jan 11, 2022
@CarlSchwan CarlSchwan added this to the Nextcloud 24 milestone Jan 11, 2022
@CarlSchwan CarlSchwan requested review from PVince81 and a team January 11, 2022 14:45
@CarlSchwan CarlSchwan self-assigned this Jan 11, 2022
@CarlSchwan CarlSchwan requested review from ArtificialOwl, skjnldsv and come-nc and removed request for a team January 11, 2022 14:45
Copy link
Member

@tcitworld tcitworld left a 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.

/**
* 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;
}

Copy link
Member

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@PVince81
Copy link
Member

if possible for this code path would be good to add unit tests with an IDN address

@CarlSchwan CarlSchwan force-pushed the fix/30595/idn-email-share branch from a666594 to 50da844 Compare January 11, 2022 19:56
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
@CarlSchwan CarlSchwan force-pushed the fix/30595/idn-email-share branch from 50da844 to 7ecb65f Compare January 11, 2022 19:59
@CarlSchwan CarlSchwan requested a review from tcitworld January 12, 2022 13:16
@CarlSchwan CarlSchwan force-pushed the fix/30595/idn-email-share branch from 7711339 to acf3bec Compare January 12, 2022 14:17
@CarlSchwan CarlSchwan force-pushed the fix/30595/idn-email-share branch from acf3bec to ed80527 Compare January 12, 2022 15:36
@CarlSchwan
Copy link
Member Author

I'm looking into the php unit failures, strange that is works locally for me :/

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
@CarlSchwan CarlSchwan force-pushed the fix/30595/idn-email-share branch from ed80527 to fffc19f Compare January 12, 2022 19:33
@CarlSchwan
Copy link
Member Author

I found why the tests seemed to work locally and fixed them :)

Copy link
Member

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@CarlSchwan CarlSchwan merged commit b104886 into master Jan 13, 2022
@CarlSchwan CarlSchwan deleted the fix/30595/idn-email-share branch January 13, 2022 08:24
@CarlSchwan
Copy link
Member Author

/backport to stable23

@CarlSchwan
Copy link
Member Author

/backport to stable22

@CarlSchwan
Copy link
Member Author

/backport to stable21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No email suggestion when sharing with IDN email address
3 participants