7

I need something like rfc822.AddressList to parse, say, the content of the "TO" header field of an email into individual addresses. Since rfc822 is deprecated in favor of the email package, I looked for something similar there but couldn't find anything. Does anyone know what I'm supposed to use instead?

Thanks!

Chung Wu
  • 2,357
  • 3
  • 21
  • 19

2 Answers2

6

Oh it's email.utils.getaddresses. Just make sure to call it with a list.

Chung Wu
  • 2,357
  • 3
  • 21
  • 19
0

If you are open to using a third party module, I ported the Python 2.x module rfc822 to Python 3.x

https://github.com/MarkNenadov/rfc822py3

It hasn't been tested thoroughly yet. I encourage you to try it out and let me know how it works and whether you have any problems.

To make your code work in both Python 2 and 3 you can take my rfc822py3 module and do:

try:
   import rfc822
except ImportError:
   import rfc822py3 as rfc822
Yehor Levchenko
  • 56
  • 1
  • 2
  • 10
Mark Nenadov
  • 6,421
  • 5
  • 24
  • 32