email_check 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d64ea1ac92ccf662e1660edbea4ee7a8a45f2c53
4
+ data.tar.gz: fefbaf3c38fde3733d97e51c2133f3ab65777b88
5
+ SHA512:
6
+ metadata.gz: 1d091477971e0d98605b62214d98e4cc8f6ca1f6113a5dfc4c9effa77797f4b01db5791b3bb1306d5b5aba4df4f0c62cd4b096a2075614dd4addcc9869a1a5b2
7
+ data.tar.gz: 138b36b598eb657cda1688c8711d25b682eb8feb6da73fc829a07e4139a30c32482f0ee84c41e69dc2da40ae3757c7d1120bd20a8be33985baecef60f06e3d5a
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in email_check.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Darshan Patil
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # EmailCheck
2
+
3
+ [![Gem Version][GV img]][Gem Version]
4
+ [![Build Status][BS img]][Build Status]
5
+ [![Dependency Status][DS img]][Dependency Status]
6
+ [![Code Climate][CC img]][Code Climate]
7
+ [![Coverage Status][CS img]][Coverage Status]
8
+
9
+ ## Description
10
+
11
+
12
+
13
+ [Gem Version]: https://rubygems.org/gems/email_check
14
+ [Build Status]: https://travis-ci.org/dapatil/email_check
15
+ [travis pull requests]: https://travis-ci.org/dapatil/email_check/pull_requests
16
+ [Dependency Status]: https://gemnasium.com/dapatil/email_check
17
+ [Code Climate]: https://codeclimate.com/github/dapatil/email_check
18
+ [Coverage Status]: https://coveralls.io/r/dapatil/email_check
19
+
20
+ [GV img]: https://badge.fury.io/rb/email_check.png
21
+ [BS img]: https://travis-ci.org/dapatil/email_check.png
22
+ [DS img]: https://gemnasium.com/dapatil/email_check.png
23
+ [CC img]: https://codeclimate.com/github/dapatil/email_check.png
24
+ [CS img]: https://coveralls.io/repos/dapatil/email_check/badge.png?branch=master
25
+
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/[my-github-username]/email_check/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.pattern = "spec/**/*_spec.rb"
7
+ end
8
+
9
+ task :default => [:spec]
10
+ task :build => [:spec]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "email_check"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'email_check/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "email_check"
8
+ spec.version = EmailCheck::VERSION
9
+ spec.authors = ["Darshan Patil"]
10
+ spec.email = ["dapatil@gmail.com"]
11
+
12
+ spec.summary = %q{ActiveModel email validator. Checks MX records. Ships with lists of free, disposable email providers}
13
+ spec.description = %q{ActiveModel email validator. Checks MX records for domains. Allows you to block free/disposable email providers}
14
+ spec.homepage = "https://github.com/dapatil/email_check"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = ">= 2.0.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.9"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec","~> 3.2"
27
+ spec.add_development_dependency "simplecov", "~> 0.10.0"
28
+ spec.add_development_dependency "coveralls", "~> 0.8.1"
29
+ spec.add_development_dependency "mail", "~> 2.5"
30
+ spec.add_development_dependency "activemodel", ">= 4.2"
31
+ end
@@ -0,0 +1,43 @@
1
+ require "email_check/version"
2
+ require "email_check/email_validator"
3
+
4
+ module EmailCheck
5
+ # Disposable email providers
6
+ def self.disposable_email_domains
7
+ @@disposable_email_domains ||= []
8
+ end
9
+
10
+ def self.disposable_email_domains=(list)
11
+ @@disposable_email_domains = list
12
+ end
13
+
14
+ # Blacklist - This will also check for subdomains
15
+ def self.blacklisted_domains
16
+ @@blacklisted_domains ||= []
17
+ end
18
+
19
+ def self.blacklisted_domains=(list)
20
+ @@blacklisted_domains = list
21
+ end
22
+
23
+ # Free email providers
24
+ def self.free_email_domains
25
+ @@free_email_domains ||= []
26
+ end
27
+
28
+ def self.free_email_domains=(list)
29
+ @@free_email_domains = list
30
+ end
31
+
32
+ # Whitelist
33
+ def self.whitelisted_domains
34
+ @@whitelisted_domains ||= []
35
+ end
36
+
37
+ def self.whitelisted_domains=(list)
38
+ @@whitelisted_domains = list
39
+ end
40
+ end
41
+
42
+ # Load data!
43
+
@@ -0,0 +1,57 @@
1
+ require 'email_check'
2
+ require 'resolv'
3
+ require 'mail'
4
+
5
+ module EmailCheck
6
+ class EmailAddress
7
+ def initialize(email_address)
8
+ @email_address = email_address.downcase
9
+ @email = Mail::Address.new(@email_address) rescue nil
10
+ end
11
+
12
+ def format_valid?
13
+ @format_valid ||= check_format()
14
+ end
15
+
16
+ def disposable?
17
+ EmailCheck.disposable_email_domains.include?(@email.domain)
18
+ end
19
+
20
+ def free?
21
+ EmailCheck.free_email_domains.include?(@email.domain)
22
+ end
23
+
24
+ def blacklisted?
25
+ EmailCheck.blacklisted_domains.each do |domain|
26
+ return true if @email.domain.include?(domain)
27
+ end
28
+
29
+ false
30
+ end
31
+
32
+ def whitelisted?
33
+ EmailCheck.whitelisted_domains.include?(@email.domain)
34
+ end
35
+
36
+ def domain_has_mx?
37
+ return false unless format_valid?
38
+
39
+ Resolv::DNS.open do |dns|
40
+ return dns.getresources(@email.domain, Resolv::DNS::Resource::IN::MX).any?
41
+ end
42
+ end
43
+
44
+ private
45
+ def check_format
46
+ return false unless @email
47
+
48
+ if @email.domain && @email.address == @email_address
49
+ domain = @email.domain
50
+ # Must have a ., Must not have consecutive .s
51
+ domain.include?('.') && !domain.match(/\.{2,}/)
52
+ else
53
+ false
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,36 @@
1
+ require 'active_model'
2
+ require 'active_model/validations'
3
+ require 'email_check/email_address'
4
+
5
+ class EmailValidator < ActiveModel::EachValidator
6
+ def validate_each(record, attribute, value)
7
+ error(record, attribute) unless value.present?
8
+
9
+ address = EmailCheck::EmailAddress.new(value)
10
+
11
+ error(record, attribute) && return unless address.format_valid?
12
+
13
+ return if address.whitelisted?
14
+
15
+ if options[:disposable]
16
+ error(record, attribute) && return if address.disposable?
17
+ end
18
+
19
+ if options[:blacklist]
20
+ error(record, attribute) && return if address.blacklisted?
21
+ end
22
+
23
+ if options[:free]
24
+ error(record, attribute) && return if address.free?
25
+ end
26
+
27
+ if options[:mx]
28
+ error(record, attribute) && return unless address.domain_has_mx?
29
+ end
30
+ end
31
+
32
+ private
33
+ def error(record, attribute)
34
+ record.errors.add(attribute, options[:message] || :invalid)
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module EmailCheck
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: email_check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Darshan Patil
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: mail
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activemodel
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '4.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '4.2'
111
+ description: ActiveModel email validator. Checks MX records for domains. Allows you
112
+ to block free/disposable email providers
113
+ email:
114
+ - dapatil@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - email_check.gemspec
129
+ - lib/email_check.rb
130
+ - lib/email_check/email_address.rb
131
+ - lib/email_check/email_validator.rb
132
+ - lib/email_check/version.rb
133
+ homepage: https://github.com/dapatil/email_check
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 2.0.0
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.4.6
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: ActiveModel email validator. Checks MX records. Ships with lists of free,
157
+ disposable email providers
158
+ test_files: []