I want to be able to parse email addresses to isolate the domain part, and test if an email address is part of a given domain.

The email module doesn't, as far as I can tell, do that. Is there anything worth using to do this other than the usual string handling and regex routines?

Note: I know how to deal with python strings. I don't need basic recipes, although awesome recipes are welcome.

The problem here is essentially that email addresses have the format (schematically) userpart@sub\.domain\.[sld]+\.tld.

Stripping the part before the @ is easy; the hard part is parsing the domain to work out which parts are subdomains on a larger organisation's domain, rather than generic second-level (or, I guess even higher order) public domains.

Imagine parsing user@mail.organisation.co.uk to find that the organisation's domain name is organisation.co.uk and so be able to match both mail.organisation.co.uk and finance.organisation.co.uk as subdomains of organisation.co.uk.

There are basically two possible (non-dns-based) approaches: build a finite automaton that knows about all generic slds and their relation to the tld (including popular 'fake' slds like uk.com), or try to guess, based on the knowledge that there must be a tld, and assuming that if there are three (or more) elements, the second-level domain is generic if it has fewer than three/four characters. The relative drawbacks of each approach should be obvious.

The alternative is to look through DNS entries to work out what is a registered domain, which has its own drawbacks.