Non-deprecated equivalent of rfc822.AddressList

Jason Tackaberry tack at
Wed Sep 16 20:49:23 CEST 2009


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>, "Doe, Jane" <jane at>'
        >>> list(rfc822.AddressList(addrlist))
        [('John Doe', 'john at'), ('Doe, Jane', 'jane at')]

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

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

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

Now, email._parseaddr.AddrlistClass has this functionality:

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

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?


More information about the Python-list mailing list