Raise error for invalidly-formatted email addresses.

A message's `from_email` and each address in its `to`, `cc`, and `bcc` lists must contain exactly one email address. Previous code would silently ignore additional addresses, leading to unusual behavior. Now, raises new `AnymailInvalidAddress` exception.

Example: `from_email='Widgets, Inc. <widgets@example.com>'` is invalid: it needs double-quotes around the "Widgets, Inc." display-name portion. In earlier versions, this probably would have sent the message from something like "From: Widgets <@localhost>". Now, it will raise an exception.

**Potentially-breaking change:** If your code is using an unquoted display-name containing a comma in an email address, it will now raise an error. In earlier versions, this may have appeared to succeed, but was almost certainly not doing what you intended.

Fixes #44.
This commit is contained in:
medmunds
2016-12-15 13:57:49 -08:00
parent 4ca39a976f
commit d0596d100b
4 changed files with 116 additions and 20 deletions

View File

@@ -101,6 +101,10 @@ class AnymailRecipientsRefused(AnymailError):
super(AnymailRecipientsRefused, self).__init__(message, *args, **kwargs)
class AnymailInvalidAddress(AnymailError, ValueError):
"""Exception when using an invalidly-formatted email address"""
class AnymailUnsupportedFeature(AnymailError, ValueError):
"""Exception for Anymail features that the ESP doesn't support.