truemail 2.3.3 → 2.4.3
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 +4 -4
- data/{circle.yml → .circleci/config.yml} +37 -19
- data/.codeclimate.yml +1 -1
- data/.reek.yml +9 -8
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +65 -0
- data/Gemfile.lock +37 -36
- data/README.md +111 -26
- data/lib/truemail/configuration.rb +19 -24
- data/lib/truemail/core.rb +5 -2
- data/lib/truemail/log/serializer/base.rb +17 -8
- data/lib/truemail/log/serializer/validator_text.rb +3 -3
- data/lib/truemail/validate/mx_blacklist.rb +26 -0
- data/lib/truemail/validate/smtp.rb +1 -1
- data/lib/truemail/validator.rb +6 -2
- data/lib/truemail/version.rb +1 -1
- data/truemail.gemspec +11 -11
- metadata +36 -42
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
[](LICENSE.txt)
|
11
11
|
[](CODE_OF_CONDUCT.md)
|
12
12
|
|
13
|
-
Configurable framework agnostic plain Ruby email validator. Verify email via Regex, DNS and
|
13
|
+
Configurable framework agnostic plain Ruby email validator. Verify email via Regex, DNS, SMTP and even more. Be sure that email address valid and exists.
|
14
14
|
|
15
15
|
> Actual and maintainable documentation :books: for developers is living [here](https://truemail-rb.org/truemail-gem).
|
16
16
|
|
@@ -39,6 +39,7 @@ Configurable framework agnostic plain Ruby email validator. Verify email via Reg
|
|
39
39
|
- [DNS (MX) validation](#mx-validation)
|
40
40
|
- [RFC MX lookup flow](#rfc-mx-lookup-flow)
|
41
41
|
- [Not RFC MX lookup flow](#not-rfc-mx-lookup-flow)
|
42
|
+
- [MX blacklist validation](#mx-blacklist-validation)
|
42
43
|
- [SMTP validation](#smtp-validation)
|
43
44
|
- [SMTP fail fast enabled](#smtp-fail-fast-enabled)
|
44
45
|
- [SMTP safe check disabled](#smtp-safe-check-disabled)
|
@@ -80,10 +81,11 @@ Also Truemail gem allows performing an audit of the host in which runs.
|
|
80
81
|
## Features
|
81
82
|
|
82
83
|
- Configurable validator, validate only what you need
|
83
|
-
-
|
84
|
+
- Only one runtime dependency
|
84
85
|
- Supporting of internationalized emails ([EAI](https://en.wikipedia.org/wiki/Email_address#Internationalization))
|
85
86
|
- Whitelist/blacklist validation layers
|
86
87
|
- Ability to configure different MX/SMTP validation flows
|
88
|
+
- Ability to configure [DEA](https://en.wikipedia.org/wiki/Disposable_email_address) validation flow
|
87
89
|
- Simple SMTP debugger
|
88
90
|
- Event logger
|
89
91
|
- Host auditor tools (helps to detect common host problems interfering to proper email verification)
|
@@ -132,6 +134,7 @@ You can use global gem configuration or custom independent configuration. Availa
|
|
132
134
|
- whitelisted domains
|
133
135
|
- whitelist validation
|
134
136
|
- blacklisted domains
|
137
|
+
- blacklisted mx ip-addresses
|
135
138
|
- custom DNS gateway(s)
|
136
139
|
- RFC MX lookup flow
|
137
140
|
- SMTP fail fast
|
@@ -175,11 +178,12 @@ Truemail.configure do |config|
|
|
175
178
|
|
176
179
|
# Optional parameter. You can predefine default validation type for
|
177
180
|
# Truemail.validate('email@email.com') call without with-parameter
|
178
|
-
# Available validation types: :regex, :mx, :smtp
|
181
|
+
# Available validation types: :regex, :mx, :mx_blacklist, :smtp
|
179
182
|
config.default_validation_type = :mx
|
180
183
|
|
181
184
|
# Optional parameter. You can predefine which type of validation will be used for domains.
|
182
|
-
# Also you can skip validation by domain.
|
185
|
+
# Also you can skip validation by domain.
|
186
|
+
# Available validation types: :regex, :mx, :mx_blacklist, :smtp
|
183
187
|
# This configuration will be used over current or default validation type parameter
|
184
188
|
# All of validations for 'somedomain.com' will be processed with regex validation only.
|
185
189
|
# And all of validations for 'otherdomain.com' will be processed with mx validation only.
|
@@ -189,7 +193,7 @@ Truemail.configure do |config|
|
|
189
193
|
# Optional parameter. Validation of email which contains whitelisted domain always will
|
190
194
|
# return true. Other validations will not processed even if it was defined in validation_type_for
|
191
195
|
# It is equal to empty array by default.
|
192
|
-
config.whitelisted_domains = [
|
196
|
+
config.whitelisted_domains = %w[somedomain1.com somedomain2.com]
|
193
197
|
|
194
198
|
# Optional parameter. With this option Truemail will validate email which contains whitelisted
|
195
199
|
# domain only, i.e. if domain whitelisted, validation will passed to Regex, MX or SMTP validators.
|
@@ -200,13 +204,18 @@ Truemail.configure do |config|
|
|
200
204
|
# Optional parameter. Validation of email which contains blacklisted domain always will
|
201
205
|
# return false. Other validations will not processed even if it was defined in validation_type_for
|
202
206
|
# It is equal to empty array by default.
|
203
|
-
config.blacklisted_domains = [
|
207
|
+
config.blacklisted_domains = %w[somedomain3.com somedomain4.com]
|
208
|
+
|
209
|
+
# Optional parameter. With this option Truemail will filter out unwanted mx servers via
|
210
|
+
# predefined list of ip addresses. It can be used as a part of DEA (disposable email
|
211
|
+
# address) validations. It is equal to empty array by default.
|
212
|
+
config.blacklisted_mx_ip_addresses = %w[1.1.1.1 2.2.2.2]
|
204
213
|
|
205
214
|
# Optional parameter. This option will provide to use custom DNS gateway when Truemail
|
206
|
-
# interacts with DNS. If you won't specify
|
207
|
-
# DNS TCP/UDP port 53. By default Truemail
|
208
|
-
# and this option is equal to empty array.
|
209
|
-
config.dns = [
|
215
|
+
# interacts with DNS. Valid port numbers are in the range 1-65535. If you won't specify
|
216
|
+
# nameserver's ports Truemail will use default DNS TCP/UDP port 53. By default Truemail
|
217
|
+
# uses DNS gateway from system settings and this option is equal to empty array.
|
218
|
+
config.dns = %w[10.0.0.1 10.0.0.2:54]
|
210
219
|
|
211
220
|
# Optional parameter. This option will provide to use not RFC MX lookup flow.
|
212
221
|
# It means that MX and Null MX records will be cheked on the DNS validation layer only.
|
@@ -214,7 +223,7 @@ Truemail.configure do |config|
|
|
214
223
|
config.not_rfc_mx_lookup_flow = true
|
215
224
|
|
216
225
|
# Optional parameter. This option will provide to use smtp fail fast behaviour. When
|
217
|
-
# smtp_fail_fast = true it means that
|
226
|
+
# smtp_fail_fast = true it means that Truemail ends smtp validation session after first
|
218
227
|
# attempt on the first mx server in any fail cases (network connection/timeout error,
|
219
228
|
# smtp validation error). This feature helps to reduce total time of SMTP validation
|
220
229
|
# session up to 1 second. By default this option is disabled.
|
@@ -245,11 +254,13 @@ Truemail.configuration
|
|
245
254
|
@smtp_error_body_pattern=/regex_pattern/,
|
246
255
|
@response_timeout=1,
|
247
256
|
@connection_attempts=3,
|
248
|
-
@
|
249
|
-
@
|
257
|
+
@default_validation_type=:mx,
|
258
|
+
@validation_type_by_domain={"somedomain.com" => :regex, "otherdomain.com" => :mx},
|
259
|
+
@whitelisted_domains=["somedomain1.com", "somedomain2.com"],
|
250
260
|
@whitelist_validation=true,
|
251
|
-
@blacklisted_domains=[],
|
252
|
-
@
|
261
|
+
@blacklisted_domains=["somedomain3.com", "somedomain4.com"],
|
262
|
+
@blacklisted_mx_ip_addresses=["1.1.1.1", "2.2.2.2"],
|
263
|
+
@dns=["10.0.0.1", "10.0.0.2:54"],
|
253
264
|
@verifier_domain="somedomain.com",
|
254
265
|
@verifier_email="verifier@example.com",
|
255
266
|
@not_rfc_mx_lookup_flow=true,
|
@@ -276,11 +287,13 @@ Truemail.configuration
|
|
276
287
|
@smtp_error_body_pattern=/regex_pattern/,
|
277
288
|
@response_timeout=4,
|
278
289
|
@connection_attempts=1,
|
279
|
-
@
|
280
|
-
@
|
290
|
+
@default_validation_type=:mx,
|
291
|
+
@validation_type_by_domain={"somedomain.com" => :regex, "otherdomain.com" => :mx},
|
292
|
+
@whitelisted_domains=["somedomain1.com", "somedomain2.com"],
|
281
293
|
@whitelist_validation=true,
|
282
|
-
@blacklisted_domains=[],
|
283
|
-
@
|
294
|
+
@blacklisted_domains=["somedomain3.com", "somedomain4.com"],
|
295
|
+
@blacklisted_mx_ip_addresses=["1.1.1.1", "2.2.2.2"],
|
296
|
+
@dns=["10.0.0.1", "10.0.0.2:54"],
|
284
297
|
@verifier_domain="somedomain.com",
|
285
298
|
@verifier_email="verifier@example.com",
|
286
299
|
@not_rfc_mx_lookup_flow=true,
|
@@ -338,8 +351,8 @@ require 'truemail'
|
|
338
351
|
|
339
352
|
Truemail.configure do |config|
|
340
353
|
config.verifier_email = 'verifier@example.com'
|
341
|
-
config.whitelisted_domains = [
|
342
|
-
config.blacklisted_domains = [
|
354
|
+
config.whitelisted_domains = %w[white-domain.com somedomain.com]
|
355
|
+
config.blacklisted_domains = %w[black-domain.com somedomain.com]
|
343
356
|
config.validation_type_for = { 'somedomain.com' => :mx }
|
344
357
|
end
|
345
358
|
```
|
@@ -361,6 +374,7 @@ Truemail.validate('email@white-domain.com')
|
|
361
374
|
smtp_debug=nil>,
|
362
375
|
configuration=#<Truemail::Configuration:0x00005629f801bd28
|
363
376
|
@blacklisted_domains=["black-domain.com", "somedomain.com"],
|
377
|
+
@blacklisted_mx_ip_addresses=[],
|
364
378
|
@dns=[],
|
365
379
|
@connection_attempts=2,
|
366
380
|
@connection_timeout=2,
|
@@ -386,7 +400,7 @@ require 'truemail'
|
|
386
400
|
|
387
401
|
Truemail.configure do |config|
|
388
402
|
config.verifier_email = 'verifier@example.com'
|
389
|
-
config.whitelisted_domains = [
|
403
|
+
config.whitelisted_domains = %w[white-domain.com]
|
390
404
|
config.whitelist_validation = true
|
391
405
|
end
|
392
406
|
```
|
@@ -409,6 +423,7 @@ Truemail.validate('email@white-domain.com', with: :regex)
|
|
409
423
|
configuration=
|
410
424
|
#<Truemail::Configuration:0x0000563f0d2605c8
|
411
425
|
@blacklisted_domains=[],
|
426
|
+
@blacklisted_mx_ip_addresses=[],
|
412
427
|
@dns=[],
|
413
428
|
@connection_attempts=2,
|
414
429
|
@connection_timeout=2,
|
@@ -443,6 +458,7 @@ Truemail.validate('email@domain.com', with: :regex)
|
|
443
458
|
configuration=
|
444
459
|
#<Truemail::Configuration:0x0000563f0cd82ab0
|
445
460
|
@blacklisted_domains=[],
|
461
|
+
@blacklisted_mx_ip_addresses=[],
|
446
462
|
@dns=[],
|
447
463
|
@connection_attempts=2,
|
448
464
|
@connection_timeout=2,
|
@@ -463,7 +479,7 @@ Truemail.validate('email@domain.com', with: :regex)
|
|
463
479
|
|
464
480
|
##### Blacklist case
|
465
481
|
|
466
|
-
When email in blacklist, validation type will be redefined too. Validation result returns
|
482
|
+
When email in blacklist, validation type will be redefined too. Validation result returns `false`.
|
467
483
|
|
468
484
|
```ruby
|
469
485
|
Truemail.validate('email@black-domain.com')
|
@@ -479,6 +495,7 @@ Truemail.validate('email@black-domain.com')
|
|
479
495
|
configuration=
|
480
496
|
#<Truemail::Configuration:0x0000563f0d36f4f0
|
481
497
|
@blacklisted_domains=[],
|
498
|
+
@blacklisted_mx_ip_addresses=[],
|
482
499
|
@dns=[],
|
483
500
|
@connection_attempts=2,
|
484
501
|
@connection_timeout=2,
|
@@ -515,6 +532,7 @@ Truemail.validate('email@somedomain.com')
|
|
515
532
|
configuration=
|
516
533
|
#<Truemail::Configuration:0x0000563f0d3f8fc0
|
517
534
|
@blacklisted_domains=[],
|
535
|
+
@blacklisted_mx_ip_addresses=[],
|
518
536
|
@dns=[],
|
519
537
|
@connection_attempts=2,
|
520
538
|
@connection_timeout=2,
|
@@ -559,7 +577,8 @@ Truemail.validate('email@example.com', with: :regex)
|
|
559
577
|
=> #<Truemail::Validator:0x000055590cc9bdb8
|
560
578
|
@result=
|
561
579
|
#<struct Truemail::Validator::Result
|
562
|
-
success=true,
|
580
|
+
success=true,
|
581
|
+
email="email@example.com",
|
563
582
|
domain=nil,
|
564
583
|
mail_servers=[],
|
565
584
|
errors={},
|
@@ -567,6 +586,7 @@ Truemail.validate('email@example.com', with: :regex)
|
|
567
586
|
configuration=
|
568
587
|
#<Truemail::Configuration:0x000055aa56a54d48
|
569
588
|
@blacklisted_domains=[],
|
589
|
+
@blacklisted_mx_ip_addresses=[],
|
570
590
|
@dns=[],
|
571
591
|
@connection_attempts=2,
|
572
592
|
@connection_timeout=2,
|
@@ -611,6 +631,7 @@ Truemail.validate('email@example.com', with: :regex)
|
|
611
631
|
configuration=
|
612
632
|
#<Truemail::Configuration:0x0000560e58d80830
|
613
633
|
@blacklisted_domains=[],
|
634
|
+
@blacklisted_mx_ip_addresses=[],
|
614
635
|
@dns=[],
|
615
636
|
@connection_attempts=2,
|
616
637
|
@connection_timeout=2,
|
@@ -666,6 +687,7 @@ Truemail.validate('email@example.com', with: :mx)
|
|
666
687
|
configuration=
|
667
688
|
#<Truemail::Configuration:0x0000559b6e44af70
|
668
689
|
@blacklisted_domains=[],
|
690
|
+
@blacklisted_mx_ip_addresses=[],
|
669
691
|
@dns=[],
|
670
692
|
@connection_attempts=2,
|
671
693
|
@connection_timeout=2,
|
@@ -712,6 +734,7 @@ Truemail.validate('email@example.com', with: :mx)
|
|
712
734
|
configuration=
|
713
735
|
#<Truemail::Configuration:0x0000559b6e44af70
|
714
736
|
@blacklisted_domains=[],
|
737
|
+
@blacklisted_mx_ip_addresses=[],
|
715
738
|
@dns=[],
|
716
739
|
@connection_attempts=2,
|
717
740
|
@connection_timeout=2,
|
@@ -730,12 +753,63 @@ Truemail.validate('email@example.com', with: :mx)
|
|
730
753
|
@validation_type=:mx>
|
731
754
|
```
|
732
755
|
|
756
|
+
#### MX blacklist validation
|
757
|
+
|
758
|
+
MX blacklist validation is the third validation level. This layer provides checking extracted mail server(s) IP address from MX validation with predefined blacklisted IP addresses list. It can be used as a part of DEA ([disposable email address](https://en.wikipedia.org/wiki/Disposable_email_address)) validations.
|
759
|
+
|
760
|
+
```code
|
761
|
+
[Whitelist/Blacklist] -> [Regex validation] -> [MX validation] -> [MX blacklist validation]
|
762
|
+
```
|
763
|
+
|
764
|
+
Example of usage:
|
765
|
+
|
766
|
+
```ruby
|
767
|
+
require 'truemail'
|
768
|
+
|
769
|
+
Truemail.configure do |config|
|
770
|
+
config.verifier_email = 'verifier@example.com'
|
771
|
+
config.blacklisted_mx_ip_addresses = %w[127.0.1.2]
|
772
|
+
end
|
773
|
+
|
774
|
+
Truemail.validate('email@example.com', with: :mx_blacklist)
|
775
|
+
|
776
|
+
=> #<Truemail::Validator:0x00007fca0c8aea70
|
777
|
+
@result=
|
778
|
+
#<struct Truemail::Validator::Result
|
779
|
+
success=false,
|
780
|
+
email="email@example.com",
|
781
|
+
domain="example.com",
|
782
|
+
mail_servers=["127.0.1.1", "127.0.1.2"],
|
783
|
+
errors={:mx_blacklist=>"blacklisted mx server ip address"},
|
784
|
+
smtp_debug=nil,
|
785
|
+
configuration=
|
786
|
+
#<Truemail::Configuration:0x00007fca0c8aeb38
|
787
|
+
@blacklisted_domains=[],
|
788
|
+
@blacklisted_mx_ip_addresses=["127.0.1.2"],
|
789
|
+
@connection_attempts=2,
|
790
|
+
@connection_timeout=2,
|
791
|
+
@default_validation_type=:smtp,
|
792
|
+
@dns=[],
|
793
|
+
@email_pattern=/(?=\A.{6,255}\z)(\A([\p{L}0-9]+[\w|\-.+]*)@((?i-mx:[\p{L}0-9]+([\-.]{1}[\p{L}0-9]+)*\.\p{L}{2,63}))\z)/,
|
794
|
+
@not_rfc_mx_lookup_flow=false,
|
795
|
+
@response_timeout=2,
|
796
|
+
@smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
|
797
|
+
@smtp_fail_fast=false,
|
798
|
+
@smtp_safe_check=false,
|
799
|
+
@validation_type_by_domain={},
|
800
|
+
@verifier_domain="example.com",
|
801
|
+
@verifier_email="verifier@example.com",
|
802
|
+
@whitelist_validation=false,
|
803
|
+
@whitelisted_domains=[]>>,
|
804
|
+
@validation_type=:mx_blacklist>
|
805
|
+
```
|
806
|
+
|
733
807
|
#### SMTP validation
|
734
808
|
|
735
|
-
SMTP validation is a final,
|
809
|
+
SMTP validation is a final, fourth validation level. This type of validation tries to check real existence of email account on a current email server. This validation runs a chain of previous validations and if they're complete successfully then runs itself.
|
736
810
|
|
737
811
|
```code
|
738
|
-
[Whitelist/Blacklist] -> [Regex validation] -> [MX validation] -> [SMTP validation]
|
812
|
+
[Whitelist/Blacklist] -> [Regex validation] -> [MX validation] -> [MX blacklist validation] -> [SMTP validation]
|
739
813
|
```
|
740
814
|
|
741
815
|
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`.
|
@@ -787,6 +861,7 @@ Truemail.validate('email@example.com')
|
|
787
861
|
configuration=
|
788
862
|
#<Truemail::Configuration:0x00007fdc4504f5c8
|
789
863
|
@blacklisted_domains=[],
|
864
|
+
@blacklisted_mx_ip_addresses=[],
|
790
865
|
@dns=[],
|
791
866
|
@connection_attempts=2,
|
792
867
|
@connection_timeout=2,
|
@@ -831,6 +906,7 @@ Truemail.validate('email@example.com')
|
|
831
906
|
configuration=
|
832
907
|
#<Truemail::Configuration:0x00005615e87b9298
|
833
908
|
@blacklisted_domains=[],
|
909
|
+
@blacklisted_mx_ip_addresses=[],
|
834
910
|
@dns=[],
|
835
911
|
@connection_attempts=2,
|
836
912
|
@connection_timeout=2,
|
@@ -882,6 +958,7 @@ Truemail.validate('email@example.com')
|
|
882
958
|
configuration=
|
883
959
|
#<Truemail::Configuration:0x00005615e87b9298
|
884
960
|
@blacklisted_domains=[],
|
961
|
+
@blacklisted_mx_ip_addresses=[],
|
885
962
|
@dns=[],
|
886
963
|
@connection_attempts=2,
|
887
964
|
@connection_timeout=2,
|
@@ -945,6 +1022,7 @@ Truemail.validate('email@example.com')
|
|
945
1022
|
configuration=
|
946
1023
|
#<Truemail::Configuration:0x00005615e87b9298
|
947
1024
|
@blacklisted_domains=[],
|
1025
|
+
@blacklisted_mx_ip_addresses=[],
|
948
1026
|
@dns=[],
|
949
1027
|
@connection_attempts=2,
|
950
1028
|
@connection_timeout=2,
|
@@ -993,6 +1071,7 @@ Truemail.validate('email@example.com')
|
|
993
1071
|
configuration=
|
994
1072
|
#<Truemail::Configuration:0x00005615e87b9298
|
995
1073
|
@blacklisted_domains=[],
|
1074
|
+
@blacklisted_mx_ip_addresses=[],
|
996
1075
|
@dns=[],
|
997
1076
|
@connection_attempts=2,
|
998
1077
|
@connection_timeout=2,
|
@@ -1042,6 +1121,7 @@ Truemail.host_audit
|
|
1042
1121
|
configuration=
|
1043
1122
|
#<Truemail::Configuration:0x00005615e86327a8
|
1044
1123
|
@blacklisted_domains=[],
|
1124
|
+
@blacklisted_mx_ip_addresses=[],
|
1045
1125
|
@dns=[],
|
1046
1126
|
@connection_attempts=2,
|
1047
1127
|
@connection_timeout=2,
|
@@ -1070,6 +1150,7 @@ Truemail.host_audit
|
|
1070
1150
|
configuration=
|
1071
1151
|
#<Truemail::Configuration:0x00005615e86327a8
|
1072
1152
|
@blacklisted_domains=[],
|
1153
|
+
@blacklisted_mx_ip_addresses=[],
|
1073
1154
|
@dns=[],
|
1074
1155
|
@connection_attempts=2,
|
1075
1156
|
@connection_timeout=2,
|
@@ -1123,6 +1204,7 @@ Truemail::Log::Serializer::AuditorJson.call(Truemail.host_audit)
|
|
1123
1204
|
},
|
1124
1205
|
"configuration": {
|
1125
1206
|
"blacklisted_domains": null,
|
1207
|
+
"blacklisted_mx_ip_addresses": null,
|
1126
1208
|
"dns": null,
|
1127
1209
|
"email_pattern": "default gem value",
|
1128
1210
|
"not_rfc_mx_lookup_flow": false,
|
@@ -1163,6 +1245,7 @@ Truemail::Log::Serializer::ValidatorJson.call(Truemail.validate('nonexistent_ema
|
|
1163
1245
|
],
|
1164
1246
|
"configuration": {
|
1165
1247
|
"blacklisted_domains": null,
|
1248
|
+
"blacklisted_mx_ip_addresses": null,
|
1166
1249
|
"dns": null,
|
1167
1250
|
"email_pattern": "default gem value",
|
1168
1251
|
"not_rfc_mx_lookup_flow": false,
|
@@ -1205,6 +1288,7 @@ Truemail.host_audit.as_json
|
|
1205
1288
|
},
|
1206
1289
|
"configuration": {
|
1207
1290
|
"blacklisted_domains": null,
|
1291
|
+
"blacklisted_mx_ip_addresses": null,
|
1208
1292
|
"dns": null,
|
1209
1293
|
"email_pattern": "default gem value",
|
1210
1294
|
"not_rfc_mx_lookup_flow": false,
|
@@ -1242,6 +1326,7 @@ Truemail.validate('nonexistent_email@bestweb.com.ua').as_json
|
|
1242
1326
|
],
|
1243
1327
|
"configuration": {
|
1244
1328
|
"blacklisted_domains": null,
|
1329
|
+
"blacklisted_mx_ip_addresses": null,
|
1245
1330
|
"dns": null,
|
1246
1331
|
"email_pattern": "default gem value",
|
1247
1332
|
"not_rfc_mx_lookup_flow": false,
|
@@ -15,13 +15,14 @@ module Truemail
|
|
15
15
|
connection_attempts
|
16
16
|
whitelisted_domains
|
17
17
|
blacklisted_domains
|
18
|
+
blacklisted_mx_ip_addresses
|
19
|
+
dns
|
18
20
|
].freeze
|
19
21
|
|
20
22
|
attr_reader :verifier_email,
|
21
23
|
:verifier_domain,
|
22
24
|
:default_validation_type,
|
23
25
|
:validation_type_by_domain,
|
24
|
-
:dns,
|
25
26
|
:logger,
|
26
27
|
*Truemail::Configuration::SETTERS
|
27
28
|
|
@@ -55,9 +56,9 @@ module Truemail
|
|
55
56
|
validation_type_by_domain.merge!(settings)
|
56
57
|
end
|
57
58
|
|
58
|
-
def argument_consistent?(argument)
|
59
|
+
def argument_consistent?(method, argument)
|
59
60
|
case argument
|
60
|
-
when ::Array then
|
61
|
+
when ::Array then items_match_regex?(argument, regex_by_method(method))
|
61
62
|
when ::Integer then argument.positive?
|
62
63
|
when ::Regexp then true
|
63
64
|
end
|
@@ -65,16 +66,11 @@ module Truemail
|
|
65
66
|
|
66
67
|
Truemail::Configuration::SETTERS.each do |method|
|
67
68
|
define_method("#{method}=") do |argument|
|
68
|
-
raise_unless(argument, __method__, argument_consistent?(argument))
|
69
|
+
raise_unless(argument, __method__, argument_consistent?(method, argument))
|
69
70
|
instance_variable_set(:"@#{method}", argument)
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
73
|
-
def dns=(argument)
|
74
|
-
raise_unless(argument, __method__, argument.is_a?(::Array) && check_dns_settings(argument))
|
75
|
-
@dns = argument
|
76
|
-
end
|
77
|
-
|
78
74
|
def logger=(options)
|
79
75
|
tracking_event, stdout, log_absolute_path = logger_options(options)
|
80
76
|
valid_event = Truemail::Log::Event::TRACKING_EVENTS.key?(tracking_event)
|
@@ -104,6 +100,7 @@ module Truemail
|
|
104
100
|
whitelisted_domains: [],
|
105
101
|
whitelist_validation: false,
|
106
102
|
blacklisted_domains: [],
|
103
|
+
blacklisted_mx_ip_addresses: [],
|
107
104
|
dns: [],
|
108
105
|
not_rfc_mx_lookup_flow: false,
|
109
106
|
smtp_fail_fast: false,
|
@@ -115,25 +112,27 @@ module Truemail
|
|
115
112
|
raise Truemail::ArgumentError.new(argument_context, argument_name) unless condition
|
116
113
|
end
|
117
114
|
|
115
|
+
def match_regex?(regex_pattern, object)
|
116
|
+
regex_pattern.match?(object.to_s)
|
117
|
+
end
|
118
|
+
|
118
119
|
def validate_arguments(argument, method)
|
119
|
-
|
120
|
-
raise_unless(argument, method,
|
120
|
+
regex_pattern = Truemail::RegexConstant.const_get("regex_#{method[/\A.+_(.+)=\z/, 1]}_pattern".upcase)
|
121
|
+
raise_unless(argument, method, match_regex?(regex_pattern, argument))
|
121
122
|
end
|
122
123
|
|
123
124
|
def default_verifier_domain
|
124
125
|
self.verifier_domain ||= verifier_email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3]
|
125
126
|
end
|
126
127
|
|
127
|
-
def
|
128
|
-
|
128
|
+
def regex_by_method(method)
|
129
|
+
return Truemail::RegexConstant::REGEX_IP_ADDRESS_PATTERN if method.eql?(:blacklisted_mx_ip_addresses)
|
130
|
+
return Truemail::RegexConstant::REGEX_DNS_SERVER_ADDRESS_PATTERN if method.eql?(:dns)
|
131
|
+
Truemail::RegexConstant::REGEX_DOMAIN_PATTERN
|
129
132
|
end
|
130
133
|
|
131
|
-
def
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
def check_domain_list(domains)
|
136
|
-
domains.all?(&domain_matcher)
|
134
|
+
def items_match_regex?(items, regex_pattern)
|
135
|
+
items.all? { |item| match_regex?(regex_pattern, item) }
|
137
136
|
end
|
138
137
|
|
139
138
|
def check_validation_type(validation_type)
|
@@ -143,15 +142,11 @@ module Truemail
|
|
143
142
|
def validate_validation_type(settings)
|
144
143
|
raise_unless(settings, 'hash with settings', settings.is_a?(::Hash))
|
145
144
|
settings.each do |domain, validation_type|
|
146
|
-
|
145
|
+
raise_unless(domain, 'domain', match_regex?(Truemail::RegexConstant::REGEX_DOMAIN_PATTERN, domain))
|
147
146
|
check_validation_type(validation_type)
|
148
147
|
end
|
149
148
|
end
|
150
149
|
|
151
|
-
def check_dns_settings(dns_servers)
|
152
|
-
dns_servers.all? { |dns_server| Truemail::RegexConstant::REGEX_DNS_SERVER_ADDRESS_PATTERN.match?(dns_server.to_s) }
|
153
|
-
end
|
154
|
-
|
155
150
|
def logger_options(current_options)
|
156
151
|
Truemail::Configuration::DEFAULT_LOGGER_OPTIONS.merge(current_options).values
|
157
152
|
end
|