truemail 2.1.0 → 2.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: c97288083bd45ad7d2c72816ee979f166795806193a7df46a43a4a9b9e657cef
4
- data.tar.gz: 0e332a857d8639513d71c1876de23406f6ec531174d40fbd160cedc3fcc443f1
3
+ metadata.gz: ccc592c306e3cb61ae0b64e88204a5d464d614abb842bc6538112a19acca812a
4
+ data.tar.gz: f61ebb1883ff711a1816c3f6523c1ab2f4ffa11b13782011d4d42f9204a4e298
5
5
  SHA512:
6
- metadata.gz: c7ee9a4a07c04e44b8db3ab346ce190bbaf441cf7e68202cd60b3766c4fd3cf1f9003a7d4d35023a8b87d7864be4d2d8f01580ab4cd291f3e265107e9a947455
7
- data.tar.gz: c8ec35b9b9491853303a5c49c2bfdd06111ff713c710f3058178c691daa55d9b8ff75bdd47099c91b30bd2d90bdd4b5f4fd35077fd4adcb0578cdae9909066a6
6
+ metadata.gz: 640d6769aee1f4fde2d525253d3096a99866ecd190ad1e3f5ddb77c4105908f97a7cd3468fb65d97363291ec3931cc4802f25673e696ffee6d028000f8d5edff
7
+ data.tar.gz: 21e63e9a6b6e17b830569a64ddb563264e8ff1a5a4ab6ac22da21169bd331474ae2e467765a196d36b5bafd5ef40867cf4baf74b3861cab967c24bfd457d4a73
data/.reek.yml CHANGED
@@ -27,6 +27,7 @@ detectors:
27
27
  exclude:
28
28
  - Truemail::Configuration#whitelist_validation
29
29
  - Truemail::Configuration#not_rfc_mx_lookup_flow
30
+ - Truemail::Configuration#smtp_fail_fast
30
31
  - Truemail::Configuration#smtp_safe_check
31
32
  - Truemail::Wrapper#attempts
32
33
 
@@ -2,9 +2,35 @@
2
2
 
3
3
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
4
 
