truemail 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +33 -17
- data/lib/truemail/configuration.rb +6 -4
- data/lib/truemail/validate/resolver_execution_wrapper.rb +1 -1
- data/lib/truemail/validate/smtp.rb +13 -2
- data/lib/truemail/validate/smtp/request.rb +12 -2
- data/lib/truemail/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26d3676d287c46be8f5a9d6b62afe0bb8bf9258f49fd2020d08ff12ffbbb3b58
|
4
|
+
data.tar.gz: cfe874f2fc20513acfd761527fce3ef79eabdd6f020f0a377f6f6cb0027bccd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 795c62d127fdc4d173817db4c3ad3ea70e671dff16fd822777473239b4238206afd4553dbeb8c4cfff98717fef3548d252d27a095aab39e809283ac88fed9070
|
7
|
+
data.tar.gz: 3e21af180880bedaff7457cdfee47c55bcb9f79562d71eb15aeeb39813f73af880421da7e7c96b5ce569da133c9763471f864b1521ffa8bcb67d3bc9fe4d0dd6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -64,8 +64,10 @@ Truemail.configure do |config|
|
|
64
64
|
# Optional parameter. A SMTP server response timeout is equal to 2 ms by default.
|
65
65
|
config.response_timeout = 1
|
66
66
|
|
67
|
-
# Optional parameter. Total of
|
68
|
-
|
67
|
+
# Optional parameter. Total of connection attempts. It is equal to 2 by default.
|
68
|
+
# This parameter uses in mx lookup timeout error and smtp request (for cases when
|
69
|
+
# there is one mx server).
|
70
|
+
config.connection_attempts = 3
|
69
71
|
|
70
72
|
# Optional parameter. You can predefine which type of validation will be used for domains.
|
71
73
|
# Available validation types: :regex, :mx, :smtp
|
@@ -91,7 +93,7 @@ Truemail.configuration
|
|
91
93
|
@connection_timeout=1,
|
92
94
|
@email_pattern=/regex_pattern/,
|
93
95
|
@response_timeout=1,
|
94
|
-
@
|
96
|
+
@connection_attempts=3,
|
95
97
|
@validation_type_by_domain={},
|
96
98
|
@verifier_domain="somedomain.com",
|
97
99
|
@verifier_email="verifier@example.com"
|
@@ -105,7 +107,7 @@ Truemail.configuration.connection_timeout = 3
|
|
105
107
|
=> 3
|
106
108
|
Truemail.configuration.response_timeout = 4
|
107
109
|
=> 4
|
108
|
-
Truemail.configuration.
|
110
|
+
Truemail.configuration.connection_attempts = 1
|
109
111
|
=> 1
|
110
112
|
|
111
113
|
Truemail.configuration
|
@@ -113,7 +115,7 @@ Truemail.configuration
|
|
113
115
|
@connection_timeout=3,
|
114
116
|
@email_pattern=/regex_pattern/,
|
115
117
|
@response_timeout=4,
|
116
|
-
@
|
118
|
+
@connection_attempts=1,
|
117
119
|
@validation_type_by_domain={},
|
118
120
|
@verifier_domain="somedomain.com",
|
119
121
|
@verifier_email="verifier@example.com",
|
@@ -187,7 +189,13 @@ Truemail.validate('email@example.com', with: :regex)
|
|
187
189
|
|
188
190
|
#### MX validation
|
189
191
|
|
190
|
-
Validation by MX records is the second validation level. It uses Regex validation before running itself. When regex validation has completed successfully then runs itself.
|
192
|
+
Validation by MX records is the second validation level. It uses Regex validation before running itself. When regex validation has completed successfully then runs itself.
|
193
|
+
|
194
|
+
```code
|
195
|
+
[Regex validation] -> [MX validation]
|
196
|
+
```
|
197
|
+
|
198
|
+
Truemail MX validation performs strictly following the [RFC 5321](https://tools.ietf.org/html/rfc5321#section-5) standard.
|
191
199
|
|
192
200
|
Example of usage:
|
193
201
|
|
@@ -206,7 +214,7 @@ Truemail.validate('email@example.com', with: :mx)
|
|
206
214
|
success=true,
|
207
215
|
email="email@example.com",
|
208
216
|
domain="example.com",
|
209
|
-
mail_servers=["
|
217
|
+
mail_servers=["127.0.1.1", "127.0.1.2"],
|
210
218
|
errors={},
|
211
219
|
smtp_debug=nil>,
|
212
220
|
@validation_type=:mx>
|
@@ -220,6 +228,8 @@ SMTP validation is a final, third validation level. This type of validation trie
|
|
220
228
|
[Regex validation] -> [MX validation] -> [SMTP validation]
|
221
229
|
```
|
222
230
|
|
231
|
+
If total count of MX servers is equal to one, ```Truemail::Smtp``` validator will use value from ```Truemail.configuration.connection_attempts``` as connection attempts. By default it's equal 2.
|
232
|
+
|
223
233
|
By default, you don't need pass with-parameter to use it. Example of usage is specified below:
|
224
234
|
|
225
235
|
With ```smtp_safe_check = false```
|
@@ -240,7 +250,7 @@ Truemail.validate('email@example.com')
|
|
240
250
|
success=true,
|
241
251
|
email="email@example.com",
|
242
252
|
domain="example.com",
|
243
|
-
mail_servers=["
|
253
|
+
mail_servers=["127.0.1.1", "127.0.1.2"],
|
244
254
|
errors={},
|
245
255
|
smtp_debug=nil>,
|
246
256
|
@validation_type=:smtp>
|
@@ -252,7 +262,7 @@ Truemail.validate('email@example.com')
|
|
252
262
|
success=false,
|
253
263
|
email="email@example.com",
|
254
264
|
domain="example.com",
|
255
|
-
mail_servers=["
|
265
|
+
mail_servers=["127.0.1.1", "127.0.1.2"],
|
256
266
|
errors={:smtp=>"smtp error"},
|
257
267
|
smtp_debug=
|
258
268
|
[#<Truemail::Validate::Smtp::Request:0x0000000002d49b10
|
@@ -261,12 +271,14 @@ Truemail.validate('email@example.com')
|
|
261
271
|
@connection_timeout=2,
|
262
272
|
@email_pattern=/regex_pattern/,
|
263
273
|
@response_timeout=2,
|
274
|
+
@connection_attempts=2,
|
264
275
|
@smtp_safe_check=false,
|
265
276
|
@validation_type_by_domain={},
|
266
277
|
@verifier_domain="example.com",
|
267
278
|
@verifier_email="verifier@example.com">,
|
268
279
|
@email="email@example.com",
|
269
|
-
@host="
|
280
|
+
@host="127.0.1.1",
|
281
|
+
@attempts=nil,
|
270
282
|
@response=
|
271
283
|
#<struct Truemail::Validate::Smtp::Response
|
272
284
|
port_opened=true,
|
@@ -274,7 +286,7 @@ Truemail.validate('email@example.com')
|
|
274
286
|
helo=
|
275
287
|
#<Net::SMTP::Response:0x0000000002d5aca8
|
276
288
|
@status="250",
|
277
|
-
@string="250
|
289
|
+
@string="250 127.0.1.1 Hello example.com\n">,
|
278
290
|
mailfrom=
|
279
291
|
#<Net::SMTP::Response:0x0000000002d5a618
|
280
292
|
@status="250",
|
@@ -303,7 +315,7 @@ Truemail.validate('email@example.com')
|
|
303
315
|
success=true,
|
304
316
|
email="email@example.com",
|
305
317
|
domain="example.com",
|
306
|
-
mail_servers=["
|
318
|
+
mail_servers=["127.0.1.1", "127.0.1.2"],
|
307
319
|
errors={},
|
308
320
|
smtp_debug=
|
309
321
|
[#<Truemail::Validate::Smtp::Request:0x0000000002c95d40
|
@@ -312,12 +324,14 @@ Truemail.validate('email@example.com')
|
|
312
324
|
@connection_timeout=2,
|
313
325
|
@email_pattern=/regex_pattern/,
|
314
326
|
@response_timeout=2,
|
327
|
+
@connection_attempts=2,
|
315
328
|
@smtp_safe_check=true,
|
316
329
|
@validation_type_by_domain={},
|
317
330
|
@verifier_domain="example.com",
|
318
331
|
@verifier_email="verifier@example.com">,
|
319
332
|
@email="email@example.com",
|
320
|
-
@host="
|
333
|
+
@host="127.0.1.1",
|
334
|
+
@attempts=nil,
|
321
335
|
@response=
|
322
336
|
#<struct Truemail::Validate::Smtp::Response
|
323
337
|
port_opened=true,
|
@@ -325,7 +339,7 @@ Truemail.validate('email@example.com')
|
|
325
339
|
helo=
|
326
340
|
#<Net::SMTP::Response:0x0000000002c934c8
|
327
341
|
@status="250",
|
328
|
-
@string="250
|
342
|
+
@string="250 127.0.1.1\n">,
|
329
343
|
mailfrom=false,
|
330
344
|
rcptto=nil,
|
331
345
|
errors={:mailfrom=>"554 5.7.1 Client host blocked\n", :connection=>"server dropped connection after response"}>>,]>,
|
@@ -338,7 +352,7 @@ Truemail.validate('email@example.com')
|
|
338
352
|
success=false,
|
339
353
|
email="email@example.com",
|
340
354
|
domain="example.com",
|
341
|
-
mail_servers=["
|
355
|
+
mail_servers=["127.0.1.1", "127.0.1.2"],
|
342
356
|
errors={:smtp=>"smtp error"},
|
343
357
|
smtp_debug=
|
344
358
|
[#<Truemail::Validate::Smtp::Request:0x0000000002d49b10
|
@@ -347,12 +361,14 @@ Truemail.validate('email@example.com')
|
|
347
361
|
@connection_timeout=2,
|
348
362
|
@email_pattern=/regex_pattern/,
|
349
363
|
@response_timeout=2,
|
364
|
+
@connection_attempts=2,
|
350
365
|
@smtp_safe_check=true,
|
351
366
|
@validation_type_by_domain={},
|
352
367
|
@verifier_domain="example.com",
|
353
368
|
@verifier_email="verifier@example.com">,
|
354
369
|
@email="email@example.com",
|
355
|
-
@host="
|
370
|
+
@host="127.0.1.1",
|
371
|
+
@attempts=nil,
|
356
372
|
@response=
|
357
373
|
#<struct Truemail::Validate::Smtp::Response
|
358
374
|
port_opened=true,
|
@@ -360,7 +376,7 @@ Truemail.validate('email@example.com')
|
|
360
376
|
helo=
|
361
377
|
#<Net::SMTP::Response:0x0000000002d5aca8
|
362
378
|
@status="250",
|
363
|
-
@string="250
|
379
|
+
@string="250 127.0.1.1 Hello example.com\n">,
|
364
380
|
mailfrom=#<Net::SMTP::Response:0x0000000002d5a618 @status="250", @string="250 OK\n">,
|
365
381
|
rcptto=false,
|
366
382
|
errors={:rcptto=>"550 User not found\n"}>>]>,
|
@@ -4,23 +4,25 @@ module Truemail
|
|
4
4
|
class Configuration
|
5
5
|
DEFAULT_CONNECTION_TIMEOUT = 2
|
6
6
|
DEFAULT_RESPONSE_TIMEOUT = 2
|
7
|
-
|
7
|
+
DEFAULT_CONNECTION_ATTEMPTS = 2
|
8
8
|
|
9
9
|
attr_reader :email_pattern,
|
10
10
|
:verifier_email,
|
11
11
|
:verifier_domain,
|
12
12
|
:connection_timeout,
|
13
13
|
:response_timeout,
|
14
|
-
:
|
14
|
+
:connection_attempts,
|
15
15
|
:validation_type_by_domain
|
16
16
|
|
17
17
|
attr_accessor :smtp_safe_check
|
18
18
|
|
19
|
+
alias retry_count connection_attempts
|
20
|
+
|
19
21
|
def initialize
|
20
22
|
@email_pattern = Truemail::RegexConstant::REGEX_EMAIL_PATTERN
|
21
23
|
@connection_timeout = Truemail::Configuration::DEFAULT_CONNECTION_TIMEOUT
|
22
24
|
@response_timeout = Truemail::Configuration::DEFAULT_RESPONSE_TIMEOUT
|
23
|
-
@
|
25
|
+
@connection_attempts = Truemail::Configuration::DEFAULT_CONNECTION_ATTEMPTS
|
24
26
|
@validation_type_by_domain = {}
|
25
27
|
@smtp_safe_check = false
|
26
28
|
end
|
@@ -41,7 +43,7 @@ module Truemail
|
|
41
43
|
@verifier_domain = domain.downcase
|
42
44
|
end
|
43
45
|
|
44
|
-
%i[connection_timeout response_timeout
|
46
|
+
%i[connection_timeout response_timeout connection_attempts].each do |method|
|
45
47
|
define_method("#{method}=") do |argument|
|
46
48
|
raise ArgumentError.new(argument, __method__) unless argument.is_a?(Integer) && argument.positive?
|
47
49
|
instance_variable_set(:"@#{method}", argument)
|
@@ -29,13 +29,24 @@ module Truemail
|
|
29
29
|
smtp_results.last
|
30
30
|
end
|
31
31
|
|
32
|
+
def mail_servers
|
33
|
+
result.mail_servers
|
34
|
+
end
|
35
|
+
|
36
|
+
def attempts
|
37
|
+
@attempts ||=
|
38
|
+
mail_servers.one? ? { attempts: Truemail.configuration.connection_attempts } : {}
|
39
|
+
end
|
40
|
+
|
32
41
|
def rcptto_error
|
33
42
|
request.response.errors[:rcptto]
|
34
43
|
end
|
35
44
|
|
36
45
|
def establish_smtp_connection
|
37
|
-
|
38
|
-
smtp_results << Truemail::Validate::Smtp::Request.new(
|
46
|
+
mail_servers.each do |mail_server|
|
47
|
+
smtp_results << Truemail::Validate::Smtp::Request.new(
|
48
|
+
host: mail_server, email: result.email, **attempts
|
49
|
+
)
|
39
50
|
next unless request.check_port
|
40
51
|
request.run || rcptto_error ? break : next
|
41
52
|
end
|
@@ -13,17 +13,19 @@ module Truemail
|
|
13
13
|
|
14
14
|
attr_reader :host, :email, :response
|
15
15
|
|
16
|
-
def initialize(host:, email:)
|
16
|
+
def initialize(host:, email:, attempts: nil)
|
17
17
|
@host = host
|
18
18
|
@email = email
|
19
19
|
@response = Truemail::Validate::Smtp::Response.new
|
20
|
+
@attempts = attempts
|
20
21
|
end
|
21
22
|
|
22
23
|
def check_port
|
23
24
|
Timeout.timeout(configuration.connection_timeout) do
|
24
25
|
return response.port_opened = !TCPSocket.new(host, Truemail::Validate::Smtp::Request::SMTP_PORT).close
|
25
26
|
end
|
26
|
-
rescue
|
27
|
+
rescue => error
|
28
|
+
retry if attempts_exist? && error.is_a?(Timeout::Error)
|
27
29
|
response.port_opened = false
|
28
30
|
end
|
29
31
|
|
@@ -33,11 +35,19 @@ module Truemail
|
|
33
35
|
smtp_handshakes(smtp_request, response)
|
34
36
|
end
|
35
37
|
rescue => error
|
38
|
+
retry if attempts_exist?
|
36
39
|
assign_error(attribute: :connection, message: compose_from(error))
|
37
40
|
end
|
38
41
|
|
39
42
|
private
|
40
43
|
|
44
|
+
attr_reader :attempts
|
45
|
+
|
46
|
+
def attempts_exist?
|
47
|
+
return false unless attempts
|
48
|
+
(@attempts -= 1).positive?
|
49
|
+
end
|
50
|
+
|
41
51
|
def configuration
|
42
52
|
@configuration ||= Truemail.configuration.dup.freeze
|
43
53
|
end
|
data/lib/truemail/version.rb
CHANGED
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: 0.1.
|
4
|
+
version: 0.1.5
|
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-04-
|
11
|
+
date: 2019-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|