Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encode/decode enhancement #122

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*.so

# Packages
*.egg
*.eggs
*.egg-info
dist
build
Expand All @@ -18,6 +18,7 @@ develop-eggs
lib
lib64
__pycache__
/ENV

# Installer logs
pip-log.txt
Expand All @@ -37,3 +38,7 @@ nosetests.xml

# Editor temp files
*.swp

# PLY
parser.out
parsetab.py
17 changes: 7 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
language: python
python: 2.7

env:
- TOX_ENV=py26
- TOX_ENV=py27
- TOX_ENV=pypy

python:
- 2.7
install:
- pip install tox

- pip install -e .
- pip install nose mock coverage coveralls
script:
- tox -e $TOX_ENV
- nosetests --with-coverage --cover-package=flanker
after_success:
- coveralls
30 changes: 11 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.. image:: https://drone.io/github.com/mailgun/flanker/status.png
Flanker - email address and MIME parsing for Python
===================================================

*******
Flanker
*******
.. image:: https://travis-ci.org/mailgun/flanker.svg?branch=master
:target: https://travis-ci.org/mailgun/flanker

.. image:: https://coveralls.io/repos/github/mailgun/flanker/badge.svg?branch=master
:target: https://coveralls.io/github/mailgun/flanker?branch=master

Flanker is an open source parsing library written in Python by the Mailgun Team.
Flanker currently consists of an address parsing library (`flanker.addresslib`) as
Expand All @@ -11,11 +14,8 @@ well as a MIME parsing library (`flanker.mime`).
Detailed documentation is provided in the `User Manual <https://github.com/mailgun/flanker/blob/master/docs/User%20Manual.md>`_ as well as the
`API Reference <https://github.com/mailgun/flanker/blob/master/docs/API%20Reference.md>`_. A Quickstart Guide is provided below.

Quickstart Guide
################

Installing
**********
----------

**Flanker was built and tested with Python 2.7.2.**

Expand All @@ -32,28 +32,20 @@ You'll need Python headers files before you start working with flanker, so insta

If you are using `pip`, simply type:


.. code-block:: bash

pip install flanker

*Note about installing from PyPi. Installing without specifying a version number will
install the latest version from PyPi that does not pin version dependences. This version
of Flanker will most likely work, but is not guaranteed. If you want to run a guaranteed
to work version of Flanker, run the version where we pin dependences, which is one lower
major version number. For example, if the current release is `0.4.4` then the stabled
pinned dependency version is `0.3.4`.*

If you are cloning from GitHub, you can type:

.. code-block:: bash

git clone [email protected]:mailgun/flanker.git
cd flanker
python setup.py install
pip install -e .

Address Parsing
***************
---------------

To parse a single mailbox (display name as well as email address):

Expand Down Expand Up @@ -129,7 +121,7 @@ To validate an address list:
([[email protected], [email protected]], ['@mailgun.com'])

MIME Parsing
************
------------

For the following examples, `message_string` will be set to the following MIME message:

Expand Down
45 changes: 8 additions & 37 deletions flanker/addresslib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
The flanker.addresslib package exposes a simple address parsing library that
can handle email addresses and urls.

Expand All @@ -8,43 +8,14 @@

To override the default DNS lookup library or MX Cache, use the
set_dns_lookup and set_mx_cache methods. For more details, see the User Manual.
'''
import re
"""

from flanker.addresslib.drivers.redis_driver import RedisCache
from flanker.addresslib.drivers.dns_lookup import DNSLookup

from flanker.addresslib.plugins import yahoo
from flanker.addresslib.plugins import aol
from flanker.addresslib.plugins import gmail
from flanker.addresslib.plugins import icloud
from flanker.addresslib.plugins import hotmail
from flanker.addresslib.plugins import google
def set_dns_lookup(dns_lookup):
from flanker.addresslib import validate
validate._dns_lookup = dns_lookup


mx_cache = RedisCache()
dns_lookup = DNSLookup()

YAHOO_PATTERN = re.compile(r'''mta[0-9]+\.am[0-9]+\.yahoodns\.net$''')
GMAIL_PATTERN = re.compile(r'''.*gmail-smtp-in\.l\.google.com$''')
AOL_PATTERN = re.compile(r'''.*\.mx\.aol\.com$''')
ICLOUD_PATTERN = re.compile(r'''.*\.mail\.icloud\.com$''')
HOTMAIL_PATTERN = re.compile(r'''mx[0-9]\.hotmail\.com''')
GOOGLE_PATTERN = re.compile(r'''(.*aspmx\.l\.google\.com$)|(aspmx.*\.googlemail.com$)''', re.IGNORECASE)

CUSTOM_GRAMMAR_LIST = [
(YAHOO_PATTERN, yahoo),
(GMAIL_PATTERN, gmail),
(AOL_PATTERN, aol),
(ICLOUD_PATTERN, icloud),
(HOTMAIL_PATTERN, hotmail),
(GOOGLE_PATTERN, google),
]

def set_dns_lookup(dlookup):
global dns_lookup
dns_lookup = dlookup

def set_mx_cache(mcache):
global mx_cache
mx_cache = mcache
def set_mx_cache(mx_cache):
from flanker.addresslib import validate
validate._mx_cache = mx_cache
Loading