rich_email_validator 0.0.1
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 +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +22 -0
- data/.yardopts +5 -0
- data/Gemfile +30 -0
- data/Guardfile +7 -0
- data/LICENSE.md +16 -0
- data/README.md +103 -0
- data/Rakefile +10 -0
- data/collection.rb +20 -0
- data/lib/rich_email_validator/email_validator.rb +67 -0
- data/lib/rich_email_validator/file_validator.rb +58 -0
- data/lib/rich_email_validator/list_validator.rb +60 -0
- data/lib/rich_email_validator/version.rb +15 -0
- data/lib/rich_email_validator.rb +48 -0
- data/rich_email_validator.gemspec +20 -0
- data/spec/fixtures/list_fixture.txt +15 -0
- data/spec/fixtures/valid_fixture.txt +10 -0
- data/spec/helper.rb +103 -0
- data/spec/rich_email_validator/email_validator_spec.rb +47 -0
- data/spec/rich_email_validator/file_validator_spec.rb +28 -0
- data/spec/rich_email_validator/list_validator_spec.rb +15 -0
- data/spec/rich_email_validator/rich_email_validator_spec.rb +86 -0
- data/spec/rich_email_validator/version_spec.rb +9 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 342b23a6f90fe7e83ee17b5c4d359c9bbc06cb69
|
4
|
+
data.tar.gz: 68036edb2fbff383bd50ee82b238b89ea445044b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f5a82bca84c3d7b9b5e23cdfd7e486e4089e2da26c318cb55f0684c8ded936d0c44b1b796c74127e2d49ebdce6bb592cbbfef2991f493fc17678158fa96454d4
|
7
|
+
data.tar.gz: 9990e019cc24483513138ca10a6d67733bd8fd1141158c00aa7674d7b580d71ca2da8f4ce0bb30ea75630d564741bc588dc04cb5ef0712e2279f9e45934d29e3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
bundler_args: --without development
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
- 2.0.0
|
7
|
+
- 2.1
|
8
|
+
- rbx-2
|
9
|
+
- jruby-19mode
|
10
|
+
- ruby-head
|
11
|
+
- jruby-head
|
12
|
+
matrix:
|
13
|
+
include:
|
14
|
+
- rvm: jruby-19mode
|
15
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
16
|
+
- rvm: jruby-head
|
17
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
18
|
+
allow_failures:
|
19
|
+
- rvm: jruby-head
|
20
|
+
- rvm: rbx-2
|
21
|
+
- rvm: ruby-head
|
22
|
+
fast_finish: true
|
data/.yardopts
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'jruby-openssl', :platforms => :jruby
|
4
|
+
gem 'rake'
|
5
|
+
gem 'yard'
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem 'pry'
|
9
|
+
gem 'pry-remote'
|
10
|
+
gem 'pry-nav'
|
11
|
+
platforms :ruby_19, :ruby_20, :ruby_21 do
|
12
|
+
gem 'redcarpet'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem 'coveralls', '~> 0.7', :require => false
|
18
|
+
gem 'rspec', '>= 2.14'
|
19
|
+
gem 'rspec-nc'
|
20
|
+
gem 'rubocop', '>= 0.2', :platforms => [:ruby_19, :ruby_20, :ruby_21]
|
21
|
+
gem 'simplecov', '~> 0.7.1', :require => false
|
22
|
+
if RUBY_VERSION >= "1.9.3"
|
23
|
+
gem 'guard', '~> 2.6'
|
24
|
+
gem 'guard-rspec', '~> 4.2'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
# Specify your gem's dependencies in feedlr.gemspec
|
30
|
+
gemspec
|
data/Guardfile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
guard 'rspec' do
|
2
|
+
watch(%r{^spec/.+_spec\.rb$})
|
3
|
+
watch(%r{^spec/gateway/.+_spec\.rb$})
|
4
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/feedlr/#{m[1]}_spec.rb" }
|
5
|
+
watch(%r{^lib/gateway/(.+)\.rb$}) { |m| "spec/feedlr/gateway/#{m[1]}_spec.rb" }
|
6
|
+
watch('spec/helper.rb') { "spec" }
|
7
|
+
end
|
data/LICENSE.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Copyright (c) 2014 Khaled alHabache
|
2
|
+
|
3
|
+
LGPL-3.0 License
|
4
|
+
|
5
|
+
This library is free software; you can redistribute it and/or
|
6
|
+
modify it under the terms of the GNU Lesser General Public
|
7
|
+
License as published by the Free Software Foundation; either
|
8
|
+
version 3.0 of the License, or (at your option) any later version.
|
9
|
+
|
10
|
+
This library is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public
|
16
|
+
License along with this library.
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# RichEmailValidator
|
2
|
+
|
3
|
+
A set of helpers to validate emails:
|
4
|
+
|
5
|
+
- [x] Validate an email
|
6
|
+
- [x] Filter a list of emails
|
7
|
+
- [x] Filter a list of emails from file
|
8
|
+
- [x] Filter a list of emails from file and output to file
|
9
|
+
|
10
|
+
It works as follows:
|
11
|
+
|
12
|
+
- Checks the availability of the mx records of the email's domain. This is done via a DNS lookup.
|
13
|
+
- Checks the format of the email via a regular expression that can be configured. **This is done for performance only**.
|
14
|
+
- Use a configurable number of threads to check thousands of emails in minutes.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
gem 'rich_email_validator'
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install rich_email_validator
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
### Validate an email
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'rich_email_validator'
|
36
|
+
RichEmailValidator.valid_email?('khellls@gmail.com') # => true
|
37
|
+
RichEmailValidator.valid_email?('khellls@g.com') # => false because DNS lookup check
|
38
|
+
```
|
39
|
+
### Set a predfined Regexp
|
40
|
+
|
41
|
+
It's only used for **performace reasons** to filter the format of an email before doing a DNS lookup check.
|
42
|
+
|
43
|
+
The current value is:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
/\A[\w!#$%&'*+\/=?`{|}~^-]+(?:\.[\w!#$%&'*+\/=?`{|}~^-]+)*@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}\Z/i
|
47
|
+
|
48
|
+
```
|
49
|
+
|
50
|
+
You can change it:
|
51
|
+
```ruby
|
52
|
+
# Customized email regular expression
|
53
|
+
RichEmailValidator.email_regexp = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
### Filter a list of emails
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
list = ['khellls@g.com', 'khellls@gmail.com']
|
61
|
+
RichEmailValidator.filter_list(list) #=> ["khellls@gmail.com"]
|
62
|
+
|
63
|
+
# You have a fine grained control, so you can control threads count
|
64
|
+
# Default is 20
|
65
|
+
RichEmailValidator.filter_list(list, threads_count: 15)
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
### Filter a list of emails from file
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
file_path = '/path/to/emails_list'
|
73
|
+
File.readlines(file_path).size #=> 15
|
74
|
+
RichEmailValidator.filter_file(file_path).size #=> 10
|
75
|
+
|
76
|
+
# You have a fine grained control, so you can control threads count
|
77
|
+
# Default is 20
|
78
|
+
RichEmailValidator.filter_file(file_path, threads_count: 15)
|
79
|
+
|
80
|
+
```
|
81
|
+
|
82
|
+
### Filter a list of emails from file and output to file
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
file_path = '/path/to/emails_list'
|
86
|
+
output_path = '/path/to/output'
|
87
|
+
File.readlines(file_path).size # => 15
|
88
|
+
RichEmailValidator.export_valid_list(file_path, output_path)
|
89
|
+
File.readlines('output.txt').size #=> 10
|
90
|
+
|
91
|
+
# You have a fine grained control, so you can control threads count
|
92
|
+
# Default is 20
|
93
|
+
RichEmailValidator.export_valid_list(file_path, output_path, threads_count: 15)
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
## Contributing
|
98
|
+
|
99
|
+
1. Fork it ( https://github.com/[my-github-username]/rich_email_validator/fork )
|
100
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
101
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
102
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
103
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
task.rspec_opts = ['--color', '--format', 'doc']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :spec
|
data/collection.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
module Feedlr
|
3
|
+
# When the response is of Array type,
|
4
|
+
# it creates an array of Feedlr::Base or plain types values
|
5
|
+
class Collection < SimpleDelegator
|
6
|
+
# Initializer
|
7
|
+
# @param [Array] data
|
8
|
+
# @return [Feedlr::Collection]
|
9
|
+
def initialize(data = [])
|
10
|
+
super([])
|
11
|
+
data.each { |value| self << build_object(value) }
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def build_object(value)
|
17
|
+
value.is_a?(Hash) ? Feedlr::Base.new(value) : value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'resolv'
|
2
|
+
|
3
|
+
module RichEmailValidator
|
4
|
+
# Validate email address
|
5
|
+
class EmailValidator
|
6
|
+
class << self
|
7
|
+
attr_writer :email_regexp
|
8
|
+
|
9
|
+
def valid?(email)
|
10
|
+
new(email).valid?
|
11
|
+
end
|
12
|
+
|
13
|
+
def email_regexp
|
14
|
+
@email_regexp || default_email_regexp
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def default_email_regexp
|
20
|
+
@default_email_regexp ||=
|
21
|
+
/\A[\w!#$%&'*+\/=?`{|}~^-]+(?:\.[\w!#$%&'*+\/=?`{|}~^-]+)*@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}\Z/i
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :email
|
26
|
+
|
27
|
+
# Validates an email
|
28
|
+
# @param email [String]
|
29
|
+
def initialize(email)
|
30
|
+
@email = email
|
31
|
+
end
|
32
|
+
|
33
|
+
# Validates an email
|
34
|
+
# @return [Boolean]
|
35
|
+
def valid?
|
36
|
+
@valid ||= valid_form? && valid_mx_record?
|
37
|
+
end
|
38
|
+
|
39
|
+
# Validates an email
|
40
|
+
# @return [Boolean]
|
41
|
+
def valid_form?
|
42
|
+
@valid_form ||= check_form
|
43
|
+
end
|
44
|
+
|
45
|
+
# Validates an email
|
46
|
+
# @return [Boolean]
|
47
|
+
def valid_mx_record?
|
48
|
+
@validate_mx_record ||= check_mx_record
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def check_form
|
54
|
+
(email =~ (self.class.email_regexp)) == 0
|
55
|
+
end
|
56
|
+
|
57
|
+
def check_mx_record
|
58
|
+
domain = email.match(/\@(.+)/)[1]
|
59
|
+
mx = 0
|
60
|
+
Resolv::DNS.open do |dns|
|
61
|
+
mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) +
|
62
|
+
dns.getresources(domain, Resolv::DNS::Resource::IN::A)
|
63
|
+
end
|
64
|
+
mx.size > 0 ? true : false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module RichEmailValidator
|
2
|
+
# Validate input file emails and save valid ones to another output file
|
3
|
+
class FileValidator
|
4
|
+
attr_reader :input_file_path
|
5
|
+
|
6
|
+
class << self
|
7
|
+
# Validates input from file
|
8
|
+
# @param input_file_path [File]
|
9
|
+
# @param [Hash] options
|
10
|
+
# @option options [#to_int] :threads_count number of threads that will
|
11
|
+
# be fired simultaneously to calculate the result
|
12
|
+
# @return [Array]
|
13
|
+
def filter(input_file_path, options = {})
|
14
|
+
new(input_file_path, options).filter
|
15
|
+
end
|
16
|
+
|
17
|
+
# Validates input from file and write to file
|
18
|
+
# @param input_file_path [File]
|
19
|
+
# @param output_file_path [File]
|
20
|
+
# @param [Hash] options
|
21
|
+
# @option options [#to_int] :threads_count number of threads that will
|
22
|
+
# be fired simultaneously to calculate the result
|
23
|
+
def export_valid_list(input_file_path, output_file_path, options = {})
|
24
|
+
new(input_file_path, options).export_valid_list(output_file_path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Validates input from file
|
29
|
+
# @param input_file_path [File]
|
30
|
+
# @param [Hash] options
|
31
|
+
# @option options [#to_int] :threads_count number of threads that will
|
32
|
+
# be fired simultaneously to calculate the result
|
33
|
+
def initialize(input_file_path, options = {})
|
34
|
+
@input_file_path = input_file_path
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
# Validates input from file
|
39
|
+
# @return [Array]
|
40
|
+
def filter
|
41
|
+
@filtered ||= run_filter
|
42
|
+
end
|
43
|
+
|
44
|
+
# Validates input from file and writes to file
|
45
|
+
def export_valid_list(output_file_path)
|
46
|
+
File.open(output_file_path, 'w') do |file|
|
47
|
+
filter.each { |email| file.puts(email) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def run_filter
|
54
|
+
list = File.readlines(@input_file_path).map(&:chomp)
|
55
|
+
ListValidator.filter(list, @options)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'resolv'
|
2
|
+
require 'forwardable'
|
3
|
+
|
4
|
+
module RichEmailValidator
|
5
|
+
# Validates list of emails and return the valid ones
|
6
|
+
class ListValidator
|
7
|
+
class << self
|
8
|
+
# Validates list of emails
|
9
|
+
# @param list [Enumerator]
|
10
|
+
# @param [Hash] options
|
11
|
+
# @option options [#to_int] :threads_count number of threads that will
|
12
|
+
# be fired simultaneously to calculate the result
|
13
|
+
# @return [Array]
|
14
|
+
def filter(list, options = {})
|
15
|
+
new(list, options).filter
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :list, :threads_count
|
20
|
+
|
21
|
+
# Validates list of emails
|
22
|
+
# @param list [Enumerator]
|
23
|
+
# @param [Hash] options
|
24
|
+
# @option options [#to_int] :threads_count number of threads that will
|
25
|
+
# be fired simultaneously to calculate the result
|
26
|
+
def initialize(list, options = {})
|
27
|
+
@list = list
|
28
|
+
@threads_count = options.fetch(:threads_count) { 20 }
|
29
|
+
@result = []
|
30
|
+
@total_slices = (@list.size / @threads_count.to_f).ceil
|
31
|
+
end
|
32
|
+
|
33
|
+
# Validates list of emails
|
34
|
+
# @return [Array]
|
35
|
+
def filter
|
36
|
+
@filtered ||= run_filter
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_reader :result, :total_slices
|
42
|
+
|
43
|
+
def run_filter
|
44
|
+
threads = (0...total_slices).map do |slice_index|
|
45
|
+
Thread.new { filter_slice(slice_index) }
|
46
|
+
end
|
47
|
+
threads.each { |thread| thread.join }
|
48
|
+
result.select { |email| email }
|
49
|
+
end
|
50
|
+
|
51
|
+
def filter_slice(slice_index)
|
52
|
+
start_index = (threads_count * slice_index)
|
53
|
+
end_index = [start_index + threads_count, list.size].min
|
54
|
+
(start_index...end_index).each do |list_index|
|
55
|
+
email = list[list_index]
|
56
|
+
result[list_index] = email if EmailValidator.valid?(email)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative 'rich_email_validator/version'
|
2
|
+
require_relative 'rich_email_validator/email_validator'
|
3
|
+
require_relative 'rich_email_validator/list_validator'
|
4
|
+
require_relative 'rich_email_validator/file_validator'
|
5
|
+
|
6
|
+
# RichEmailValidator top level module
|
7
|
+
module RichEmailValidator
|
8
|
+
class << self
|
9
|
+
# Validates an email
|
10
|
+
# @param email [String]
|
11
|
+
# @return [Boolean]
|
12
|
+
def valid_email?(email)
|
13
|
+
EmailValidator.valid?(email)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Validates list of emails
|
17
|
+
# @param list [Enumerator]
|
18
|
+
# @param [Hash] options
|
19
|
+
# @option options [#to_int] :threads_count number of threads that will
|
20
|
+
# be fired simultaneously to calculate the result
|
21
|
+
# @return [Array]
|
22
|
+
def filter_list(list, options = {})
|
23
|
+
ListValidator.filter(list, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Validates input from file
|
27
|
+
# @param input_file_path [File]
|
28
|
+
# @param [Hash] options
|
29
|
+
# @option options [#to_int] :threads_count number of threads that will
|
30
|
+
# be fired simultaneously to calculate the result
|
31
|
+
# @return [Array]
|
32
|
+
def filter_file(input_file_path, options = {})
|
33
|
+
FileValidator.filter(input_file_path, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Validates input from file and writes to file
|
37
|
+
# @param input_file_path [File]
|
38
|
+
# @param output_file_path [File]
|
39
|
+
# @param [Hash] options
|
40
|
+
# @option options [#to_int] :threads_count number of threads that will
|
41
|
+
# be fired simultaneously to calculate the result
|
42
|
+
def export_valid_list(input_file_path, output_file_path, options = {})
|
43
|
+
FileValidator.export_valid_list(input_file_path,
|
44
|
+
output_file_path,
|
45
|
+
options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rich_email_validator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "rich_email_validator"
|
8
|
+
gem.version = RichEmailValidator::Version
|
9
|
+
gem.authors = ["Khaled alHabache"]
|
10
|
+
gem.email = ["khellls@gmail.com"]
|
11
|
+
gem.summary = %q{Set of helpers to validate emails}
|
12
|
+
gem.description = %q{Set of helpers to validate emails}
|
13
|
+
gem.homepage = "https://github.com/Startappz/rich_email_validator"
|
14
|
+
gem.license = 'LGPL-3'
|
15
|
+
gem.required_ruby_version = '>= 1.9.2'
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = Dir.glob('spec/**/*')
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
fatmazohra27688@hotmail.com
|
2
|
+
rawnd2013@gmail.com
|
3
|
+
al7.zena@hotmail.com
|
4
|
+
saron@a121@gmail.com
|
5
|
+
batoolsali@hotmail.com
|
6
|
+
faroha20032@hotmail.com
|
7
|
+
khellls@gmail.com
|
8
|
+
um.rashoodi@live.com
|
9
|
+
www kowtheralhabsi@yahoo.com
|
10
|
+
lolatop42@yahoo.com
|
11
|
+
hessa41185@hotmail.com
|
12
|
+
nevony_2005[@yahoo.com
|
13
|
+
@dghc.com
|
14
|
+
moooon_880@hotmail.com
|
15
|
+
hassan@@adnan.com.sa
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require_relative '../lib/rich_email_validator'
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
6
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
7
|
+
#
|
8
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
9
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
10
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
11
|
+
# individual file that may not need all of that loaded. Instead, make a
|
12
|
+
# separate helper file that requires this one and then use it only in the specs
|
13
|
+
# that actually need it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.run_all_when_everything_filtered = true
|
21
|
+
config.filter_run :focus
|
22
|
+
|
23
|
+
# Run specs in random order to surface order dependencies. If you find an
|
24
|
+
# order dependency and want to debug it, you can fix the order by providing
|
25
|
+
# the seed, which is printed after each run.
|
26
|
+
# --seed 1234
|
27
|
+
config.order = 'random'
|
28
|
+
config.expect_with :rspec do |c|
|
29
|
+
c.syntax = :expect
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
RSpec.configure do |config|
|
35
|
+
# The settings below are suggested to provide a good initial experience
|
36
|
+
# with RSpec, but feel free to customize to your heart's content.
|
37
|
+
=begin
|
38
|
+
# These two settings work together to allow you to limit a spec run
|
39
|
+
# to individual examples or groups you care about by tagging them with
|
40
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
41
|
+
# get run.
|
42
|
+
config.filter_run :focus
|
43
|
+
config.run_all_when_everything_filtered = true
|
44
|
+
|
45
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
46
|
+
# file, and it's useful to allow more verbose output when running an
|
47
|
+
# individual spec file.
|
48
|
+
if config.files_to_run.one?
|
49
|
+
# Use the documentation formatter for detailed output,
|
50
|
+
# unless a formatter has already been configured
|
51
|
+
# (e.g. via a command-line flag).
|
52
|
+
config.default_formatter = 'doc'
|
53
|
+
end
|
54
|
+
|
55
|
+
# Print the 10 slowest examples and example groups at the
|
56
|
+
# end of the spec run, to help surface which specs are running
|
57
|
+
# particularly slow.
|
58
|
+
config.profile_examples = 10
|
59
|
+
|
60
|
+
# Run specs in random order to surface order dependencies. If you find an
|
61
|
+
# order dependency and want to debug it, you can fix the order by providing
|
62
|
+
# the seed, which is printed after each run.
|
63
|
+
# --seed 1234
|
64
|
+
config.order = :random
|
65
|
+
|
66
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
67
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
68
|
+
# test failures related to randomization by passing the same `--seed` value
|
69
|
+
# as the one that triggered the failure.
|
70
|
+
Kernel.srand config.seed
|
71
|
+
|
72
|
+
# rspec-expectations config goes here. You can use an alternate
|
73
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
74
|
+
# assertions if you prefer.
|
75
|
+
config.expect_with :rspec do |expectations|
|
76
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
77
|
+
# For more details, see:
|
78
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
79
|
+
expectations.syntax = :expect
|
80
|
+
end
|
81
|
+
|
82
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
83
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
84
|
+
config.mock_with :rspec do |mocks|
|
85
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
86
|
+
# For more details, see:
|
87
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
88
|
+
mocks.syntax = :expect
|
89
|
+
|
90
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
91
|
+
# a real object. This is generally recommended.
|
92
|
+
mocks.verify_partial_doubles = true
|
93
|
+
end
|
94
|
+
=end
|
95
|
+
end
|
96
|
+
|
97
|
+
def fixture_path(path)
|
98
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', path))
|
99
|
+
end
|
100
|
+
|
101
|
+
def get_list(file_name)
|
102
|
+
File.readlines(fixture_path(file_name)).map(&:chomp)
|
103
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
EmailValidator = RichEmailValidator::EmailValidator
|
4
|
+
|
5
|
+
describe EmailValidator do
|
6
|
+
|
7
|
+
describe '#validate_email' do
|
8
|
+
|
9
|
+
context 'valid email' do
|
10
|
+
it 'returns true for valid email' do
|
11
|
+
email = 'khellls@gmail.com'
|
12
|
+
validator = EmailValidator.new(email)
|
13
|
+
expect(validator.valid?).to eq(true)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'non valid email' do
|
18
|
+
it 'returns false for invalid email format' do
|
19
|
+
email = '@gmail.com'
|
20
|
+
validator = EmailValidator.new(email)
|
21
|
+
expect(validator.valid?).to eq(false)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns false for invalid DNS' do
|
25
|
+
email = 'koko@gsfsfsf.com'
|
26
|
+
validator = EmailValidator.new(email)
|
27
|
+
expect(validator.valid?).to eq(false)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '::regexp' do
|
33
|
+
after(:each) { EmailValidator.email_regexp = nil }
|
34
|
+
it 'returns default regexp if not set' do
|
35
|
+
EmailValidator.email_regexp = nil
|
36
|
+
expect(EmailValidator).to receive(:default_email_regexp)
|
37
|
+
EmailValidator.email_regexp
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns regexp if set' do
|
41
|
+
EmailValidator.email_regexp = /\d/
|
42
|
+
expect(EmailValidator).not_to receive(:default_email_regexp)
|
43
|
+
EmailValidator.email_regexp
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
FileValidator = RichEmailValidator::FileValidator
|
5
|
+
|
6
|
+
describe FileValidator do
|
7
|
+
let(:invalid_fixture_path) { fixture_path('list_fixture.txt') }
|
8
|
+
let(:valid_fixture_path) { fixture_path('valid_fixture.txt') }
|
9
|
+
|
10
|
+
describe '#filter' do
|
11
|
+
let(:valid_list) { get_list('valid_fixture.txt') }
|
12
|
+
it 'returns a list of valid emails' do
|
13
|
+
output = FileValidator.new(invalid_fixture_path).filter
|
14
|
+
expect(output).to eq(valid_list)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#export_valid_list' do
|
19
|
+
let(:output_path) { fixture_path('output.tmp') }
|
20
|
+
after(:each) { FileUtils.rm_rf(output_path) }
|
21
|
+
it 'creates new file with with valid emails' do
|
22
|
+
FileValidator.new(invalid_fixture_path).export_valid_list(output_path)
|
23
|
+
output_data = File.read(output_path)
|
24
|
+
valid_fixture_data = File.read(valid_fixture_path)
|
25
|
+
expect(output_data).to eq(valid_fixture_data)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
ListValidator = RichEmailValidator::ListValidator
|
4
|
+
|
5
|
+
describe ListValidator do
|
6
|
+
|
7
|
+
describe '#filter' do
|
8
|
+
let(:list) { get_list('list_fixture.txt') }
|
9
|
+
let(:valid_list) { get_list('valid_fixture.txt') }
|
10
|
+
it 'returns a list of valid emails' do
|
11
|
+
output = ListValidator.new(list).filter
|
12
|
+
expect(output).to eq(valid_list)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe RichEmailValidator do
|
4
|
+
describe '::valid_email' do
|
5
|
+
let(:email) { 'somehting' }
|
6
|
+
let(:result) { [true, false].sample }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
allow(RichEmailValidator::EmailValidator)
|
10
|
+
.to receive(:valid?).with(email).and_return(result)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'delegates to EmailValidator' do
|
14
|
+
expect(RichEmailValidator::EmailValidator)
|
15
|
+
.to receive(:valid?).with(email).and_return(result)
|
16
|
+
RichEmailValidator.valid_email?(email)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns the same delegated call result' do
|
20
|
+
expect(RichEmailValidator.valid_email?(email)).to eq(result)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '::filter_list' do
|
25
|
+
let(:list) { %w(one, two) }
|
26
|
+
let(:options) { { o: 1, t: 2 } }
|
27
|
+
let(:result) { [true, false].sample }
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
allow(RichEmailValidator::ListValidator)
|
31
|
+
.to receive(:filter).with(list, options).and_return(result)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'delegates to EmailValidator' do
|
35
|
+
expect(RichEmailValidator::ListValidator)
|
36
|
+
.to receive(:filter).with(list, options).and_return(result)
|
37
|
+
RichEmailValidator.filter_list(list, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns the same delegated call result' do
|
41
|
+
expect(RichEmailValidator.filter_list(list, options)).to eq(result)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '::filter_file' do
|
46
|
+
let(:file_path) { 'somewhere' }
|
47
|
+
let(:options) { { o: 1, t: 2 } }
|
48
|
+
let(:result) { [true, false].sample }
|
49
|
+
|
50
|
+
before(:each) do
|
51
|
+
allow(RichEmailValidator::FileValidator)
|
52
|
+
.to receive(:filter).with(file_path, options).and_return(result)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'delegates to EmailValidator' do
|
56
|
+
expect(RichEmailValidator::FileValidator)
|
57
|
+
.to receive(:filter).with(file_path, options).and_return(result)
|
58
|
+
RichEmailValidator.filter_file(file_path, options)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns the same delegated call result' do
|
62
|
+
expect(RichEmailValidator.filter_file(file_path, options)).to eq(result)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '::export_valid_list' do
|
67
|
+
let(:file_path) { 'somewhere' }
|
68
|
+
let(:output_file_path) { 'somewhere' }
|
69
|
+
let(:options) { { o: 1, t: 2 } }
|
70
|
+
let(:result) { [true, false].sample }
|
71
|
+
|
72
|
+
before(:each) do
|
73
|
+
allow(RichEmailValidator::FileValidator)
|
74
|
+
.to receive(:export_valid_list)
|
75
|
+
.with(file_path, options)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'delegates to EmailValidator' do
|
79
|
+
expect(RichEmailValidator::FileValidator)
|
80
|
+
.to receive(:export_valid_list)
|
81
|
+
.with(file_path, output_file_path, options)
|
82
|
+
RichEmailValidator.export_valid_list(file_path, output_file_path, options)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rich_email_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Khaled alHabache
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Set of helpers to validate emails
|
14
|
+
email:
|
15
|
+
- khellls@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".travis.yml"
|
23
|
+
- ".yardopts"
|
24
|
+
- Gemfile
|
25
|
+
- Guardfile
|
26
|
+
- LICENSE.md
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- collection.rb
|
30
|
+
- lib/rich_email_validator.rb
|
31
|
+
- lib/rich_email_validator/email_validator.rb
|
32
|
+
- lib/rich_email_validator/file_validator.rb
|
33
|
+
- lib/rich_email_validator/list_validator.rb
|
34
|
+
- lib/rich_email_validator/version.rb
|
35
|
+
- rich_email_validator.gemspec
|
36
|
+
- spec/fixtures/list_fixture.txt
|
37
|
+
- spec/fixtures/valid_fixture.txt
|
38
|
+
- spec/helper.rb
|
39
|
+
- spec/rich_email_validator/email_validator_spec.rb
|
40
|
+
- spec/rich_email_validator/file_validator_spec.rb
|
41
|
+
- spec/rich_email_validator/list_validator_spec.rb
|
42
|
+
- spec/rich_email_validator/rich_email_validator_spec.rb
|
43
|
+
- spec/rich_email_validator/version_spec.rb
|
44
|
+
homepage: https://github.com/Startappz/rich_email_validator
|
45
|
+
licenses:
|
46
|
+
- LGPL-3
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.9.2
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.4.1
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Set of helpers to validate emails
|
68
|
+
test_files:
|
69
|
+
- spec/fixtures/list_fixture.txt
|
70
|
+
- spec/fixtures/valid_fixture.txt
|
71
|
+
- spec/helper.rb
|
72
|
+
- spec/rich_email_validator/email_validator_spec.rb
|
73
|
+
- spec/rich_email_validator/file_validator_spec.rb
|
74
|
+
- spec/rich_email_validator/list_validator_spec.rb
|
75
|
+
- spec/rich_email_validator/rich_email_validator_spec.rb
|
76
|
+
- spec/rich_email_validator/version_spec.rb
|
77
|
+
has_rdoc:
|