diff --git a/membershipworks/models.py b/membershipworks/models.py index ed307b6..b00192a 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -1,3 +1,5 @@ +import django.core.mail.message +from django.conf import settings from django.db import models from django.db.models import Q, Count, BooleanField @@ -160,6 +162,12 @@ class Member(models.Model): db_table = "members" ordering = ("first_name", "last_name") + @property + def sanitized_mailbox(self): + return django.core.mail.message.sanitize_address( + (self.account_name, self.email), settings.DEFAULT_CHARSET + ) + class MemberFlag(models.Model): member = models.ForeignKey(Member, on_delete=models.PROTECT, db_column="uid") diff --git a/paperwork/api.py b/paperwork/api.py index 5a5e353..4ae81eb 100644 --- a/paperwork/api.py +++ b/paperwork/api.py @@ -38,7 +38,7 @@ class CertificationDefinitionViewSet(viewsets.ModelViewSet): for cert in version.certification_set.all(): if cert.member and cert.member.is_active: lists[definition.mailing_list].add( - f"{cert.member.account_name} <{cert.member.email}>" + cert.member.sanitized_mailbox ) return Response(lists)