Support optional Source, parse from header

The Email ``from`` header is either formatted as ``name <address>`` or ``address``.

This commit will use `parseaddr` to extract a ``(name, address)`` tuple, which we will use the ``address`` to check if it's verified.

Also support the case where ``Source`` is omitted (which AWS requires the ``from`` header to be set).
This commit is contained in:
Ben Jolitz 2018-05-04 18:22:47 -07:00
commit d21c387eb6
3 changed files with 79 additions and 5 deletions

View file

@ -75,7 +75,10 @@ class EmailResponse(BaseResponse):
return template.render(message=message)
def send_raw_email(self):
source = self.querystring.get('Source')[0]
source = self.querystring.get('Source')
if source is not None:
source, = source
raw_data = self.querystring.get('RawMessage.Data')[0]
raw_data = base64.b64decode(raw_data)
if six.PY3: