ensure emails are formatted before sending

we allow some invalid to addresses - for example, phone numbers with
spaces or brackets - in the database. This is so that users can match
up their data in a format that they expect (since they passed it in).
When we send SMS, we strip this formatting just before sending - but we
weren't with email. This commit changes that and adds some tests.

It also adds formatting for reply_to addresses. We should never expect
invalid reply_to email addresses in our data, but just in case, lets
validate them here.

Also, bump requirements.txt to capture some more email validation
This commit is contained in:
Leo Hemsted
2017-10-16 17:29:45 +01:00
parent 45ecab00e3
commit 5ad6bc7621
4 changed files with 67 additions and 5 deletions

View File

@@ -109,7 +109,7 @@ def create_notification(
template,
job=None,
job_row_number=None,
to_field='+447700900855',
to_field=None,
status='created',
reference=None,
created_at=None,
@@ -131,6 +131,9 @@ def create_notification(
if created_at is None:
created_at = datetime.utcnow()
if to_field is None:
to_field = '+447700900855' if template.template_type == SMS_TYPE else 'test@example.com'
if status != 'created':
sent_at = sent_at or datetime.utcnow()
updated_at = updated_at or datetime.utcnow()