email_check 0.1.4 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2fa37a71c436036dacc36c1bf38d1fc276e3a644
4
- data.tar.gz: 56c787b14b00b78172b51d0b12a58252d1de5d00
2
+ SHA256:
3
+ metadata.gz: be0cba5ca74845cdd02da6697b576bd3a38947116123179123dae393fd0247e3
4
+ data.tar.gz: 865c687b2a7c627da107d4157057d9a3dbb6d9de0203b94c90b0ccd40abf6578
5
5
  SHA512:
6
- metadata.gz: 4837b5e6772915a42264e22a54e8d656cb5a30f596d899f74b0e97d199b620e68822e6eb73156a3fa5e25c9127e74af7ad4ba7b7051565f53d7da7a4b4200e32
7
- data.tar.gz: e9c9d583eecec2a3395261f285fd53815875f9269539f4ae3f424faedf94c21b2a587e292b14c65c23b489a1afdd84cfe099d51ba03f018e0408994d2b909bb4
6
+ metadata.gz: c1afee8e164514a3f5f74dddf556b494be9a4fffc459322765a808bd4a944b4e8452b308016d864299d50bb15dc40a10ec513d38c12971577d246fec69e2aaa0
7
+ data.tar.gz: 90c4f836d99891b514b9aee8da286af6ffa3910bc10d5312df949dde633cb7c13c76733cf023b70224f608abfc195934bdf8f216cf6ab989976769b6d3a2eb3c
@@ -0,0 +1,70 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ master ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ master ]
20
+ schedule:
21
+ - cron: '16 2 * * 5'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'ruby' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
+ # Learn more about CodeQL language support at https://git.io/codeql-language-support
38
+
39
+ steps:
40
+ - name: Checkout repository
41
+ uses: actions/checkout@v3
42
+
43
+ # Initializes the CodeQL tools for scanning.
44
+ - name: Initialize CodeQL
45
+ uses: github/codeql-action/init@v1
46
+ with:
47
+ languages: ${{ matrix.language }}
48
+ # If you wish to specify custom queries, you can do so here or in a config file.
49
+ # By default, queries listed here will override any specified in a config file.
50
+ # Prefix the list here with "+" to use these queries and those in the config file.
51
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
52
+
53
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54
+ # If this step fails, then you should remove it and run the build manually (see below)
55
+ - name: Autobuild
56
+ uses: github/codeql-action/autobuild@v1
57
+
58
+ # ℹ️ Command-line programs to run using the OS shell.
59
+ # 📚 https://git.io/JvXDl
60
+
61
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62
+ # and modify them (or add more) to build your code if your project
63
+ # uses a compiled language
64
+
65
+ #- run: |
66
+ # make bootstrap
67
+ # make release
68
+
69
+ - name: Perform CodeQL Analysis
70
+ uses: github/codeql-action/analyze@v1
data/.travis.yml CHANGED
@@ -1,9 +1,18 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
4
- - 2.1.0
5
- - 2.0.0
3
+ - 2.3.0
4
+ - 2.5.0
6
5
 
7
6
  gemfile:
8
7
  - gemfiles/activemodel4.gemfile
8
+ - gemfiles/activemodel5.gemfile
9
+ - gemfiles/activemodel6.gemfile
9
10
 
11
+ matrix:
12
+ exclude:
13
+ - rvm: 2.3.0
14
+ gemfile: gemfiles/activemodel6.gemfile
15
+ - rvm: 2.5.0
16
+ gemfile: gemfiles/activemodel4.gemfile
17
+
18
+ before_install: gem install bundler
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Coverage Status][CS img]][Coverage Status]
8
8
 
9
9
  ## Description
