-
-
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 branch 'rubygem' of https://github.com/buren/mailchecker into b…
…uren-rubygem # Conflicts: # .gitignore # README.md
- Loading branch information
Showing
7 changed files
with
149 additions
and
4 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,4 +2,6 @@ | |
node_modules | ||
npm-*.log | ||
compare.js | ||
*.pyc | ||
*.pyc | ||
*.gem | ||
Gemfile.lock |
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,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec |
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
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,15 @@ | ||
# coding: utf-8 | ||
Gem::Specification.new do |spec| | ||
spec.name = 'mail_checker' | ||
spec.version = '0.1.0' | ||
spec.authors = ['Francois-Guillaume Ribreau', 'Jacob Burenstam'] | ||
spec.email = ['github@fgribreau.com'] | ||
|
||
spec.summary = 'Temporary (disposable/throwaway) email detection library. Covers 1979 fake email providers.' | ||
spec.description = 'Cross-language temporary (disposable/throwaway) email detection library. Covers 1979 fake email providers. http://twitter.com/FGRibreau' | ||
spec.homepage = 'https://github.com/FGRibreau/mailchecker' | ||
spec.license = 'MIT' | ||
|
||
spec.files = ['platform/ruby/mail_checker.rb'] | ||
spec.require_paths = ['platform/ruby'] | ||
end |
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,32 @@ | ||
require 'set' | ||
|
||
module MailChecker | ||
# Based on PHP FILTER_VALIDATE_EMAIL | ||
# See https://fightingforalostcause.net/content/misc/2006/compare-email-regex.php | ||
EMAIL_REGEX = /^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/i | ||
# Blacklisted domains | ||
BLACKLIST = [{{& listSTR }}]. | ||
map(&:downcase). | ||
to_set | ||
|
||
def self.valid?(email) | ||
return false unless valid_email?(email) | ||
|
||
!BLACKLIST.include?(extract_domain(email)) | ||
end | ||
|
||
def self.valid_email?(email) | ||
return false if email.nil? | ||
|
||
email =~ EMAIL_REGEX | ||
end | ||
|
||
def self.extract_domain(email) | ||
domain = email.gsub(/.+@([^.]+)/, '\1').downcase | ||
domain.split('.')[-2, 2].join('.') # Don't include subdomains | ||
end | ||
end | ||
|
||
def MailChecker(email) | ||
MailChecker.valid?(email) | ||
end |
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,39 @@ | ||
require 'minitest/autorun' | ||
|
||
require_relative '../platform/ruby/mail_checker' | ||
|
||
class TestMailChecker < MiniTest::Unit::TestCase | ||
def valid!(email) | ||
assert_equal MailChecker(email), true | ||
end | ||
|
||
def invalid!(email) | ||
assert_equal MailChecker(email), false | ||
end | ||
|
||
def test_return_true_if_valid | ||
valid!('plop@plop.com') | ||
valid!('my.ok@ok.plop.com') | ||
valid!('my+ok@ok.plop.com') | ||
valid!('my=ok@ok.plop.com') | ||
valid!('ok@gmail.com') | ||
valid!('ok@hotmail.com') | ||
end | ||
|
||
def test_return_false_if_email_invalid | ||
invalid!('plopplop.com') | ||
invalid!('my+ok@ok=plop.com') | ||
invalid!('my,ok@ok.plop.com') | ||
invalid!('ok@tmail.com') | ||
end | ||
|
||
def test_return_false_if_throwable_domain | ||
invalid!('ok@33mail.com') | ||
invalid!('ok@ok.33mail.com') | ||
invalid!('ok@guerrillamailblock.com') | ||
end | ||
|
||
def test_can_be_called_as_regular_method | ||
assert_equal MailChecker.valid?(nil), false | ||
end | ||
end |