-
-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from hslatman/hs_python_mailchecker
Add a simple Python template
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
node_modules | ||
npm-*.log | ||
compare.js | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import re | ||
|
||
class MailChecker(object): | ||
|
||
def __init__(self): | ||
self.list_string = """{{list}}""" | ||
|
||
# valid email format regex source: https://gist.github.com/dideler/5219706 | ||
self.email_regex = """([a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`" | ||
"{|}~-]+)*(@|\sat\s)(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(\.|" | ||
"\sdot\s))+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)""" | ||
self.fake_matcher = re.compile('|'.join(map(lambda x: '\\b' + x.lower() + '$', self.list_string.split(",")))) | ||
self.valid_matcher = re.compile(self.email_regex) | ||
|
||
def is_valid(self, email): | ||
email = email.lower() | ||
return self.is_valid_email_format(email) and self.fake_matcher.search(email) == None | ||
|
||
def is_valid_email_format(self, email): | ||
if email and email != '': | ||
return self.valid_matcher.search(email) != None | ||
else: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# compatibility with both Python 2.x and 3.x | ||
from __future__ import print_function | ||
|
||
# for testing only; add the python MailChecker to the system path | ||
import os, sys | ||
sys.path.insert(0, '../platform/python/') | ||
|
||
# import MailChecker, create instance, check emails | ||
import MailChecker | ||
|
||
m = MailChecker.MailChecker() | ||
|
||
print( m.is_valid('bla@example.com')) | ||
print( m.is_valid('bla@yourlms.biz')) | ||
print( m.is_valid('example@you.it')) | ||
print( m.is_valid('bla@hotmail.com')) | ||
print( m.is_valid('bla@yui.it')) | ||
print( m.is_valid('')) |