Skip to content

Commit

Permalink
Merged master.
Browse files Browse the repository at this point in the history
  • Loading branch information
Russell Jones committed Jan 14, 2015
2 parents 2eb5d6b + 2f13176 commit c267d31
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/User Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Exchanger responds, the domain is considered invalid.
above two steps can be cached to improve performance. `flanker` by default uses Redis
for this cache, but use of Redis is not required. Similar to the DNS lookup library,
any cache can be used here, as long as the interface as the same as that of a `dict`.
See [flanker/addresslib/drivers/redis_cache.py](../flanker/addresslib/drivers/redis_cache.py)
See [flanker/addresslib/drivers/redis_driver.py](../flanker/addresslib/drivers/redis_driver.py)
for an example.

3. **Custom Grammar.** Large ESPs rarely if ever support the full grammar that the RFC allows
Expand All @@ -190,7 +190,7 @@ grammar, then the validator will run that additional check on the localpart of t
domain portion of an email address. This can be used to correct common typos like `gmal.com`
instead of `gmail.com`. The spelling corrector uses `difflib` which in turn uses the
[Ratcliff-Obershelp](http://xlinux.nist.gov/dads/HTML/ratcliffObershelp.html) algorithm
to compute the similarity of two strings. This is a very fast an accurate algorithm for
to compute the similarity of two strings. This is a very fast and accurate algorithm for
domain spelling correction.

###### Example: Validate a single email address
Expand Down
15 changes: 14 additions & 1 deletion flanker/addresslib/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from flanker.mime.message.headers.encodedword import mime_to_unicode
from urlparse import urlparse


@metrics_wrapper()
def parse(address, addr_spec_only=False, metrics=False):
"""
Expand Down Expand Up @@ -130,7 +131,7 @@ def parse_list(address_list, strict=False, as_tuple=False, metrics=False):

# if we have a list, transform it into a string first
if isinstance(address_list, list):
address_list = ', '.join([str(addr) for addr in address_list])
address_list = ', '.join(_normalize_address_list(address_list))

# parse
try:
Expand Down Expand Up @@ -607,3 +608,15 @@ def addr_types(self):
Returns a set of address types used in addresses in this list.
"""
return set([addr.addr_type for addr in self.container])


def _normalize_address_list(address_list):
parts = []

for addr in address_list:
if isinstance(addr, Address):
parts.append(addr.to_unicode())
if isinstance(addr, basestring):
parts.append(addr)

return parts
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


setup(name='flanker',
version='0.3.25',
version='0.3.26',
description='Mailgun Parsing Tools',
long_description=open('README.rst').read(),
classifiers=[],
Expand Down
18 changes: 18 additions & 0 deletions tests/addresslib/address_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ def test_addresslist_with_apostrophe():
eq_(u'Eugueny ώ Kontsevoy', lst[0].display_name)


def test_addresslist_non_ascii_list_input():
al = [u'Aurélien Berger <[email protected]>', 'Os Wi <[email protected]>']
lst = parse_list(al)
eq_(2, len(lst))
eq_('=?utf-8?q?Aur=C3=A9lien_Berger?= <[email protected]>', lst[0].full_spec())
eq_('Os Wi <[email protected]>', lst[1].full_spec())


def test_addresslist_address_obj_list_input():
al = [EmailAddress(u'Aurélien Berger <[email protected]>'),
UrlAddress('https://www.example.com')]
lst = parse_list(al)
eq_(2, len(lst))
eq_('=?utf-8?q?Aur=C3=A9lien_Berger?= <[email protected]>',
lst[0].full_spec())
eq_('https://www.example.com', lst[1].full_spec())


def test_edge_cases():
email = EmailAddress('"foo.bar@"@example.com')
eq_('"foo.bar@"@example.com', email.address)
Expand Down

0 comments on commit c267d31

Please sign in to comment.