5
+ ## [2.2.0] - 2020.12.01
6
+
7
+ Ability to use fail fast behaviour for SMTP validation layer. When `smtp_fail_fast = true` it means that `truemail` ends smtp validation session after first attempt on the first mx server in any fail cases (network connection/timeout error, smtp validation error). This feature helps to reduce total time of SMTP validation session up to 1 second.
8
+
9
+ ### Added
10
+
11
+ - Added `Truemail::Configuration#smtp_fail_fast`
12
+ - Added `Truemail::Validate::Smtp#smtp_fail_fast?`
13
+ - Added `Truemail::Validate::Smtp#filtered_mail_servers_by_fail_fast_scenario`
14
+
15
+ ### Changed
16
+
17
+ - Updated `Truemail::Validate::Smtp#attempts`
18
+ - Updated `Truemail::Validate::Smtp#establish_smtp_connection`
19
+ - Updated gem documentation
20
+
21
+ It's a configurable and not required option:
22
+
23
+ ```ruby
24
+ Truemail.configure do |config|
25
+ config.smtp_fail_fast = true # by default it's equal to false
26
+ end
27
+ ```
28
+
29
+ Thanks to [@wikiti](https://github.com/wikiti) for timeout reports.
30
+
5
31
  ## [2.1.0] - 2020.11.21
6
32
 
7
- Collecting only unique ip-addresses for target mail servers. This update should reduce email validation time for case when remote server have closed connection via avoiding connection attempt to server with the same ip address.
33
+ Collecting only unique ip-addresses for target mail servers. This update reduces email validation time for case when remote server have closed connection via avoiding connection attempt to server with the same ip address.
8
34
 
9
35
  ### Changed
10
36
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- truemail (2.1.0)
4
+ truemail (2.2.0)
5
5
  simpleidn (~> 0.1.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -40,6 +40,7 @@ Configurable framework agnostic plain Ruby email validator. Verify email via Reg
40
40
  - [RFC MX lookup flow](#rfc-mx-lookup-flow)
41
41
  - [Not RFC MX lookup flow](#not-rfc-mx-lookup-flow)
42
42
  - [SMTP validation](#smtp-validation)
43
+ - [SMTP fail fast enabled](#smtp-fail-fast-enabled)
43
44
  - [SMTP safe check disabled](#smtp-safe-check-disabled)
44
45
  - [SMTP safe check enabled](#smtp-safe-check-enabled)
45
46
  - [Host audit features](#host-audit-features)
@@ -82,10 +83,12 @@ Also Truemail gem allows performing an audit of the host in which runs.
82
83
  - Minimal runtime dependencies
83
84
  - Supporting of internationalized emails ([EAI](https://en.wikipedia.org/wiki/Email_address#Internationalization))
84
85
  - Whitelist/blacklist validation layers
86
+ - Ability to configure different MX/SMTP validation flows
85
87
  - Simple SMTP debugger
86
88
  - Event logger
87
89
  - Host auditor tools (helps to detect common host problems interfering to proper email verification)
88
90
  - JSON serializers
91
+ - Ability to use the library as independent stateless microservice ([Truemail Server](https://truemail-rb.org/truemail-rack))
89
92
 
90
93
  ## Requirements
91
94
 
@@ -129,6 +132,8 @@ You can use global gem configuration or custom independent configuration. Availa
129
132
  - whitelisted domains
130
133
  - whitelist validation
131
134
  - blacklisted domains
135
+ - RFC MX lookup flow
136
+ - SMTP fail fast
132
137
  - SMTP safe check
133
138
  - event logger
134
139
  - JSON serializer
@@ -201,6 +206,13 @@ Truemail.configure do |config|
201
206
  # By default this option is disabled.
202
207
  config.not_rfc_mx_lookup_flow = true
203
208
 
209
+ # Optional parameter. This option will provide to use smtp fail fast behaviour. When
210
+ # smtp_fail_fast = true it means that truemail ends smtp validation session after first
211
+ # attempt on the first mx server in any fail cases (network connection/timeout error,
212
+ # smtp validation error). This feature helps to reduce total time of SMTP validation
213
+ # session up to 1 second. By default this option is disabled.
214
+ config.smtp_fail_fast = true
215
+
204
216
  # Optional parameter. This option will be parse bodies of SMTP errors. It will be helpful
205
217
  # if SMTP server does not return an exact answer that the email does not exist
206
218
  # By default this option is disabled, available for SMTP validation only.
@@ -233,6 +245,7 @@ Truemail.configuration
233
245
  @verifier_domain="somedomain.com",
234
246
  @verifier_email="verifier@example.com",
235
247
  @not_rfc_mx_lookup_flow=true,
248
+ @smtp_fail_fast=true,
236
249
  @smtp_safe_check=true,
237
250
  @logger=#<Truemail::Logger:0x0000557f837450b0
238
251
  @event=:all, @file="/home/app/log/truemail.log", @stdout=true>>
@@ -262,6 +275,7 @@ Truemail.configuration
262
275
  @verifier_domain="somedomain.com",
263
276
  @verifier_email="verifier@example.com",
264
277
  @not_rfc_mx_lookup_flow=true,
278
+ @smtp_fail_fast=true,
265
279
  @smtp_safe_check=true,
266
280
  @logger=#<Truemail::Logger:0x0000557f837450b0
267
281
  @event=:all, @file="/home/app/log/truemail.log", @stdout=true>>
@@ -294,7 +308,6 @@ Truemail.host_audit('email@example.com', custom_configuration: custom_configurat
294
308
 
295
309
  Please note, you should have global or custom configuration for use Truemail gem.
296
310
 
297
-
298
311
  ### Validation features
299
312
 
300
313
  #### Whitelist/Blacklist check
@@ -346,6 +359,7 @@ Truemail.validate('email@white-domain.com')
346
359
  @response_timeout=2,
347
360
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
348
361
  @not_rfc_mx_lookup_flow=false,
362
+ @smtp_fail_fast=false,
349
363
  @smtp_safe_check=false,
350
364
  @validation_type_by_domain={"somedomain.com"=>:mx},
351
365
  @verifier_domain="example.com",
@@ -392,6 +406,7 @@ Truemail.validate('email@white-domain.com', with: :regex)
392
406
  @response_timeout=2,
393
407
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
394
408
  @not_rfc_mx_lookup_flow=false,
409
+ @smtp_fail_fast=false,
395
410
  @smtp_safe_check=false,
396
411
  @validation_type_by_domain={},
397
412
  @verifier_domain="example.com",
@@ -424,6 +439,7 @@ Truemail.validate('email@domain.com', with: :regex)
424
439
  @response_timeout=2,
425
440
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
426
441
  @not_rfc_mx_lookup_flow=false,
442
+ @smtp_fail_fast=false,
427
443
  @smtp_safe_check=false,
428
444
  @validation_type_by_domain={},
429
445
  @verifier_domain="example.com",
@@ -458,6 +474,7 @@ Truemail.validate('email@black-domain.com')
458
474
  @response_timeout=2,
459
475
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
460
476
  @not_rfc_mx_lookup_flow=false,
477
+ @smtp_fail_fast=false,
461
478
  @smtp_safe_check=false,
462
479
  @validation_type_by_domain={},
463
480
  @verifier_domain="example.com",
@@ -492,6 +509,7 @@ Truemail.validate('email@somedomain.com')
492
509
  @response_timeout=2,
493
510
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
494
511
  @not_rfc_mx_lookup_flow=false,
512
+ @smtp_fail_fast=false,
495
513
  @smtp_safe_check=false,
496
514
  @validation_type_by_domain={},
497
515
  @verifier_domain="example.com",
@@ -542,6 +560,7 @@ Truemail.validate('email@example.com', with: :regex)
542
560
  @response_timeout=2,
543
561
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
544
562
  @not_rfc_mx_lookup_flow=false,
563
+ @smtp_fail_fast=false,
545
564
  @smtp_safe_check=false,
546
565
  @validation_type_by_domain={},
547
566
  @verifier_domain="example.com",
@@ -584,6 +603,7 @@ Truemail.validate('email@example.com', with: :regex)
584
603
  @response_timeout=2,
585
604
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
586
605
  @not_rfc_mx_lookup_flow=false,
606
+ @smtp_fail_fast=false,
587
607
  @smtp_safe_check=false,
588
608
  @validation_type_by_domain={},
589
609
  @verifier_domain="example.com",
@@ -637,6 +657,7 @@ Truemail.validate('email@example.com', with: :mx)
637
657
  @response_timeout=2,
638
658
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
639
659
  @not_rfc_mx_lookup_flow=false,
660
+ @smtp_fail_fast=false,
640
661
  @smtp_safe_check=false,
641
662
  @validation_type_by_domain={},
642
663
  @verifier_domain="example.com",
@@ -681,6 +702,7 @@ Truemail.validate('email@example.com', with: :mx)
681
702
  @response_timeout=2,
682
703
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
683
704
  @not_rfc_mx_lookup_flow=true,
705
+ @smtp_fail_fast=false,
684
706
  @smtp_safe_check=false,
685
707
  @validation_type_by_domain={},
686
708
  @verifier_domain="example.com",
@@ -702,6 +724,68 @@ If total count of MX servers is equal to one, `Truemail::Smtp` validator will us
702
724
 
703
725
  By default, you don't need pass with-parameter to use it. Example of usage is specified below:
704
726
 
727
+ ##### SMTP fail fast enabled
728
+
729
+ Truemail can use fail fast behaviour for SMTP validation layer. When `smtp_fail_fast = true` it means that `truemail` ends smtp validation session after first attempt on the first mx server in any fail cases (network connection/timeout error, smtp validation error). This feature helps to reduce total time of SMTP validation session up to 1 second.
730
+
731
+ ```ruby
732
+ require 'truemail'
733
+
734
+ Truemail.configure do |config|
735
+ config.verifier_email = 'verifier@example.com'
736
+ config.smtp_fail_fast = true
737
+ end
738
+
739
+ Truemail.validate('email@example.com')
740
+
741
+ # SMTP validation failed, smtp fail fast validation scenario
742
+ => #<Truemail::Validator:0x00007fdc4504f460
743
+ @result=
744
+ #<struct Truemail::Validator::Result
745
+ success=false,
746
+ email="email@example.com",
747
+ domain="example.com",
748
+ mail_servers=["127.0.1.1", "127.0.1.2", "127.0.1.3"], # there are 3 mail servers in a row
749
+ errors={:smtp=>"smtp error"},
750
+ smtp_debug=
751
+ [#<Truemail::Validate::Smtp::Request:0x00007fdc43150b90 # but iteration has been stopped after the first failure
752
+ @attempts=nil,
753
+ @configuration=
754
+ #<Truemail::Validate::Smtp::Request::Configuration:0x00007fdc43150b18
755
+ @connection_timeout=2,
756
+ @response_timeout=2,
757
+ @verifier_domain="example.com",
758
+ @verifier_email="verifier@example.com">,
759
+ @email="email@example.com",
760
+ @host="127.0.1.1",
761
+ @response=
762
+ #<struct Truemail::Validate::Smtp::Response
763
+ port_opened=false,
764
+ connection=nil,
765
+ helo=nil,
766
+ mailfrom=nil,
767
+ rcptto=nil,
768
+ errors={}>>],
769
+ configuration=
770
+ #<Truemail::Configuration:0x00007fdc4504f5c8
771
+ @blacklisted_domains=[],
772
+ @connection_attempts=2,
773
+ @connection_timeout=2,
774
+ @default_validation_type=:smtp,
775
+ @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)/,
776
+ @not_rfc_mx_lookup_flow=false,
777
+ @response_timeout=2,
778
+ @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
779
+ @smtp_fail_fast=true,
780
+ @smtp_safe_check=false,
781
+ @validation_type_by_domain={},
782
+ @verifier_domain="example.com",
783
+ @verifier_email="verifier@example.com",
784
+ @whitelist_validation=false,
785
+ @whitelisted_domains=[]>>,
786
+ @validation_type=:smtp>
787
+ ```
788
+
705
789
  ##### SMTP safe check disabled
706
790
 
707
791
  With `smtp_safe_check = false`
@@ -735,6 +819,7 @@ Truemail.validate('email@example.com')
735
819
  @response_timeout=2,
736
820
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
737
821
  @not_rfc_mx_lookup_flow=false,
822
+ @smtp_fail_fast=false,
738
823
  @smtp_safe_check=false,
739
824
  @validation_type_by_domain={},
740
825
  @verifier_domain="example.com",
@@ -784,6 +869,7 @@ Truemail.validate('email@example.com')
784
869
  @response_timeout=2,
785
870
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
786
871
  @not_rfc_mx_lookup_flow=false,
872
+ @smtp_fail_fast=false,
787
873
  @smtp_safe_check=false,
788
874
  @validation_type_by_domain={},
789
875
  @verifier_domain="example.com",
@@ -845,6 +931,7 @@ Truemail.validate('email@example.com')
845
931
  @response_timeout=2,
846
932
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
847
933
  @not_rfc_mx_lookup_flow=false,
934
+ @smtp_fail_fast=false,
848
935
  @smtp_safe_check=false,
849
936
  @validation_type_by_domain={},
850
937
  @verifier_domain="example.com",
@@ -891,6 +978,7 @@ Truemail.validate('email@example.com')
891
978
  @response_timeout=2,
892
979
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
893
980
  @not_rfc_mx_lookup_flow=false,
981
+ @smtp_fail_fast=false,
894
982
  @smtp_safe_check=false,
895
983
  @validation_type_by_domain={},
896
984
  @verifier_domain="example.com",
@@ -938,6 +1026,7 @@ Truemail.host_audit
938
1026
  @response_timeout=2,
939
1027
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
940
1028
  @not_rfc_mx_lookup_flow=false,
1029
+ @smtp_fail_fast=false,
941
1030
  @smtp_safe_check=false,
942
1031
  @validation_type_by_domain={},
943
1032
  @verifier_domain="example.com",
@@ -964,6 +1053,7 @@ Truemail.host_audit
964
1053
  @response_timeout=2,
965
1054
  @smtp_error_body_pattern=/(?=.*550)(?=.*(user|account|customer|mailbox)).*/i,
966
1055
  @not_rfc_mx_lookup_flow=false,
1056
+ @smtp_fail_fast=false,
967
1057
  @smtp_safe_check=false,
968
1058
  @validation_type_by_domain={},
969
1059
  @verifier_domain="example.com",
@@ -1012,6 +1102,7 @@ Truemail::Log::Serializer::AuditorJson.call(Truemail.host_audit)
1012
1102
  "whitelisted_domains": null,
1013
1103
  "blacklisted_domains": null,
1014
1104
  "not_rfc_mx_lookup_flow": false,
1105
+ "smtp_fail_fast": false,
1015
1106
  "smtp_safe_check": false,
1016
1107
  "email_pattern": "default gem value",
1017
1108
  "smtp_error_body_pattern": "default gem value"
@@ -1050,6 +1141,7 @@ Truemail::Log::Serializer::ValidatorJson.call(Truemail.validate('nonexistent_ema
1050
1141
  "whitelisted_domains": null,
1051
1142
  "blacklisted_domains": null,
1052
1143
  "not_rfc_mx_lookup_flow": false,
1144
+ "smtp_fail_fast": false,
1053
1145
  "smtp_safe_check": false,
1054
1146
  "email_pattern": "default gem value",
1055
1147
  "smtp_error_body_pattern": "default gem value"
@@ -1090,6 +1182,7 @@ Truemail.host_audit.as_json
1090
1182
  "whitelisted_domains": null,
1091
1183
  "blacklisted_domains": null,
1092
1184
  "not_rfc_mx_lookup_flow": false,
1185
+ "smtp_fail_fast": false,
1093
1186
  "smtp_safe_check": false,
1094
1187
  "email_pattern": "default gem value",
1095
1188
  "smtp_error_body_pattern": "default gem value"
@@ -1125,6 +1218,7 @@ Truemail.validate('nonexistent_email@bestweb.com.ua').as_json
1125
1218
  "whitelisted_domains": null,
1126
1219
  "blacklisted_domains": null,
1127
1220
  "not_rfc_mx_lookup_flow": false,
1221
+ "smtp_fail_fast": false,
1128
1222
  "smtp_safe_check": false,
1129
1223
  "email_pattern": "default gem value",
1130
1224
  "smtp_error_body_pattern": "default gem value"
@@ -21,7 +21,7 @@ module Truemail
21
21
  :blacklisted_domains,
22
22
  :logger
23
23
 
24
- attr_accessor :whitelist_validation, :not_rfc_mx_lookup_flow, :smtp_safe_check
24
+ attr_accessor :whitelist_validation, :not_rfc_mx_lookup_flow, :smtp_fail_fast, :smtp_safe_check
25
25
 
26
26
  def initialize(&block)
27
27
  instance_initializer.each do |instace_variable, value|
@@ -102,6 +102,7 @@ module Truemail
102
102
  whitelist_validation: false,
103
103
  blacklisted_domains: [],
104
104
  not_rfc_mx_lookup_flow: false,
105
+ smtp_fail_fast: false,
105
106
  smtp_safe_check: false
106
107
  }
107
108
  end
@@ -24,13 +24,23 @@ module Truemail
24
24
 
25
25
  private
26
26
 
27
- def request
28
- smtp_results.last
27
+ def fail_fast?
28
+ configuration.smtp_fail_fast
29
+ end
30
+
31
+ def filtered_mail_servers_by_fail_fast_scenario
32
+ fail_fast? ? mail_servers.first(1) : mail_servers
29
33
  end
30
34
 
31
35
  def attempts
32
- @attempts ||=
33
- mail_servers.one? ? { attempts: configuration.connection_attempts } : {}
36
+ @attempts ||= begin
37
+ return {} if fail_fast? || !mail_servers.one?
38
+ { attempts: configuration.connection_attempts }
39
+ end
40
+ end
41
+
42
+ def request
43
+ smtp_results.last
34
44
  end
35
45
 
36
46
  def rcptto_error
@@ -38,7 +48,7 @@ module Truemail
38
48
  end
39
49
 
40
50
  def establish_smtp_connection
41
- mail_servers.each do |mail_server|
51
+ filtered_mail_servers_by_fail_fast_scenario.each do |mail_server|
42
52
  smtp_results << Truemail::Validate::Smtp::Request.new(
43
53
  configuration: configuration, host: mail_server, email: result.punycode_email, **attempts
44
54
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Truemail
4
- VERSION = '2.1.0'
4
+ VERSION = '2.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: 2.1.0
4
+ version: 2.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: 2020-11-21 00:00:00.000000000 Z
11
+ date: 2020-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simpleidn