10
- This was built for [Anonybuzz](https://anonybuzz.com).
10
+ This was originally built for [Anonybuzz](https://anonybuzz.com) and is now used at [StarTalent](https://startalent.io).
11
11
  This gem provides a robust mechanism to validate email addresses and restrict account creation to corporate email accounts.
12
12
 
13
13
  This gem also ships with a data-set of free and [disposable](http://en.wikipedia.org/wiki/Disposable_email_address)
@@ -26,46 +26,57 @@ You can also block certain usernames from creating accounts. Examples: admin, ro
26
26
  ## Installation
27
27
  Add this line to your application's Gemfile:
28
28
  ```ruby
29
- gem "check_email"
29
+ gem "email_check"
30
30
  ```
31
31
 
32
32
  ## Usage
33
33
  ### Use with ActiveModel
34
- To validate just the email address:
34
+ To validate just the format of the email address
35
35
  ```ruby
36
36
  class User < ActiveRecord::Base
37
- validates :email, email: true
37
+ validates_email :email
38
38
  end
39
39
  ```
40
40
  To validate that the domain has a MX record:
41
41
  ```ruby
42
- validates :email, email: { mx: true }
42
+ validates_email :email, check_mx: true
43
43
  ```
44
44
  To validate that the email is not from a disposable or free email provider:
45
45
  ```ruby
46
- validates :email, email: { disposable:true, free:true }
46
+ validates_email :email, not_disposable:true, not_free:true
47
47
  ```
48
48
  To validate that the domain is not blacklisted:
49
49
  ```ruby
50
- validates :email, email: { blacklist:true}
50
+ validates_email :email, not_blacklisted:true
51
51
  ```
52
52
 
53
53
  To validate that the username is not blocked
54
54
  ```ruby
55
- validates :email, email: { blocked_usernames:true }
55
+ validates_email :email, block_special_usernames:true
56
+ ```
56
57
 
57
58
  Everything together:
58
59
  ```ruby
59
- validates :email, email: {
60
- mx: true,
61
- disposable:true,
62
- free:true,
63
- blacklist:true,
64
- blocked_usernames:true,
65
- message: "Please register with your corporate email" }
60
+ validates_email :email,
61
+ check_mx: true,
62
+ not_disposable:true,
63
+ not_free:true,
64
+ not_blacklisted:true,
65
+ block_special_usernames:true,
66
+ message: "Please register with your corporate email"
67
+ ```
68
+
69
+ To turn everything on by default, you can use the validates_email_strictness helper.
70
+
71
+ ```ruby
72
+ # Example above
73
+ validates_email_strictness :email
74
+
75
+ # Everything but allow free emails. This is what most people would want to use
76
+ validates_email_strictness :email, not_free:false
66
77
  ```
67
78
 
68
- ### Modifying inbuilt lists
79
+ ### Modifying the inbuilt lists
69
80
  The lists are exposed as assignable arrays so you can customize them or load whatever data you please.
70
81
 
71
82
  Add a config/intializers/email_check.rb
@@ -75,16 +86,21 @@ EmailCheck.disposable_email_domains = ['freemail.org']
75
86
  # Append to the whitelist
76
87
  EmailCheck.whitelisted_domains << 'gmail.com'
77
88
  EmailCheck.free_email_domains << 'thenewgmail.com'
78
- # Setting a domain in the blacklist also will blacklist all subdomains
89
+ # Setting a domain in the blacklist will also blacklist all subdomains
79
90
  EmailCheck.blacklisted_domains << 'lvh.me'
91
+ # Block the 'anonymous' username for all domains
80
92
  EmailCheck.blocked_usernames << 'anonymous'
81
93
  ```
82
94
 
83
95
  ## Requirements
84
96
  This gem is tested with Rails 4.0+. Ruby versions tested:
85
- - Ruby 2.0
86
- - Ruby 2.1
87
- - Ruby 2.2
97
+ - Ruby 2.3
98
+ - Ruby 2.5
99
+
100
+ Rails versions tested:
101
+ Rails 4.0
102
+ Rails 5.0
103
+ Rails 6.0
88
104
 
89
105
  ## Credits
90
106
  - This code is heavily based upon: [lisinge/valid_email2](https://github.com/lisinge/valid_email2)
data/SECURITY.md ADDED
@@ -0,0 +1,14 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Use this section to tell people about which versions of your project are
6
+ currently being supported with security updates.
7
+
8
+ | Version | Supported |
9
+ | ------- | ------------------ |
10
+ | 1.0.2 | :white_check_mark: |
11
+ | 1.0.1 | :x: |
12
+ | 1.0.0 | :x: |
13
+
14
+
data/email_check.gemspec CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.required_ruby_version = ">= 2.0.0"
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.9"
25
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "bundler", "~> 2.3"
25
+ spec.add_development_dependency "rake", "~> 12.3.3"
26
26
  spec.add_development_dependency "rspec","~> 3.2"
27
27
  spec.add_development_dependency "simplecov", "~> 0.10.0"
28
28
  spec.add_development_dependency "coveralls", "~> 0.8.1"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activemodel", "~> 5.0.0"
4
+
5
+ gemspec path: "../"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activemodel", "~> 6.1.0"
4
+
5
+ gemspec path: "../"
@@ -17,19 +17,19 @@ module EmailCheck
17
17
  EmailCheck.disposable_email_domains.include?(@email.domain)
18
18
  end
19
19
 
20
- def free?
20
+ def free_email_provider?
21
21
  EmailCheck.free_email_domains.include?(@email.domain)
22
22
  end
23
23
 
24
- def blacklisted?
24
+ def blacklisted_domain?
25
25
  EmailCheck.blacklisted_domains.each do |domain|
26
- return true if @email.domain.include?(domain)
26
+ return true if @email.domain&.include?(domain)
27
27
  end
28
28
 
29
29
  false
30
30
  end
31
31
 
32
- def whitelisted?
32
+ def whitelisted_domain?
33
33
  EmailCheck.whitelisted_domains.include?(@email.domain)
34
34
  end
35
35
 
@@ -39,10 +39,11 @@ module EmailCheck
39
39
 
40
40
  def domain_has_mx?
41
41
  return false unless format_valid?
42
-
42
+ val = false
43
43
  Resolv::DNS.open do |dns|
44
- return dns.getresources(@email.domain, Resolv::DNS::Resource::IN::MX).any?
44
+ val = dns.getresources(@email.domain, Resolv::DNS::Resource::IN::MX).any?
45
45
  end
46
+ return val
46
47
  end
47
48
 
48
49
  private
@@ -1,40 +1,54 @@
1
1
  require 'active_model'
2
2
  require 'active_model/validations'
3
3
  require 'email_check/email_address'
4
+ require 'pp'
4
5
 
5
6
  class EmailValidator < ActiveModel::EachValidator
6
7
  def validate_each(record, attribute, value)
7
- error(record, attribute) unless value.present?
8
8
 
9
- address = EmailCheck::EmailAddress.new(value)
9
+ unless value.present?
10
+ add_error(record, attribute)
11
+ return
12
+ end
10
13
 
11
- error(record, attribute) && return unless address.format_valid?
14
+ address = EmailCheck::EmailAddress.new(value)
12
15
 
13
- return if address.whitelisted?
16
+ unless address && address.format_valid?
17
+ add_error(record, attribute)
18
+ return
19
+ end
14
20
 
15
- if options[:blocked_usernames]
16
- error(record, attribute) && return if address.blocked_username?
21
+ if options[:block_special_usernames] && address.blocked_username?
22
+ add_error(record, attribute)
23
+ return
17
24
  end
18
25
 
19
- if options[:disposable]
20
- error(record, attribute) && return if address.disposable?
26
+ return if address.whitelisted_domain?
27
+
28
+ if options[:not_disposable] && address.disposable?
29
+ add_error(record, attribute)
30
+ return
21
31
  end
22
32
 
23
- if options[:blacklist]
24
- error(record, attribute) && return if address.blacklisted?
33
+ if options[:not_blacklisted] && address.blacklisted_domain?
34
+ add_error(record, attribute)
35
+ return
25
36
  end
26
37
 
27
- if options[:free]
28
- error(record, attribute) && return if address.free?
38
+ if options[:not_free] && address.free_email_provider?
39
+ add_error(record, attribute)
40
+ return
29
41
  end
30
42
 
31
- if options[:mx]
32
- error(record, attribute) && return unless address.domain_has_mx?
43
+ # TODO: Add a callback to bypass this if the domain is already known
44
+ if options[:check_mx] && address.domain_has_mx? == false
45
+ add_error(record, attribute)
46
+ return
33
47
  end
34
48
  end
35
49
 
36
50
  private
37
- def error(record, attribute)
51
+ def add_error(record, attribute)
38
52
  record.errors.add(attribute, options[:message] || :invalid)
39
53
  end
40
54
  end
@@ -0,0 +1,27 @@
1
+ module ActiveModel
2
+ module Validations
3
+ module HelperMethods
4
+ # Validates email
5
+ #
6
+ # Configuration options:
7
+ # * <tt>:check_mx</tt> - Check MX record for domain
8
+ # * <tt>:not_disposable</tt> - Check that this is not a disposable email
9
+ # * <tt>:not_free</tt> - Not a free email (ex. gmail.com, hotmail.com)
10
+ # * <tt>:not_blacklisted</tt> - If domain is on the blacklist, reject it
11
+ # * <tt>:block_special_usernames</tt> - If the username is one of the special usernames, reject it
12
+ def validates_email(*attr_names)
13
+ validates_with EmailValidator, _merge_attributes(attr_names)
14
+ end
15
+
16
+ # Turn everything on..
17
+ def validates_email_strictness(*attr_names)
18
+ validates_with EmailValidator, _merge_attributes(attr_names).merge(
19
+ :check_mx => true,
20
+ :not_disposable => true,
21
+ :not_free => true,
22
+ :not_blacklisted => true,
23
+ :block_special_usernames => true)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module EmailCheck
2
- VERSION = "0.1.4"
2
+ VERSION = "1.0.2"
3
3
  end
data/lib/email_check.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "email_check/version"
2
2
  require "email_check/email_validator"
3
+ require 'email_check/helper_methods'
3
4
 
4
5
  module EmailCheck
5
6
  # Load the data
data/vendor/blacklist.yml CHANGED
@@ -4,3 +4,4 @@
4
4
  - freeservers.com
5
5
  - zzn.com
6
6
  - lvh.me
7
+ - acccounts.com