Non-deprecated equivalent of rfc822.AddressList

Jason Tackaberry tack at urandom.ca
Wed Sep 16 14:49:23 EDT 2009


Hi, 

Since the rfc822 module was removed in Python 3, and is deprecated in
2.3, I am obviously trying to avoid using it.

But I'm having a hard time finding an equivalent to rfc822.AddressList
in the email module, which I want to use to parse a _list_ of addresses:

        >>> addrlist = 'John Doe <john at example.com>, "Doe, Jane" <jane at example.com>'
        >>> list(rfc822.AddressList(addrlist))
        [('John Doe', 'john at example.com'), ('Doe, Jane', 'jane at example.com')]


email.utils.parseaddr() only returns the first address in the list:

        >>> email.utils.parseaddr(addrlist)
        ('John Doe', 'john at example.com')


email.utils.getaddresses() expects a list or tuple, and I can't simply
pass it addrlist.split(', ') for obvious reasons, and anyway rather
defeats the purpose of using a helper function to handle the tricky
bits.

Now, email._parseaddr.AddrlistClass has this functionality:

        >>> email._parseaddr.AddrlistClass(addrlist).getaddrlist()
        [('John Doe', 'john at example.com'), ('Doe, Jane', 'jane at example.com')]

But that's obviously not a documented, public interface.  Amusingly,
even in 3.1, the code for AddrlistClass says:

        Note: this class interface is deprecated and may be removed in
        the future.  Use rfc822.AddressList instead.


Is there some non-deprecated method I can use to parse an RFC 2822
address list?

Thanks,
Jason.





More information about the Python-list mailing list