From 4afe0b8830fe60e77a7268ab5e9cadff23de87c2 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Thu, 25 May 2017 14:10:42 +0000 Subject: [PATCH] Added stripping of leading and trailing whitespace from submission data (including email addresses) gleaned from submitted xml. Changed email line parsing to use email.utils.parseaddr() instead of a regex which only would handle unwuoted names (and possibly not utf-8 names) correctly. - Legacy-Id: 13423 --- ietf/submit/forms.py | 10 +++++----- ietf/submit/models.py | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ietf/submit/forms.py b/ietf/submit/forms.py index 0491f0442..790936907 100644 --- a/ietf/submit/forms.py +++ b/ietf/submit/forms.py @@ -181,13 +181,13 @@ class SubmissionUploadForm(forms.Form): author_info = self.xmlroot.findall('front/author') for author in author_info: author_dict = dict( - company = author.findtext('organization'), - last_name = author.attrib.get('surname'), - full_name = author.attrib.get('fullname'), - email = author.findtext('address/email'), + company = author.findtext('organization').strip(), + last_name = author.attrib.get('surname').strip(), + full_name = author.attrib.get('fullname').strip(), + email = author.findtext('address/email').strip(), ) self.author_list.append(author_dict) - line = "%(full_name)s <%(email)s>" % author_dict + line = email.utils.formataddr((author_dict['full_name'], author_dict['email'])) self.authors.append(line) except forms.ValidationError: raise diff --git a/ietf/submit/models.py b/ietf/submit/models.py index 6e710cc6b..8788400f4 100644 --- a/ietf/submit/models.py +++ b/ietf/submit/models.py @@ -1,5 +1,5 @@ -import re import datetime +import email from django.db import models import jsonfield @@ -15,12 +15,12 @@ from ietf.utils.accesstoken import generate_random_key, generate_access_token def parse_email_line(line): - """Split line on the form 'Some Name '""" - m = re.match("([^<]+) <([^>]+)>$", line) - if m: - return dict(name=m.group(1), email=m.group(2)) - else: - return dict(name=line, email="") + """ + Split email address into name and email like + email.utils.parseaddr() but return a dictionary + """ + name, addr = email.utils.parseaddr(line) if '@' in line else (line, '') + return dict(name=name, email=addr) class Submission(models.Model): state = models.ForeignKey(DraftSubmissionStateName)