truemail 1.2.1 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bea26f52dfcf96b622b86b964aad8cca27ee059ed50dc5d2e24b55173ec7cdf7
4
- data.tar.gz: 030f628c6102f3bd4bbb7fb05480850fef362528a5d7c56955d9bd0052e7c64e
3
+ metadata.gz: 4a79768ed850e2481e1a818783ece53c2dcda4dc93e1b69c2c183fa7ba172f1e
4
+ data.tar.gz: 51f0d6958b0036733feda8b9dea2226a9dcab65536c111e0c2a503fe32d742eb
5
5
  SHA512:
6
- metadata.gz: d2f6e20972ded71818590c21b9cdc286594995d01db45d1974c653a9d4b59a8697731a2b7813bd1345e9122c0932bb381b8c32e9971e7a9922ba15b0f28b657e
7
- data.tar.gz: e6134e62d76c3faddc9a88a6ff5f99715585dd1c5a1a5f62d360971bdfd4010129511c13f0b28712af79262b7dc8e8756f28e6b5f2003a7aa6c6489fba9c1bf7
6
+ metadata.gz: 76f5d8eb6f238ef14bae1012df322ceafe53c149263be9230cce6e60c5ba729cdc7c66f8d0f7d4f780521aae2e91139b888b49239caceeccb4bc3def7970e9a0
7
+ data.tar.gz: f472b4a46800af9c56303b99dd27854326a9afb040d33af11e8e0da12a1dd860cbcbe671ef879c1ef9f8c03065d2bbc1383e38954c845a60053d3f8be7075986
data/.reek.yml CHANGED
@@ -17,6 +17,7 @@ detectors:
17
17
  TooManyInstanceVariables:
18
18
  exclude:
19
19
  - Truemail::Configuration
20
+ - Truemail::Validate::Smtp::Request
20
21
 
21
22
  Attribute:
22
23
  exclude:
@@ -40,11 +41,13 @@ detectors:
40
41
  - Truemail::Worker#success
41
42
  - Truemail#raise_unless
42
43
  - Truemail::Configuration#raise_unless
44
+ - Truemail#determine_configuration
43
45
 
44
46
  FeatureEnvy:
45
47
  exclude:
46
48
  - Truemail::Validate::Smtp#not_includes_user_not_found_errors
47
49
  - Truemail::GenerateEmailHelper#prepare_user_name
50
+ - Truemail::ConfigurationHelper#create_configuration
48
51
 
49
52
  NilCheck:
50
53
  exclude:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- truemail (1.2.1)
