diff --git a/.gitignore b/.gitignore index 59d842b..30f7de0 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,8 @@ node_modules # Users Environment Variables .lock-wscript + +.idea +*.pyc +*.egg-info +dist diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..86ed68b --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +freemail \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/freemail.iml b/.idea/freemail.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/.idea/freemail.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..f117667 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,28 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..3b31283 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f3001dc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f464cf8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..96f82c2 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,600 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1458748151073 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 415d04f..c8aa6b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,10 @@ -language: node_js - -node_js: -- "0.10.28" +language: python +python: + - "2.7" + - "3.3" + - "3.4" + - "3.5" +# command to install dependencies +install: "pip install -r requirements.txt" +# command to run tests +script: python tests.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..2e6d258 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include freemail/update +include freemail/data/free.txt +include freemail/data/disposable.txt diff --git a/README.md b/README.md index 6b6cae8..5826f80 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -[![Build Status](https://travis-ci.org/willwhite/freemail.svg?branch=master)](https://travis-ci.org/willwhite/freemail) +[![Build Status](https://travis-ci.org/wearespindle/freemail.svg?branch=master)](https://travis-ci.org/wearespindle/freemail) # freemail A database of free and [disposable](http://en.wikipedia.org/wiki/Disposable_email_address) email domains and a handy Node.js module for querying it. -Use the Node.js module or access the files in the `./data` directory and parse +Install via npm or pip or access the files in the `./data` directory and parse with your language of choice. In an effort to create the most up-to-date list of domains, the database can be @@ -16,9 +16,9 @@ domains directly by opening a pull request. There are three key data files in this project: -- [free.txt](https://github.com/willwhite/freemail/blob/master/data/free.txt) contains a list of domains that are known to provide free email service -- [disposable.txt](https://github.com/willwhite/freemail/blob/master/data/disposable.txt) contains a list of domains that are known to provide disposable email service -- [blacklist.txt](https://github.com/willwhite/freemail/blob/master/data/blacklist.txt) contains a list of domains that this project will refuse to add to either list +- [free.txt](https://github.com/wearespindle/freemail/blob/master/data/free.txt) contains a list of domains that are known to provide free email service +- [disposable.txt](https://github.com/wearespindle/freemail/blob/master/data/disposable.txt) contains a list of domains that are known to provide disposable email service +- [blacklist.txt](https://github.com/wearespindle/freemail/blob/master/data/blacklist.txt) contains a list of domains that this project will refuse to add to either list Domains may only be a member of one list. @@ -29,23 +29,22 @@ Run `./update` to pull in the latest domains from the sources listed in If any domains provide disposable email service, they may be moved to `disposable.txt`. -## Node +## Python ### Install ``` -npm install --save freemail +pip install freemail ``` -```javascript -var freemail = require('freemail'); -freemail.isFree('smith@gmail.com'); -> true -freemail.isFree('jack@mailinater.com'); -> true -freemail.isDisposable('smith@gmail.com'); -> false -freemail.isDisposable('jack@mailinater.com'); -> true - +```python +>>> import freemail +>>> freemail.is_free('smith@gmail.com') +True +>>> freemail.is_free('jack@mailinater.com') +True +>>> freemail.is_disposable('smith@gmail.com') +False +>>> freemail.is_disposable('jack@mailinater.com') +True ``` diff --git a/freemail/__init__.py b/freemail/__init__.py new file mode 100644 index 0000000..d91dbf4 --- /dev/null +++ b/freemail/__init__.py @@ -0,0 +1,37 @@ +import os +import tldextract +import subprocess + +__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))) +free_file = os.path.join(__location__, './data/free.txt') +disp_file = os.path.join(__location__, './data/disposable.txt') + + +def is_free(email_address): + if not isinstance(email_address, str): + raise TypeError('email must be a string') + + with open(free_file, 'r') as free, open(disp_file, 'r') as disposable: + domain_list = free.read().splitlines() + disposable.read().splitlines() + domain = tldextract.extract(email_address.split('@')[1]).registered_domain + + return domain in domain_list + + +def is_disposable(email_address): + if not isinstance(email_address, str): + raise TypeError('email must be a string') + + with open(disp_file, 'r') as disposable: + domain_list = disposable.read().splitlines() + domain = tldextract.extract(email_address.split('@')[1]).registered_domain + + return domain in domain_list + + +def update(): + try: + subprocess.call("./update", shell=True) + return True + except subprocess.CalledProcessError: + return False diff --git a/data/blacklist.txt b/freemail/data/blacklist.txt similarity index 100% rename from data/blacklist.txt rename to freemail/data/blacklist.txt diff --git a/data/disposable.txt b/freemail/data/disposable.txt similarity index 99% rename from data/disposable.txt rename to freemail/data/disposable.txt index 6d85b83..e84a2c4 100644 --- a/data/disposable.txt +++ b/freemail/data/disposable.txt @@ -30,7 +30,6 @@ brefmail.com bsnow.net bspamfree.org bugmenot.com -byom.de casualdx.com centermail.com centermail.net @@ -210,7 +209,6 @@ privacy.net proxymail.eu prtnx.com putthisinyourspamdatabase.com -qq.com quickinbox.com rcpt.at recode.me diff --git a/data/free.txt b/freemail/data/free.txt similarity index 99% rename from data/free.txt rename to freemail/data/free.txt index cb9e0a3..2123930 100644 --- a/data/free.txt +++ b/freemail/data/free.txt @@ -200,6 +200,7 @@ bachelorboy.com bachelorgal.com backpackers.com backstreet-boys.com +backstreetboysclub.com bagherpour.com baldmama.de baldpapa.de @@ -621,6 +622,7 @@ epage.ru epix.net eposta.hu eresmas.com +eriga.lv estranet.it ethos.st etrademail.com @@ -1095,6 +1097,7 @@ italymail.com itmom.com ivebeenframed.com ivillage.com +iwan-fals.com iwmail.com iwon.com izadpanah.com @@ -1155,6 +1158,7 @@ krongthip.com krunis.com ksanmail.com ksee24mail.com +kube93mail.com kukamail.com kulturbetrieb.info kumarweb.com @@ -1208,14 +1212,12 @@ live.com.pt live.com.sg live.de live.dk -live.dk live.fr live.ie live.in live.it live.jp live.nl -live.nl live.ru live.se liverpoolfans.com @@ -1235,6 +1237,7 @@ lovelygirl.net lovemail.com lover-boy.com lovethebroncos.com +lovethecowboys.com loveyouforever.de lovingjesus.com lowandslow.com @@ -3389,6 +3392,7 @@ topmail.com.ar torontomail.com tortenboxer.de totalmail.de +totalmusic.net tpg.com.au trashdevil.de trialbytrivia.com @@ -3521,6 +3525,7 @@ webave.com webcammail.com webcity.ca webdream.com +webinbox.com webindia123.com webmail.co.za webmail.hu diff --git a/data/sources.txt b/freemail/data/sources.txt similarity index 100% rename from data/sources.txt rename to freemail/data/sources.txt diff --git a/update b/freemail/update similarity index 100% rename from update rename to freemail/update diff --git a/index.js b/index.js deleted file mode 100644 index f5cc7f6..0000000 --- a/index.js +++ /dev/null @@ -1,22 +0,0 @@ -var fs = require('fs'); -var tldjs = require('tldjs'); - -var disposable = fs.readFileSync(__dirname + '/data/disposable.txt').toString().split('\n'); -var free = fs.readFileSync(__dirname + '/data/free.txt').toString().split('\n').concat(disposable); - -function isFree(email) { - if (typeof email !== 'string') throw new TypeError('email must be a string'); - var domain = tldjs.getDomain(email.split('@').pop()); - return free.indexOf(domain) !== -1; -} - -function isDisposable(email) { - if (typeof email !== 'string') throw new TypeError('email must be a string'); - var domain = tldjs.getDomain(email.split('@').pop()); - return disposable.indexOf(domain) !== -1; -} - -module.exports = { - isFree: isFree, - isDisposable: isDisposable -}; diff --git a/package.json b/package.json deleted file mode 100644 index 1279f94..0000000 --- a/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "freemail", - "version": "1.2.0", - "description": "A database of free and disposable email domains and a handy Node.js module for querying it.", - "main": "index.js", - "scripts": { - "test": "tape test/test.js" - }, - "author": "Will White ", - "license": "ISC", - "devDependencies": { - "tape": "^3.5.0" - }, - "repository": { - "type": "git", - "url": "git://github.com/willwhite/freemail.git" - }, - "dependencies": { - "tldjs": "^1.5.2" - } -} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bd351db --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +tldextract==1.7.5 +pypandoc==1.1.3 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..de4b9de --- /dev/null +++ b/setup.py @@ -0,0 +1,78 @@ +"""A setuptools based setup module. +See: +https://packaging.python.org/en/latest/distributing.html +https://github.com/pypa/sampleproject +""" + +# Always prefer setuptools over distutils +from setuptools import setup, find_packages + +# For upload to pypi convert readme to rst. +try: + import pypandoc + long_description = pypandoc.convert('README.md', 'rst') +except: + long_description = '' + +setup( + name='freemail', + + # Versions should comply with PEP440. For a discussion on single-sourcing + # the version across setup.py and the project code, see + # https://packaging.python.org/en/latest/single_source_version.html + version='1.2.15', + + description='A database of free and disposable email domains', + long_description=long_description, + + # The project's main homepage. + url='https://github.com/wearespindle/freemail', + download_url='https://github.com/wearespindle/freemail', + # Author details + author='Devhouse Spindle', + author_email='info@wearespindle.com', + + # See https://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ + # How mature is this project? + # 1 - Planning + # 2 - Pre-Alpha + # 3 - Alpha + # 4 - Beta + # 5 - Production/Stable + # 6 - Mature + # 7 - Inactive + 'Development Status :: 4 - Beta', + + # Indicate who your project is intended for + 'Intended Audience :: Developers', + + # Specify the Python versions you support here. In particular, ensure + # that you indicate whether you support Python 2, Python 3 or both. + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.4', + ], + + # What does your project relate to? + keywords='email', + + # You can just specify the packages manually here if your project is + # simple. Or you can use find_packages(). + packages=find_packages(), + include_package_data=True, + + # List run-time dependencies here. These will be installed by pip when + # your project is installed. For an analysis of "install_requires" vs pip's + # requirements files see: + # https://packaging.python.org/en/latest/requirements.html + install_requires=[ + 'tldextract' + ], + + # List additional groups of dependencies here (e.g. development + # dependencies). You can install these using the following syntax, + # for example: + # $ pip install -e .[dev,test] + extras_require={}, + test_suite='' +) diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 83efd41..0000000 --- a/test/test.js +++ /dev/null @@ -1,32 +0,0 @@ -var test = require('tape'); -var freemail = require('..'); - -test('gmail.com should be free', function(t) { - t.plan(1); - t.equal(freemail.isFree('smith@gmail.com'), true); -}); - -test('gmail.com should be free with domain only', function(t) { - t.plan(1); - t.equal(freemail.isFree('gmail.com'), true); -}); - -test('fb.com should not be free', function(t) { - t.plan(1); - t.equal(freemail.isFree('fb.com'), false); -}); - -test('mailinater.com should be free', function(t) { - t.plan(1); - t.equal(freemail.isFree('smith@mailinater.com'), true); -}); - -test('mailinater.com should be disposable', function(t) { - t.plan(1); - t.equal(freemail.isDisposable('smith@mailinater.com'), true); -}); - -test('gmail.com should not be disposable', function(t) { - t.plan(1); - t.equal(freemail.isDisposable('smith@gmail.com'), false); -}); diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..0993e63 --- /dev/null +++ b/tests.py @@ -0,0 +1,17 @@ +import unittest +import freemail + + +class TestFreemail(unittest.TestCase): + + def test_free(self): + self.assertTrue(freemail.is_free('smith@gmail.com')) + self.assertTrue(freemail.is_free('jack@mailinater.com')) + self.assertFalse(freemail.is_free('something@notfree.com')) + + def test_disposable(self): + self.assertFalse(freemail.is_disposable('smith@gmail.com')) + self.assertTrue(freemail.is_disposable('jack@mailinater.com')) + +if __name__ == '__main__': + unittest.main()