marrow / mailer

A light-weight, modular, message representation and mail delivery framework for Python.
MIT License
279 stars 62 forks source link

Comma in Email Address Name #78

Open nashley opened 6 years ago

nashley commented 6 years ago

Commas in the name in an email address cause the address parser to parse the address as multiple addresses and therefore fail.

Take the following address for example:
"Bond, James" <james.bond@spies.com> It should have Bond, James as the name and james.bond@spies.com as the email, but instead it tries to parse Bond as an email address and fails.

Here's a traceback:

Traceback (most recent call last):
  File "__main__.py", line 136, in <module>
    main()
  File "__main__.py", line 126, in main
    download_calendars()
  File "__main__.py", line 111, in download_calendars
    sender='bondvillian@evil.com'
  File "/usr/local/lib/python3.6/site-packages/marrow/mailer/message.py", line 79, in __init__
    self.author = author
  File "/usr/local/lib/python3.6/site-packages/marrow/mailer/message.py", line 95, in __setattr__
    object.__setattr__(self, name, value)
  File "/usr/local/lib/python3.6/site-packages/marrow/mailer/address.py", line 222, in __set__
    value = self.cls(value)
  File "/usr/local/lib/python3.6/site-packages/marrow/mailer/address.py", line 145, in __init__
    self.extend(addresses)
  File "/usr/local/lib/python3.6/site-packages/marrow/mailer/address.py", line 182, in extend
    values = [Address(val) if not isinstance(val, Address) else val for val in sequence]
  File "/usr/local/lib/python3.6/site-packages/marrow/mailer/address.py", line 182, in <listcomp>
    values = [Address(val) if not isinstance(val, Address) else val for val in sequence]
  File "/usr/local/lib/python3.6/site-packages/marrow/mailer/address.py", line 58, in __init__
    raise ValueError('"{0}" is not a valid e-mail address: {1}'.format(email, err))
ValueError: "Bond" is not a valid e-mail address: An email address must contain a single @

This behavior is only expected if the name is not encapsulated with quotes.