4
+ truemail (1.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
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
- 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.
5
+ The Truemail gem helps you validate emails via regex pattern, presence of DNS 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
 
7
7
  ## Features
8
8
 
@@ -34,17 +34,19 @@ Email validation is a tricky thing. There are a number of different ways to vali
34
34
 
35
35
  **Syntax Checking**: Checks the email addresses via regex pattern.
36
36
 
37
- **Mail Server Existence Check**: Checks the availability of the email address domain using DNS MX records.
37
+ **Mail Server Existence Check**: Checks the availability of the email address domain using DNS records.
38
38
 
39
39
  **Mail Existence Check**: Checks if the email address really exists and can receive email via SMTP connections and email-sending emulation techniques.
40
40
 
41
41
  ## Usage
42
42
 
43
- ### Configuration features
43
+ ### Configuration features
44
44
 
45
- #### Set configuration
45
+ You can use global gem configuration or custom independent configuration.
46
46
 
47
- To have an access for ```Truemail.configuration``` and gem features, you must configure it first as in the example below:
47
+ #### Setting global configuration
48
+
49
+ To have an access for ```Truemail.configuration``` and gem configuration features, you must configure it first as in the example below:
48
50
 
49
51
  ```ruby
50
52
  require 'truemail'
@@ -110,7 +112,7 @@ Truemail.configure do |config|
110
112
  end
111
113
  ```
112
114
 
113
- #### Read configuration
115
+ ##### Read global configuration
114
116
 
115
117
  After successful configuration, you can read current Truemail configuration instance anywhere in your application.
116
118
 
@@ -132,7 +134,7 @@ Truemail.configuration
132
134
  @smtp_safe_check=true>
133
135
  ```
134
136
 
135
- #### Update configuration
137
+ ##### Update global configuration
136
138
 
137
139
  ```ruby
138
140
  Truemail.configuration.connection_timeout = 3
@@ -158,7 +160,7 @@ Truemail.configuration
158
160
  @smtp_safe_check=true>
159
161
  ```
160
162
 
161
- #### Reset configuration
163
+ ##### Reset global configuration
162
164
 
163
165
  Also you can reset Truemail configuration.
164
166
 
@@ -169,6 +171,23 @@ Truemail.configuration
169
171
  => nil
170
172
  ```
171
173
 
174
+ #### Using custom independent configuration
175
+
176
+ Allows to use independent configuration for each validation/audition instance. When using this feature you do not need to have Truemail global configuration.
177
+
178
+ ```ruby
179
+ custom_configuration = Truemail::Configuration.new do |config|
180
+ config.verifier_email = 'verifier@example.com'
181
+ end
182
+
183
+ Truemail.validate('email@example.com', custom_configuration: custom_configuration)
184
+ Truemail.valid?('email@example.com', custom_configuration: custom_configuration)
185
+ Truemail.host_audit('email@example.com', custom_configuration: custom_configuration)
186
+ ```
187
+
188
+ Please note, you should have global or custom configuration for use Truemail gem.
189
+
190
+
172
191
  ### Validation features
173
192
 
174
193
  #### Whitelist/Blacklist check
@@ -210,6 +229,20 @@ Truemail.validate('email@white-domain.com')
210
229
  mail_servers=[],
211
230
  errors={},
212
231
  smtp_debug=nil>,
232
+ configuration=#<Truemail::Configuration:0x00005629f801bd28
233
+ @blacklisted_domains=["black-domain.com", "somedomain.com"],
234
+ @connection_attempts=2,
235
+ @connection_timeout=2,
236
+ @default_validation_type=:smtp,
237
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
238
+ @response_timeout=2,
239
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
240
+ @smtp_safe_check=false,
241
+ @validation_type_by_domain={"somedomain.com"=>:mx},
242
+ @verifier_domain="example.com",
243
+ @verifier_email="verifier@example.com",
244
+ @whitelist_validation=false,
245
+ @whitelisted_domains=["white-domain.com", "somedomain.com"]>,
213
246
  @validation_type=:whitelist>
214
247
  ```
215
248
 
@@ -241,6 +274,21 @@ Truemail.validate('email@white-domain.com', with: :regex)
241
274
  mail_servers=[],
242
275
  errors={},
243
276
  smtp_debug=nil>,
277
+ configuration=
278
+ #<Truemail::Configuration:0x0000563f0d2605c8
279
+ @blacklisted_domains=[],
280
+ @connection_attempts=2,
281
+ @connection_timeout=2,
282
+ @default_validation_type=:smtp,
283
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
284
+ @response_timeout=2,
285
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
286
+ @smtp_safe_check=false,
287
+ @validation_type_by_domain={},
288
+ @verifier_domain="example.com",
289
+ @verifier_email="verifier@example.com",
290
+ @whitelist_validation=true,
291
+ @whitelisted_domains=["white-domain.com"]>,
244
292
  @validation_type=:regex>
245
293
  ```
246
294
 
@@ -257,6 +305,21 @@ Truemail.validate('email@domain.com', with: :regex)
257
305
  mail_servers=[],
258
306
  errors={},
259
307
  smtp_debug=nil>,
308
+ configuration=
309
+ #<Truemail::Configuration:0x0000563f0cd82ab0
310
+ @blacklisted_domains=[],
311
+ @connection_attempts=2,
312
+ @connection_timeout=2,
313
+ @default_validation_type=:smtp,
314
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
315
+ @response_timeout=2,
316
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
317
+ @smtp_safe_check=false,
318
+ @validation_type_by_domain={},
319
+ @verifier_domain="example.com",
320
+ @verifier_email="verifier@example.com",
321
+ @whitelist_validation=true,
322
+ @whitelisted_domains=["white-domain.com"]>,
260
323
  @validation_type=:blacklist>
261
324
  ```
262
325
 
@@ -275,6 +338,21 @@ Truemail.validate('email@black-domain.com')
275
338
  mail_servers=[],
276
339
  errors={},
277
340
  smtp_debug=nil>,
341
+ configuration=
342
+ #<Truemail::Configuration:0x0000563f0d36f4f0
343
+ @blacklisted_domains=[],
344
+ @connection_attempts=2,
345
+ @connection_timeout=2,
346
+ @default_validation_type=:smtp,
347
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
348
+ @response_timeout=2,
349
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
350
+ @smtp_safe_check=false,
351
+ @validation_type_by_domain={},
352
+ @verifier_domain="example.com",
353
+ @verifier_email="verifier@example.com",
354
+ @whitelist_validation=true,
355
+ @whitelisted_domains=["white-domain.com"]>,
278
356
  @validation_type=:blacklist>
279
357
  ```
280
358
 
@@ -293,6 +371,21 @@ Truemail.validate('email@somedomain.com')
293
371
  mail_servers=[],
294
372
  errors={},
295
373
  smtp_debug=nil>,
374
+ configuration=
375
+ #<Truemail::Configuration:0x0000563f0d3f8fc0
376
+ @blacklisted_domains=[],
377
+ @connection_attempts=2,
378
+ @connection_timeout=2,
379
+ @default_validation_type=:smtp,
380
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
381
+ @response_timeout=2,
382
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
383
+ @smtp_safe_check=false,
384
+ @validation_type_by_domain={},
385
+ @verifier_domain="example.com",
386
+ @verifier_email="verifier@example.com",
387
+ @whitelist_validation=true,
388
+ @whitelisted_domains=["white-domain.com"]>,
296
389
  @validation_type=:whitelist>
297
390
  ```
298
391
 
@@ -327,6 +420,21 @@ Truemail.validate('email@example.com', with: :regex)
327
420
  mail_servers=[],
328
421
  errors={},
329
422
  smtp_debug=nil>,
423
+ configuration=
424
+ #<Truemail::Configuration:0x000055aa56a54d48
425
+ @blacklisted_domains=[],
426
+ @connection_attempts=2,
427
+ @connection_timeout=2,
428
+ @default_validation_type=:smtp,
429
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
430
+ @response_timeout=2,
431
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
432
+ @smtp_safe_check=false,
433
+ @validation_type_by_domain={},
434
+ @verifier_domain="example.com",
435
+ @verifier_email="verifier@example.com",
436
+ @whitelist_validation=false,
437
+ @whitelisted_domains=[]>,
330
438
  @validation_type=:regex>
331
439
  ```
332
440
 
@@ -351,6 +459,21 @@ Truemail.validate('email@example.com', with: :regex)
351
459
  mail_servers=[],
352
460
  errors={},
353
461
  smtp_debug=nil>,
462
+ configuration=
463
+ #<Truemail::Configuration:0x0000560e58d80830
464
+ @blacklisted_domains=[],
465
+ @connection_attempts=2,
466
+ @connection_timeout=2,
467
+ @default_validation_type=:smtp,
468
+ @email_pattern=/regex_pattern/,
469
+ @response_timeout=2,
470
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
471
+ @smtp_safe_check=false,
472
+ @validation_type_by_domain={},
473
+ @verifier_domain="example.com",
474
+ @verifier_email="verifier@example.com",
475
+ @whitelist_validation=false,
476
+ @whitelisted_domains=[]>,
354
477
  @validation_type=:regex>
355
478
  ```
356
479
 
@@ -384,6 +507,21 @@ Truemail.validate('email@example.com', with: :mx)
384
507
  mail_servers=["127.0.1.1", "127.0.1.2"],
385
508
  errors={},
386
509
  smtp_debug=nil>,
510
+ configuration=
511
+ #<Truemail::Configuration:0x0000559b6e44af70
512
+ @blacklisted_domains=[],
513
+ @connection_attempts=2,
514
+ @connection_timeout=2,
515
+ @default_validation_type=:smtp,
516
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
517
+ @response_timeout=2,
518
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
519
+ @smtp_safe_check=false,
520
+ @validation_type_by_domain={},
521
+ @verifier_domain="example.com",
522
+ @verifier_email="verifier@example.com",
523
+ @whitelist_validation=false,
524
+ @whitelisted_domains=[]>,
387
525
  @validation_type=:mx>
388
526
  ```
389
527
 
@@ -420,6 +558,21 @@ Truemail.validate('email@example.com')
420
558
  mail_servers=["127.0.1.1", "127.0.1.2"],
421
559
  errors={},
422
560
  smtp_debug=nil>,
561
+ configuration=
562
+ #<Truemail::Configuration:0x00005615e87b9298
563
+ @blacklisted_domains=[],
564
+ @connection_attempts=2,
565
+ @connection_timeout=2,
566
+ @default_validation_type=:smtp,
567
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
568
+ @response_timeout=2,
569
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
570
+ @smtp_safe_check=false,
571
+ @validation_type_by_domain={},
572
+ @verifier_domain="example.com",
573
+ @verifier_email="verifier@example.com",
574
+ @whitelist_validation=false,
575
+ @whitelisted_domains=[]>,
423
576
  @validation_type=:smtp>
424
577
 
425
578
  # SMTP validation failed
@@ -434,17 +587,9 @@ Truemail.validate('email@example.com')
434
587
  smtp_debug=
435
588
  [#<Truemail::Validate::Smtp::Request:0x0000000002d49b10
436
589
  @configuration=
437
- #<Truemail::Configuration:0x0000000002d49930
590
+ #<Truemail::Validate::Smtp::Request::Configuration:0x00005615e8d21848
438
591
  @connection_timeout=2,
439
- @email_pattern=/regex_pattern/,
440
- @smtp_error_body_pattern=/regex_pattern/,
441
592
  @response_timeout=2,
442
- @connection_attempts=2,
443
- @smtp_safe_check=false,
444
- @validation_type_by_domain={},
445
- @whitelisted_domains=[],
446
- @whitelist_validation=false,
447
- @blacklisted_domains=[],
448
593
  @verifier_domain="example.com",
449
594
  @verifier_email="verifier@example.com">,
450
595
  @email="email@example.com",
@@ -464,6 +609,21 @@ Truemail.validate('email@example.com')
464
609
  @string="250 OK\n">,
465
610
  rcptto=false,
466
611
  errors={:rcptto=>"550 User not found\n"}>>]>,
612
+ configuration=
613
+ #<Truemail::Configuration:0x00005615e87b9298
614
+ @blacklisted_domains=[],
615
+ @connection_attempts=2,
616
+ @connection_timeout=2,
617
+ @default_validation_type=:smtp,
618
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
619
+ @response_timeout=2,
620
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
621
+ @smtp_safe_check=false,
622
+ @validation_type_by_domain={},
623
+ @verifier_domain="example.com",
624
+ @verifier_email="verifier@example.com",
625
+ @whitelist_validation=false,
626
+ @whitelisted_domains=[]>,
467
627
  @validation_type=:smtp>
468
628
  ```
469
629
 
@@ -491,33 +651,40 @@ Truemail.validate('email@example.com')
491
651
  smtp_debug=
492
652
  [#<Truemail::Validate::Smtp::Request:0x0000000002c95d40
493
653
  @configuration=
494
- #<Truemail::Configuration:0x0000000002c95b38
495
- @connection_timeout=2,
496
- @email_pattern=/regex_pattern/,
497
- @smtp_error_body_pattern=/regex_pattern/,
498
- @response_timeout=2,
499
- @connection_attempts=2,
500
- @smtp_safe_check=true,
501
- @validation_type_by_domain={},
502
- @whitelisted_domains=[],
503
- @whitelist_validation=false,
504
- @blacklisted_domains=[],
505
- @verifier_domain="example.com",
506
- @verifier_email="verifier@example.com">,
507
- @email="email@example.com",
508
- @host="127.0.1.1",
509
- @attempts=nil,
510
- @response=
511
- #<struct Truemail::Validate::Smtp::Response
512
- port_opened=true,
513
- connection=false,
514
- helo=
515
- #<Net::SMTP::Response:0x0000000002c934c8
516
- @status="250",
517
- @string="250 127.0.1.1\n">,
518
- mailfrom=false,
519
- rcptto=nil,
520
- errors={:mailfrom=>"554 5.7.1 Client host blocked\n", :connection=>"server dropped connection after response"}>>,]>,
654
+ #<Truemail::Validate::Smtp::Request::Configuration:0x00005615e8d21848
655
+ @connection_timeout=2,
656
+ @response_timeout=2,
657
+ @verifier_domain="example.com",
658
+ @verifier_email="verifier@example.com">,
659
+ @email="email@example.com",
660
+ @host="127.0.1.1",
661
+ @attempts=nil,
662
+ @response=
663
+ #<struct Truemail::Validate::Smtp::Response
664
+ port_opened=true,
665
+ connection=false,
666
+ helo=
667
+ #<Net::SMTP::Response:0x0000000002c934c8
668
+ @status="250",
669
+ @string="250 127.0.1.1\n">,
670
+ mailfrom=false,
671
+ rcptto=nil,
672
+ errors={:mailfrom=>"554 5.7.1 Client host blocked\n", :connection=>"server dropped connection after response"}>>,]>,
673
+ configuration=
674
+ #<Truemail::Configuration:0x00005615e87b9298
675
+ @blacklisted_domains=[],
676
+ @connection_attempts=2,
677
+ @connection_timeout=2,
678
+ @default_validation_type=:smtp,
679
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
680
+ @response_timeout=2,
681
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
682
+ @smtp_safe_check=false,
683
+ @validation_type_by_domain={},
684
+ @verifier_domain="example.com",
685
+ @verifier_email="verifier@example.com",
686
+ @whitelist_validation=false,
687
+ @whitelisted_domains=[]>,
521
688
  @validation_type=:smtp>
522
689
 
523
690
  # SMTP validation failed
@@ -532,17 +699,9 @@ Truemail.validate('email@example.com')
532
699
  smtp_debug=
533
700
  [#<Truemail::Validate::Smtp::Request:0x0000000002d49b10
534
701
  @configuration=
535
- #<Truemail::Configuration:0x0000000002d49930
702
+ #<Truemail::Validate::Smtp::Request::Configuration:0x00005615e8d21848
536
703
  @connection_timeout=2,
537
- @email_pattern=/regex_pattern/,
538
- @smtp_error_body_pattern=/regex_pattern/,
539
704
  @response_timeout=2,
540
- @connection_attempts=2,
541
- @smtp_safe_check=true,
542
- @validation_type_by_domain={},
543
- @whitelisted_domains=[],
544
- @whitelist_validation=false,
545
- @blacklisted_domains=[],
546
705
  @verifier_domain="example.com",
547
706
  @verifier_email="verifier@example.com">,
548
707
  @email="email@example.com",
@@ -559,6 +718,21 @@ Truemail.validate('email@example.com')
559
718
  mailfrom=#<Net::SMTP::Response:0x0000000002d5a618 @status="250", @string="250 OK\n">,
560
719
  rcptto=false,
561
720
  errors={:rcptto=>"550 User not found\n"}>>]>,
721
+ configuration=
722
+ #<Truemail::Configuration:0x00005615e87b9298
723
+ @blacklisted_domains=[],
724
+ @connection_attempts=2,
725
+ @connection_timeout=2,
726
+ @default_validation_type=:smtp,
727
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
728
+ @response_timeout=2,
729
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
730
+ @smtp_safe_check=false,
731
+ @validation_type_by_domain={},
732
+ @verifier_domain="example.com",
733
+ @verifier_email="verifier@example.com",
734
+ @whitelist_validation=false,
735
+ @whitelisted_domains=[]>,
562
736
  @validation_type=:smtp>
563
737
  ```
564
738
 
@@ -576,14 +750,44 @@ Truemail.host_audit
576
750
  => #<Truemail::Auditor:0x00005580df358828
577
751
  @result=
578
752
  #<struct Truemail::Auditor::Result
579
- warnings={}>>
753
+ warnings={}>,
754
+ configuration=
755
+ #<Truemail::Configuration:0x00005615e86327a8
756
+ @blacklisted_domains=[],
757
+ @connection_attempts=2,
758
+ @connection_timeout=2,
759
+ @default_validation_type=:smtp,
760
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
761
+ @response_timeout=2,
762
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
763
+ @smtp_safe_check=false,
764
+ @validation_type_by_domain={},
765
+ @verifier_domain="example.com",
766
+ @verifier_email="verifier@example.com",
767
+ @whitelist_validation=false,
768
+ @whitelisted_domains=[]>
580
769
 
581
770
  # Has PTR warning
582
771
  => #<Truemail::Auditor:0x00005580df358828
583
772
  @result=
584
773
  #<struct Truemail::Auditor::Result
585
774
  warnings=
586
- {:ptr=>"ptr record does not reference to current verifier domain"}>>
775
+ {:ptr=>"ptr record does not reference to current verifier domain"}>,
776
+ configuration=
777
+ #<Truemail::Configuration:0x00005615e86327a8
778
+ @blacklisted_domains=[],
779
+ @connection_attempts=2,
780
+ @connection_timeout=2,
781
+ @default_validation_type=:smtp,
782
+ @email_pattern=/(?=\A.{6,255}\z)(\A([a-zA-Z0-9]+[\w|\-|\.|\+]*)@((?i-mx:[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}))\z)/,
783
+ @response_timeout=2,
784
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
785
+ @smtp_safe_check=false,
786
+ @validation_type_by_domain={},
787
+ @verifier_domain="example.com",
788
+ @verifier_email="verifier@example.com",
789
+ @whitelist_validation=false,
790
+ @whitelisted_domains=[]>
587
791
  ```
588
792
 
589
793
  ### Truemail helpers
@@ -9,8 +9,12 @@ module Truemail
9
9
  result.warnings[self.class.name.split('::').last.downcase.to_sym] = message
10
10
  end
11
11
 
12
+ def configuration
13
+ result.configuration
14
+ end
15
+
12
16
  def verifier_domain
13
- Truemail.configuration.verifier_domain
17
+ configuration.verifier_domain
14
18
  end
15
19
  end
16
20
  end
@@ -27,7 +27,9 @@ module Truemail
27
27
  end
28
28
 
29
29
  def current_host_address
30
- @current_host_address ||= Truemail::Wrapper.call { IPAddr.new(detect_ip_via_ipify) }
30
+ @current_host_address ||= Truemail::Wrapper.call(configuration: configuration) do
31
+ IPAddr.new(detect_ip_via_ipify)
32
+ end
31
33
  end
32
34
 
33
35
  def current_host_reverse_lookup
@@ -35,7 +37,7 @@ module Truemail
35
37
  end
36
38
 
37
39
  def ptr_records
38
- @ptr_records ||= Truemail::Wrapper.call do
40
+ @ptr_records ||= Truemail::Wrapper.call(configuration: configuration) do
39
41
  Resolv::DNS.new.getresources(
40
42
  current_host_reverse_lookup, Resolv::DNS::Resource::IN::PTR
41
43
  ).map { |ptr_record| ptr_record.name.to_s }
@@ -47,11 +49,13 @@ module Truemail
47
49
  end
48
50
 
49
51
  def a_record
50
- Truemail::Wrapper.call { Resolv::DNS.new.getaddress(verifier_domain).to_s }
52
+ Truemail::Wrapper.call(configuration: configuration) do
53
+ Resolv::DNS.new.getaddress(verifier_domain).to_s
54
+ end
51
55
  end
52
56
 
53
57
  def verifier_domain_refer_to_current_host_address?
54
- a_record == current_host_address.to_s
58
+ a_record.eql?(current_host_address.to_s)
55
59
  end
56
60
  end
57
61
  end
@@ -2,18 +2,16 @@
2
2
 
3
3
  module Truemail
4
4
  class Auditor
5
- Result = Struct.new(:warnings, keyword_init: true) do
5
+ Result = Struct.new(:warnings, :configuration, keyword_init: true) do
6
6
  def initialize(warnings: {}, **args)
7
7
  super
8
8
  end
9
9
  end
10
10
 
11
- def self.run
12
- new.run
13
- end
11
+ attr_reader :result
14
12
 
15
- def result
16
- @result ||= Truemail::Auditor::Result.new
13
+ def initialize(configuration:)
14
+ @result = Truemail::Auditor::Result.new(configuration: configuration)
17
15
  end
18
16
 
19
17
  def run
@@ -23,10 +23,11 @@ module Truemail
23
23
 
24
24
  alias retry_count connection_attempts
25
25
 
26
- def initialize
26
+ def initialize(&block)
27
27
  instance_initializer.each do |instace_variable, value|
28
28
  instance_variable_set(:"@#{instace_variable}", value)
29
29
  end
30
+ tap(&block) if block_given?
30
31
  end
31
32
 
32
33
  %i[email_pattern smtp_error_body_pattern].each do |method|
@@ -14,7 +14,7 @@ module Truemail
14
14
  end
15
15
 
16
16
  def configuration
17
- Truemail.configuration
17
+ result.configuration
18
18
  end
19
19
  end
20
20
  end
@@ -24,7 +24,7 @@ module Truemail
24
24
 
25
25
  def mx_lookup
26
26
  host_extractor_methods.any? do |method|
27
- Truemail::Wrapper.call { send(method) }
27
+ Truemail::Wrapper.call(configuration: configuration) { send(method) }
28
28
  end
29
29
  end
30
30
 
@@ -11,12 +11,13 @@ module Truemail
11
11
  RESPONSE_TIMEOUT_ERROR = 'server response timeout'
12
12
  CONNECTION_DROPPED = 'server dropped connection after response'
13
13
 
14
- attr_reader :host, :email, :response
14
+ attr_reader :configuration, :host, :email, :response
15
15
 
16
- def initialize(host:, email:, attempts: nil)
16
+ def initialize(configuration:, host:, email:, attempts: nil)
17
+ @configuration = Truemail::Validate::Smtp::Request::Configuration.new(configuration)
18
+ @response = Truemail::Validate::Smtp::Response.new
17
19
  @host = host
18
20
  @email = email
19
- @response = Truemail::Validate::Smtp::Response.new
20
21
  @attempts = attempts
21
22
  end
22
23
 
@@ -41,6 +42,17 @@ module Truemail
41
42
 
42
43
  private
43
44
 
45
+ class Configuration
46
+ REQUEST_PARAMS = %i[connection_timeout response_timeout verifier_domain verifier_email].freeze
47
+
48
+ def initialize(configuration)
49
+ REQUEST_PARAMS.each do |attribute|
50
+ self.class.class_eval { attr_reader attribute }
51
+ instance_variable_set(:"@#{attribute}", configuration.public_send(attribute))
52
+ end
53
+ end
54
+ end
55
+
44
56
  attr_reader :attempts
45
57
 
46
58
  def attempts_exist?
@@ -48,10 +60,6 @@ module Truemail
48
60
  (@attempts -= 1).positive?
49
61
  end
50
62
 
51
- def configuration
52
- @configuration ||= Truemail.configuration.dup.freeze
53
- end
54
-
55
63
  def session
56
64
  Net::SMTP.new(host, Truemail::Validate::Smtp::Request::SMTP_PORT).tap do |settings|
57
65
  settings.open_timeout = configuration.connection_timeout
@@ -40,7 +40,7 @@ module Truemail
40
40
  def establish_smtp_connection
41
41
  mail_servers.each do |mail_server|
42
42
  smtp_results << Truemail::Validate::Smtp::Request.new(
43
- host: mail_server, email: result.email, **attempts
43
+ configuration: configuration, host: mail_server, email: result.email, **attempts
44
44
  )
45
45
  next unless request.check_port
46
46
  request.run || rcptto_error ? break : next
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Truemail
4
4
  class Validator
5
- RESULT_ATTRS = %i[success email domain mail_servers errors smtp_debug].freeze
5
+ RESULT_ATTRS = %i[success email domain mail_servers errors smtp_debug configuration].freeze
6
6
  VALIDATION_TYPES = %i[regex mx smtp].freeze
7
7
 
8
8
  Result = Struct.new(*RESULT_ATTRS, keyword_init: true) do
@@ -14,10 +14,11 @@ module Truemail
14
14
 
15
15
  attr_reader :validation_type, :result
16
16
 
17
- def initialize(email, with: Truemail.configuration.default_validation_type)
17
+ def initialize(email, with: nil, configuration:)
18
+ with ||= configuration.default_validation_type
18
19
  raise Truemail::ArgumentError.new(with, :argument) unless Truemail::Validator::VALIDATION_TYPES.include?(with)
20
+ @result = Truemail::Validator::Result.new(email: email, configuration: configuration)
19
21
  @validation_type = select_validation_type(email, with)
20
- @result = Truemail::Validator::Result.new(email: email)
21
22
  end
22
23
 
23
24
  def run
@@ -38,7 +39,7 @@ module Truemail
38
39
 
39
40
  def select_validation_type(email, current_validation_type)
40
41
  domain = email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3]
41
- Truemail.configuration.validation_type_by_domain[domain] || current_validation_type
42
+ result.configuration.validation_type_by_domain[domain] || current_validation_type
42
43
  end
43
44
  end
44
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Truemail
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -2,18 +2,20 @@
2
2
 
3
3
  module Truemail
4
4
  class Wrapper
5
+ attr_reader :timeout
5
6
  attr_accessor :attempts
6
7
 
7
- def self.call(&block)
8
- new.call(&block)
8
+ def self.call(configuration:, &block)
9
+ new(configuration).call(&block)
9
10
  end
10
11
 
11
- def initialize
12
- @attempts = Truemail.configuration.connection_attempts
12
+ def initialize(configuration)
13
+ @attempts = configuration.connection_attempts
14
+ @timeout = configuration.connection_timeout
13
15
  end
14
16
 
15
17
  def call(&block)
16
- Timeout.timeout(Truemail.configuration.connection_timeout, &block)
18
+ Timeout.timeout(timeout, &block)
17
19
  rescue Resolv::ResolvError, IPAddr::InvalidAddressError
18
20
  false
19
21
  rescue Timeout::Error
data/lib/truemail.rb CHANGED
@@ -4,7 +4,7 @@ require 'truemail/core'
4
4
 
5
5
  module Truemail
6
6
  INCOMPLETE_CONFIG = 'verifier_email is required parameter'
7
- NOT_CONFIGURED = 'use Truemail.configure before'
7
+ NOT_CONFIGURED = 'use Truemail.configure before or pass custom configuration'
8
8
 
9
9
  class << self
10
10
  def configuration
@@ -12,7 +12,7 @@ module Truemail
12
12
  return unless block_given?
13
13
  configuration = Truemail::Configuration.new
14
14
  yield(configuration)
15
- raise_unless(configuration.complete?, INCOMPLETE_CONFIG)
15
+ raise_unless(configuration.complete?, Truemail::INCOMPLETE_CONFIG)
16
16
  configuration
17
17
  end
18
18
  end
@@ -25,24 +25,29 @@ module Truemail
25
25
  @configuration = nil
26
26
  end
27
27
 
28
- def validate(email, **options)
29
- raise_unless(configuration, NOT_CONFIGURED)
30
- Truemail::Validator.new(email, **options).run
28
+ def validate(email, custom_configuration: nil, **options)
29
+ Truemail::Validator.new(email, configuration: determine_configuration(custom_configuration), **options).run
31
30
  end
32
31
 
33
32
  def valid?(email, **options)
34
33
  validate(email, **options).result.valid?
35
34
  end
36
35
 
37
- def host_audit
38
- raise_unless(configuration, NOT_CONFIGURED)
39
- Truemail::Auditor.run
36
+ def host_audit(custom_configuration: nil)
37
+ Truemail::Auditor.new(configuration: determine_configuration(custom_configuration)).run
40
38
  end
41
39
 
42
40
  private
43
41
 
44
42
  def raise_unless(condition, message)
45
- raise ConfigurationError, message unless condition
43
+ raise Truemail::ConfigurationError, message unless condition
44
+ end
45
+
46
+ def determine_configuration(custom_configuration)
47
+ current_configuration = custom_configuration || configuration
48
+ raise_unless(current_configuration, Truemail::NOT_CONFIGURED)
49
+ raise_unless(current_configuration.complete?, Truemail::INCOMPLETE_CONFIG)
50
+ current_configuration.dup.freeze
46
51
  end
47
52
  end
48
53
  end
data/truemail.gemspec CHANGED
@@ -11,7 +11,8 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ['admin@bestweb.com.ua']
12
12
 
13
13
  spec.summary = %(truemail)
14
- spec.description = %(Configurable plain ruby email validator. Validate email by regexp, mx records and real email existence)
14
+ spec.description = %(Configurable plain Ruby email validator. Verify email via Regex, DNS and SMTP. Be sure that email address exists)
15
+
15
16
  spec.homepage = 'https://github.com/rubygarage/truemail'
16
17
  spec.license = 'MIT'
17
18
 
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.2.1
4
+ version: 1.3.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-27 00:00:00.000000000 Z
11
+ date: 2019-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -164,8 +164,8 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- description: Configurable plain ruby email validator. Validate email by regexp, mx
168
- records and real email existence
167
+ description: Configurable plain Ruby email validator. Verify email via Regex, DNS
168
+ and SMTP. Be sure that email address exists
169
169
  email:
170
170
  - admin@bestweb.com.ua
171
171
  executables: []