truemail 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20487757313dd1f93984687a1bb9190b5a8e7a9f619d41a5ae0b550230de63a5
4
- data.tar.gz: fc67f8aaa93041388ff21a9dfb3cbeee16581929cd8217cb2101de64ef2c5af7
3
+ metadata.gz: 0dcc1349ffc22296ae3af4dd04ce6b42501964ff1ca2072791d3e41320478d38
4
+ data.tar.gz: 26e29784585ca4ca560f574d7cf60f23e9aa9300757f11a1567881efa826b53a
5
5
  SHA512:
6
- metadata.gz: 2f4551903201185b354ec56c919fba276633da90546a8de1c4a3e57d0f4b786de6b1d7c667be61af5a46414569f9d00c98d19e0cc9e3bfa23c80c807fc38ba1e
7
- data.tar.gz: 27873755f8df550ce1b2be550b8ad6650a3b4dbbeb1f5d0ee7bade7588d2d7a0b3eb1fe539a596ab05ecf220391006f6d10bfb95dfb312ce05653b2c59bf5c7a
6
+ metadata.gz: b51544bb6b74fe12510f1e008c1a2265ad4eb9fed77a4618025bccc22571c748d99d02ca8994504576b0011ca6064469f94b77c56f1d6dd4ed896cbb1c3f1929
7
+ data.tar.gz: 260c8f3c1b2a7d0fdce382d325a510187e1c92ec7d658f2c12e04ef231186ed49a433de826fec5f2ef9c6a30076ba04abd8f29636a10cee2a25711ad0337178d
@@ -3,8 +3,8 @@
3
3
  ### New Issue Checklist
4
4
 
5
5
  - [ ] I have updated truemail to the latest version
