When evaluating the addresses of incoming mail, Gmail servers...
- Are case insensitive
- Ignore periods
- Ignore any text after a plus sign
Additionally, @gmail.com and @googlemail.com can be used interchangeably.
All of these variables make it difficult to check a given email address for uniqueness.
The normalize(email) method in canonical_gmail.py transforms any email address on a Gmail server,
including Google Apps addresses with custom domains, to its simplest, canonical representation
(E.g., firstname.lastname@example.org becomes email@example.com) so that it can be compared against other canonical addresses.
>>> from canonical_gmail import normalize >>> >>> normalize('firstname.lastname@example.org') #Gmail address 'email@example.com' >>> >>> normalize('firstname.lastname@example.org') #Googlemail address 'email@example.com' >>> >>> normalize('firstname.lastname@example.org') #Google Apps custom domain address 'email@example.com' >>> >>> normalize('firstname.lastname@example.org') #Non-Gmail address 'email@example.com'
The canonical address should not be stored in lieu of the user's inputed address, as some folks use these modifications to route their incoming email to particular folders.These Gmail power users can be a persnickety bunch. Don't mess up their system.
DEPENDENCY: https://github.com/rthalley/dnspython (or 'pip install dnspython')