Skip to content

Commit bb5096d

Browse files
committed
Added more email validation for draft submission author emails, and blocked some baths that could lead to bad email addresses ('none') being set as document author email addresses.
- Legacy-Id: 13010
1 parent 888aa75 commit bb5096d

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

ietf/submit/utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
from ietf.community.utils import update_name_contains_indexes_with_new_doc
2424
from ietf.submit.mail import announce_to_lists, announce_new_version, announce_to_authors
2525
from ietf.submit.models import Submission, SubmissionEvent, Preapproval, DraftSubmissionStateName
26-
from ietf.utils import unaccent
2726
from ietf.utils import log
27+
from ietf.utils import unaccent
28+
from ietf.utils.mail import is_valid_email
2829

2930

3031
def validate_submission(submission):
@@ -373,20 +374,20 @@ def update_replaces_from_submission(request, submission, draft):
373374

374375
def get_person_from_name_email(name, email):
375376
# try email
376-
if email:
377+
if email and (email.startswith('unknown-email-') or is_valid_email(email)):
377378
persons = Person.objects.filter(email__address=email).distinct()
378379
if len(persons) == 1:
379380
return persons[0]
380381
else:
381382
persons = Person.objects.none()
382383

383-
if not persons:
384+
if not persons.exists():
384385
persons = Person.objects.all()
385386

386387
# try full name
387388
p = persons.filter(alias__name=name).distinct()
388-
if p:
389-
return p[0]
389+
if p.exists():
390+
return p.first()
390391

391392
return None
392393

@@ -406,7 +407,7 @@ def ensure_person_email_info_exists(name, email):
406407
person.save()
407408

408409
# make sure we have an email address
409-
if addr:
410+
if addr and (addr.startswith('unknown-email-') or is_valid_email(addr)):
410411
active = True
411412
addr = addr.lower()
412413
else:

ietf/utils/mail.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
from django.conf import settings
2020
from django.contrib import messages
21-
from django.core.exceptions import ImproperlyConfigured
21+
from django.core.exceptions import ImproperlyConfigured, ValidationError
22+
from django.core.validators import validate_email
2223
from django.template.loader import render_to_string
2324
from django.template import Context,RequestContext
2425

@@ -438,3 +439,9 @@ def send_error_to_secretariat(msg):
438439
(extype,value) = sys.exc_info()[:2]
439440
log("SMTP Exception: %s : %s" % (extype,value))
440441

442+
def is_valid_email(address):
443+
try:
444+
validate_email(address)
445+
return True
446+
except ValidationError:
447+
return False

0 commit comments

Comments
 (0)