6
- - [ ] I have read the [Contribution Guidelines](../CONTRIBUTING.md)
7
- - [ ] I have read the [documentation](../README.md)
6
+ - [ ] I have read the [Contribution Guidelines](https://github.com/rubygarage/truemail/blob/master/CONTRIBUTING.md)
7
+ - [ ] I have read the [documentation](https://github.com/rubygarage/truemail/blob/master/README.md)
8
8
  - [ ] I have searched for [existing GitHub issues](https://github.com/rubygarage/truemail/issues)
9
9
 
10
10
  ### Issue Description
@@ -40,7 +40,7 @@
40
40
  - [ ] My code follows the code style of this project
41
41
  - [ ] My change requires a change to the documentation
42
42
  - [ ] I have updated the documentation accordingly
43
- - [ ] I have read the [**CONTRIBUTING** document](../CONTRIBUTING.md)
43
+ - [ ] I have read the [**CONTRIBUTING** document](https://github.com/rubygarage/truemail/blob/master/CONTRIBUTING.md)
44
44
  - [ ] I have added tests to cover my changes
45
45
  - [ ] I have run `bundle exec rspec` from the root directory to see all new and existing tests pass
46
46
  - [ ] I have run `rubocop` and `reek` to ensure the code style is valid
data/.reek.yml CHANGED
@@ -20,6 +20,7 @@ detectors:
20
20
 
21
21
  Attribute:
22
22
  exclude:
23
+ - Truemail::Configuration#whitelist_validation
23
24
  - Truemail::Configuration#smtp_safe_check
24
25
  - Truemail::Wrapper#attempts
25
26
 
@@ -7,6 +7,9 @@ AllCops:
7
7
  Metrics/LineLength:
8
8
  Max: 140
9
9
 
10
+ Metrics/MethodLength:
11
+ Max: 15
12
+
10
13
  Metrics/CyclomaticComplexity:
11
14
  Enabled: false
12
15
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- truemail (1.1.0)
4
+ truemail (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Truemail
2
2
 
3
- [![Maintainability](https://api.codeclimate.com/v1/badges/657aa241399927dcd2e2/maintainability)](https://codeclimate.com/github/rubygarage/truemail/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/657aa241399927dcd2e2/test_coverage)](https://codeclimate.com/github/rubygarage/truemail/test_coverage) [![Gem Version](https://badge.fury.io/rb/truemail.svg)](https://badge.fury.io/rb/truemail) [![CircleCI](https://circleci.com/gh/rubygarage/truemail/tree/master.svg?style=svg)](https://circleci.com/gh/rubygarage/truemail/tree/master) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/657aa241399927dcd2e2/maintainability)](https://codeclimate.com/github/rubygarage/truemail/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/657aa241399927dcd2e2/test_coverage)](https://codeclimate.com/github/rubygarage/truemail/test_coverage) [![CircleCI](https://circleci.com/gh/rubygarage/truemail/tree/master.svg?style=svg)](https://circleci.com/gh/rubygarage/truemail/tree/master) [![Gem Version](https://badge.fury.io/rb/truemail.svg)](https://badge.fury.io/rb/truemail) [![Downloads](https://img.shields.io/gem/dt/truemail.svg?colorA=004d99&colorB=0073e6)](https://rubygems.org/gems/truemail) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)
4
4
 
5
5
  The Truemail gem helps you validate emails by regex pattern, presence of domain mx-records, and real existence of email account on a current email server. Also Truemail gem allows performing an audit of the host in which runs.
6
6
 
@@ -90,7 +90,12 @@ Truemail.configure do |config|
90
90
  # return true. Other validations will not processed even if it was defined in validation_type_for
91
91
  config.whitelisted_domains = ['somedomain1.com', 'somedomain2.com']
92
92
 
93
- # Optional parameter. Validation of email which contains whitelisted domain always will
93
+ # Optional parameter. With this option Truemail will validate email which contains whitelisted
94
+ # domain only, i.e. if domain whitelisted, validation will passed to Regex, MX or SMTP validators.
95
+ # Validation of email which not contains whitelisted domain always will return false.
96
+ config.whitelist_validation = true
97
+
98
+ # Optional parameter. Validation of email which contains blacklisted domain always will
94
99
  # return false. Other validations will not processed even if it was defined in validation_type_for
95
100
  config.blacklisted_domains = ['somedomain1.com', 'somedomain2.com']
96
101
 
@@ -116,6 +121,7 @@ Truemail.configuration
116
121
  @connection_attempts=3,
117
122
  @validation_type_by_domain={},
118
123
  @whitelisted_domains=[],
124
+ @whitelist_validation=true,
119
125
  @blacklisted_domains=[],
120
126
  @verifier_domain="somedomain.com",
121
127
  @verifier_email="verifier@example.com"
@@ -141,6 +147,7 @@ Truemail.configuration
141
147
  @connection_attempts=1,
142
148
  @validation_type_by_domain={},
143
149
  @whitelisted_domains=[],
150
+ @whitelist_validation=true,
144
151
  @blacklisted_domains=[],
145
152
  @verifier_domain="somedomain.com",
146
153
  @verifier_email="verifier@example.com",
@@ -168,7 +175,8 @@ Please note, other validations will not processed even if it was defined in ```v
168
175
 
169
176
  **Sequence of domain list check:**
170
177
  1. Whitelist check
171
- 2. Blacklist check
178
+ 2. Whitelist validation check
179
+ 3. Blacklist check
172
180
 
173
181
  Example of usage:
174
182
 
@@ -201,6 +209,53 @@ Truemail.validate('email@white-domain.com')
201
209
  @validation_type=:whitelist>
202
210
  ```
203
211
 
212
+ ##### Whitelist validation case
213
+
214
+ ```ruby
215
+ require 'truemail'
216
+
217
+ Truemail.configure do |config|
218
+ config.verifier_email = 'verifier@example.com'
219
+ config.whitelisted_domains = ['white-domain.com']
220
+ config.whitelist_validation = true
221
+ end
222
+ ```
223
+
224
+ When email domain in whitelist and ```whitelist_validation``` is sets equal to ```true``` validation type will be passed to other validators.
225
+ Validation of email which not contains whitelisted domain always will return ```false```.
226
+
227
+ ###### Email has whitelisted domain
228
+
229
+ ```ruby
230
+ Truemail.validate('email@white-domain.com', with: :regex)
231
+
232
+ #<Truemail::Validator:0x000055b8429f3490
233
+ @result=#<struct Truemail::Validator::Result
234
+ success=true,
235
+ email="email@white-domain.com",
236
+ domain=nil,
237
+ mail_servers=[],
238
+ errors={},
239
+ smtp_debug=nil>,
240
+ @validation_type=:regex>
241
+ ```
242
+
243
+ ###### Email hasn't whitelisted domain
244
+
245
+ ```ruby
246
+ Truemail.validate('email@domain.com', with: :regex)
247
+
248
+ #<Truemail::Validator:0x000055b8429f3490
249
+ @result=#<struct Truemail::Validator::Result
250
+ success=false,
251
+ email="email@domain.com",
252
+ domain=nil,
253
+ mail_servers=[],
254
+ errors={},
255
+ smtp_debug=nil>,
256
+ @validation_type=:blacklist>
257
+ ```
258
+
204
259
  ##### Blacklist case
205
260
 
206
261
  When email in blacklist, validation type will be redefined too. Validation result returns ```false```
@@ -384,6 +439,7 @@ Truemail.validate('email@example.com')
384
439
  @smtp_safe_check=false,
385
440
  @validation_type_by_domain={},
386
441
  @whitelisted_domains=[],
442
+ @whitelist_validation=false,
387
443
  @blacklisted_domains=[],
388
444
  @verifier_domain="example.com",
389
445
  @verifier_email="verifier@example.com">,
@@ -440,6 +496,7 @@ Truemail.validate('email@example.com')
440
496
  @smtp_safe_check=true,
441
497
  @validation_type_by_domain={},
442
498
  @whitelisted_domains=[],
499
+ @whitelist_validation=false,
443
500
  @blacklisted_domains=[],
444
501
  @verifier_domain="example.com",
445
502
  @verifier_email="verifier@example.com">,
@@ -480,6 +537,7 @@ Truemail.validate('email@example.com')
480
537
  @smtp_safe_check=true,
481
538
  @validation_type_by_domain={},
482
539
  @whitelisted_domains=[],
540
+ @whitelist_validation=false,
483
541
  @blacklisted_domains=[],
484
542
  @verifier_domain="example.com",
485
543
  @verifier_email="verifier@example.com">,
@@ -553,10 +611,6 @@ end
553
611
  ```
554
612
 
555
613
  ---
556
- ## ToDo
557
-
558
- Fail validations logger
559
-
560
614
  ## Contributing
561
615
 
562
616
  Bug reports and pull requests are welcome on GitHub at https://github.com/rubygarage/truemail. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. Please check the [open tikets](https://github.com/rubygarage/truemail/issues). Be shure to follow Contributor Code of Conduct below and our [Contributing Guidelines](CONTRIBUTING.md).
@@ -19,21 +19,14 @@ module Truemail
19
19
  :whitelisted_domains,
20
20
  :blacklisted_domains
21
21
 
22
- attr_accessor :smtp_safe_check
22
+ attr_accessor :whitelist_validation, :smtp_safe_check
23
23
 
24
24
  alias retry_count connection_attempts
25
25
 
26
26
  def initialize
27
- @email_pattern = Truemail::RegexConstant::REGEX_EMAIL_PATTERN
28
- @smtp_error_body_pattern = Truemail::RegexConstant::REGEX_SMTP_ERROR_BODY_PATTERN
29
- @connection_timeout = Truemail::Configuration::DEFAULT_CONNECTION_TIMEOUT
30
- @response_timeout = Truemail::Configuration::DEFAULT_RESPONSE_TIMEOUT
31
- @connection_attempts = Truemail::Configuration::DEFAULT_CONNECTION_ATTEMPTS
32
- @default_validation_type = Truemail::Configuration::DEFAULT_VALIDATION_TYPE
33
- @validation_type_by_domain = {}
34
- @whitelisted_domains = []
35
- @blacklisted_domains = []
36
- @smtp_safe_check = false
27
+ instance_initializer.each do |instace_variable, value|
28
+ instance_variable_set(:"@#{instace_variable}", value)
29
+ end
37
30
  end
38
31
 
39
32
  %i[email_pattern smtp_error_body_pattern].each do |method|
@@ -84,6 +77,22 @@ module Truemail
84
77
 
85
78
  private
86
79
 
80
+ def instance_initializer
81
+ {
82
+ email_pattern: Truemail::RegexConstant::REGEX_EMAIL_PATTERN,
83
+ smtp_error_body_pattern: Truemail::RegexConstant::REGEX_SMTP_ERROR_BODY_PATTERN,
84
+ connection_timeout: Truemail::Configuration::DEFAULT_CONNECTION_TIMEOUT,
85
+ response_timeout: Truemail::Configuration::DEFAULT_RESPONSE_TIMEOUT,
86
+ connection_attempts: Truemail::Configuration::DEFAULT_CONNECTION_ATTEMPTS,
87
+ default_validation_type: Truemail::Configuration::DEFAULT_VALIDATION_TYPE,
88
+ validation_type_by_domain: {},
89
+ whitelisted_domains: [],
90
+ whitelist_validation: false,
91
+ blacklisted_domains: [],
92
+ smtp_safe_check: false
93
+ }
94
+ end
95
+
87
96
  def raise_unless(argument_context, argument_name, condition)
88
97
  raise Truemail::ArgumentError.new(argument_context, argument_name) unless condition
89
98
  end
@@ -6,8 +6,8 @@ module Truemail
6
6
  ERROR = 'blacklisted email'
7
7
 
8
8
  def run
9
- return success(true) if whitelisted_domain?
10
- return unless blacklisted_domain?
9
+ return success(true) if whitelisted_domain? && !whitelist_validation?
10
+ return unless whitelist_validation_case? || blacklisted_domain?
11
11
  success(false)
12
12
  add_error(Truemail::Validate::DomainListMatch::ERROR)
13
13
  end
@@ -19,7 +19,15 @@ module Truemail
19
19
  end
20
20
 
21
21
  def whitelisted_domain?
22
- configuration.whitelisted_domains.include?(email_domain)
22
+ @whitelisted_domain ||= configuration.whitelisted_domains.include?(email_domain)
23
+ end
24
+
25
+ def whitelist_validation?
26
+ configuration.whitelist_validation
27
+ end
28
+
29
+ def whitelist_validation_case?
30
+ whitelist_validation? && !whitelisted_domain?
23
31
  end
24
32
 
25
33
  def blacklisted_domain?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Truemail
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truemail
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Trotsenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-18 00:00:00.000000000 Z
11
+ date: 2019-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler