Normalize IDN email addresses (#5350)

This commit is contained in:
luelista
2025-08-07 09:44:15 +02:00
committed by GitHub
parent 3212dd9b40
commit 4e89772c2d
2 changed files with 22 additions and 9 deletions

View File

@@ -93,6 +93,15 @@ def split_name_on_last_space(name, part):
return name_parts[part] if len(name_parts) > part else ""
def normalize_email(email):
if email:
local, host = email.split("@")
host = host.encode("idna").decode()
return f"{local}@{host}"
else:
return None
ORDER_POSITION = 'position'
ORDER = 'order'
EVENT = 'event'
@@ -173,8 +182,10 @@ def get_data_fields(event, for_model=None):
_("Attendee email"),
Question.TYPE_STRING,
None,
lambda position: position.attendee_email
or (position.addon_to.attendee_email if position.addon_to else None),
lambda position: normalize_email(
position.attendee_email
or (position.addon_to.attendee_email if position.addon_to else None)
),
),
DataFieldInfo(
ORDER_POSITION,
@@ -182,9 +193,11 @@ def get_data_fields(event, for_model=None):
_("Attendee or order email"),
Question.TYPE_STRING,
None,
lambda position: position.attendee_email
or (position.addon_to.attendee_email if position.addon_to else None)
or position.order.email,
lambda position: normalize_email(
position.attendee_email
or (position.addon_to.attendee_email if position.addon_to else None)
or position.order.email
),
),
DataFieldInfo(
ORDER_POSITION,
@@ -301,7 +314,7 @@ def get_data_fields(event, for_model=None):
_("Order email"),
Question.TYPE_STRING,
None,
lambda order: order.email,
lambda order: normalize_email(order.email),
),
DataFieldInfo(
ORDER,

View File

@@ -61,7 +61,7 @@ def event():
option2 = question2.options.create(identifier="F2", answer="vegan")
o1 = Order.objects.create(
code='1AAA', event=event, email='anonymous@example.org',
code='1AAA', event=event, email='anonymous@🌈.example.org',
status=Order.STATUS_PENDING, locale='en',
datetime=now(), expires=now() + timedelta(days=10),
total=46,
@@ -100,7 +100,7 @@ def expected_order_sync_result():
{
'_id': 0,
'ordernumber': 'DUMMY-1AAA',
'orderemail': 'anonymous@example.org',
'orderemail': 'anonymous@xn--og8h.example.org',
'status': 'pending',
'total': '46.00',
'payment_date': None,
@@ -158,7 +158,7 @@ def expected_sync_result_with_associations():
{
'_id': 0,
'ordernumber': 'DUMMY-1AAA',
'orderemail': 'anonymous@example.org',
'orderemail': 'anonymous@xn--og8h.example.org',
'firstname': '',
'lastname': '',
'status': 'pending',