This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: email address parser desired
Type: enhancement Stage: resolved
Components: email Versions: Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: barry, lpirl, r.david.murray
Priority: normal Keywords:

Created on 2013-07-25 17:51 by lpirl, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg193707 - (view) Author: Lukas Pirl (lpirl) Date: 2013-07-25 17:51
I am missing a non-hidden equivalent of email._parseaddr.AddressList.
AddressList was retained from the former rfc822 module and is still used internally.

Yes, there is email.utils but for what I know, with the provided functionality it is not possible to parse a comma separated list of email addresses (ex. "a@example.com, b@example.com").

Since RFC5322 allow commas in the local part [1], one cannot simply split a list of email addresses by comma and use email.utils.getaddresses.

[1] http://tools.ietf.org/html/rfc5322#section-3.2.3
msg193711 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-07-25 18:43
No, but you can do this:

  >>> utils.getaddresses(['a@example.com, b@example.com'])
  [('', 'a@example.com'), ('', 'b@example.com')]

Not the worlds most intuitive API, I know...which is why we have implemented a new improved API.  In 3.3, by using the new (provisional) policies, you can get a parsed list of addresses right from the Message object, without having to do any further processing yourself:

  >>> import email.policy
  >>> m = email.message_from_string('To: a@example.com, b@example.com\n\n', policy=email.policy.default)
  >>> m['to']
  'a@example.com, b@example.com'
  >>> m['to'].addresses
  (Address(display_name='', username='a', domain='example.com'), Address(display_name='', username='b', domain='example.com'))

This new code is not as battle tested as the old code, so I need people to try using it in order to find the bugs :)
msg193712 - (view) Author: Lukas Pirl (lpirl) Date: 2013-07-25 18:53
Ah, obviously! :)

Thanks for your rapid and enlightening answer. Now, at least, this feature is documented and can be found by others.

Best!
History
Date User Action Args
2022-04-11 14:57:48adminsetgithub: 62757
2013-07-25 18:53:49lpirlsetmessages: + msg193712
2013-07-25 18:43:07r.david.murraysetstatus: open -> closed
resolution: out of date
messages: + msg193711

stage: resolved
2013-07-25 17:51:27lpirlcreate