support UTF-8 email addresses

This commit is contained in:
missytake 2025-04-05 23:51:15 +02:00
parent 337597e4aa
commit ca1ed91e48
Signed by: missytake
GPG key ID: 04CC6658320518DF
3 changed files with 25 additions and 4 deletions

View file

@ -20,6 +20,7 @@ install_requires =
deltachat-rpc-server
wkdhash
requests
email-validator
[options.packages.find]
where = src

View file

@ -1,7 +1,6 @@
#!/usr/bin/env python3
import re
from deltachat_rpc_client import events, run_bot_cli, EventType, Message
from email_validator import validate_email, EmailNotValidError
from keyserver_bot.wkd import request_from_wkd
from keyserver_bot.koo import request_from_koo
@ -20,8 +19,9 @@ def command(event):
snapshot = event.message_snapshot
email = snapshot.text
regex = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
if not re.match(regex, email):
try:
validate_email(email, check_deliverability=False)
except EmailNotValidError:
snapshot.chat.send_text(HELP_MSG)
return

View file

@ -1,4 +1,5 @@
import os
from email_validator import validate_email, EmailNotValidError
import pytest
from keyserver_bot.hooks import request_key_by_email, delete_data
@ -34,3 +35,22 @@ def test_delete_data(acfactory):
delete_data(msg.get_snapshot())
assert bot.get_contacts() == []
assert len(bot.get_chatlist()) == 2
@pytest.mark.parametrize(
("email", "valid"),
[
("test", False),
("test@example", False),
("@example", False),
("@example.org", False),
("test+asdf@example.org", True),
("test@example.org", True),
("ätsch@ツ.life", True),
]
)
def test_validate_email(email, valid):
try:
validate_email(email, check_deliverability=False)
except EmailNotValidError:
assert not valid