Skip to content

Batterii/python-email-normalizer

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
This branch is 8 commits ahead of r-dmv:master.

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Python email normalizer

Originally forked from: python-email-normalizer. Adds a few extra utilities.

Usage

from email_normalizer import normalize

# returns alicetestemail@gmail.com
normalize('Alice.Test.Email+2e16f5091e4c9a1fecd712ad1e019569@gmail.com')

Default normalizer

The default normalizer can be overridden if you want to specify your own behavior.

from email_normalizer import normalize, BaseNormalizer

class MyNormalizer(BaseNormalizer):
    @classmethod
    def normalize(cls, local_part, domain):
        local_part = local_part.split('--')[0]
        return '{0}@{1}'.format(local_part, domain)

# returns bob@cipher.com
normalize('Bob--Test@cipher.com', default_normalizer=MyNormalizer)

Registering / Unregistering normalizers

3rd party normalizers can be registered and unregistered to provide alternate behavior for known domains.

from email_normalizer import normalize, register_normalizer, \
    unregister_normalizer, BaseNormalizer

class FooBarNormalizer(BaseNormalizer):
    domains = ['foobar.com']

    @classmethod
    def normalize(cls, local_part, domain):
        local_part = local_part.split('--')[0]
        return '{0}@{1}'.format(local_part, domain)

# register the normalizer for foobar.com
register_normalizer(FooBarNormalizer)

# returns bob@cipher.com
normalize('Bob--Test@cipher.com')

# unregister the normalizer for foobar.com
unregister_normalizer(FooBarNormalizer)

# returns bob--test@cipher.com
normalize('Bob--Test@cipher.com')

Running tests

# The first run will fetch requirements / dependencies
python setup.py test

About

Python email normalization library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%