valid_email2 3.3.0 → 3.6.1

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: b11e62f82282c1cc81c9698a17a44af5d2a0baec3dc9a1f147e8b9f6201885cd
4
- data.tar.gz: 24b9024326e7f3ad965802c320901f2ecbd42cfcfc7c0b06e757f73767a6ae92
3
+ metadata.gz: 6e84cd1fd63d5212b95f59a0a5f690a741a359cc9b15e21ff1b2e531f13dc5df
4
+ data.tar.gz: d1625475d747e36ab893733330b5c5d359f059290d0c153ec6f4d3c5ad2c77f8
5
5
  SHA512:
6
- metadata.gz: cbb94d6b281464231ef30464b775fcbe1d404a8651105b2fe4b488182bc3cdcce9b2140d0a24431db7570c302c85e353f16e4f4444cd4edda009645a64f54ed4
7
- data.tar.gz: f5783382e56e570a02dd5abb0e7190d4f4e457a5b47e523bd21ddc4eab51fac7680811e2913e56e1db9ee1593f4c368c7f594558227ce635252c1a1e731a8484
6
+ metadata.gz: c5ba5da24f452053b31658e666f31e6b6ddf1607a59a2ed98b4e13f4f681838573ca8b3b02a29ecb2b8571d460cc1b7c08f96b1b59d91cdec5c02746a0774fbd
7
+ data.tar.gz: 1f446cae5d6ab54ad37ac56351f67519e48bf65468ebd2edc412afa8dce45d128ab2b5d0673f345eed84be61bc62300567c55b33089fc10f5d9a1c78012715b6
data/.travis.yml CHANGED
@@ -3,21 +3,19 @@ language: ruby
3
3
  sudo: false
4
4
 
5
5
  rvm:
6
+ - 3.0
6
7
  - 2.7
7
8
  - 2.6
8
9
  - 2.5
9
- - 2.4
10
10
 
11
11
  gemfile:
12
- - gemfiles/activemodel3.gemfile
13
- - gemfiles/activemodel4.gemfile
14
12
  - gemfiles/activemodel5.gemfile
15
13
  - gemfiles/activemodel6.gemfile
16
14
 
17
15
  jobs:
18
16
  exclude:
19
- - rvm: 2.4
20
- gemfile: gemfiles/activemodel6.gemfile
17
+ - rvm: 3.0
18
+ gemfile: gemfiles/activemodel5.gemfile
21
19
 
22
20
  before_install:
23
21
  - gem install bundler
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## Version 3.6.1
2
+ * Add new domain https://github.com/micke/valid_email2/pull/175
3
+ * Pull new domains
4
+
5
+ ## Version 3.6.0
6
+ * Add strict_mx validation https://github.com/micke/valid_email2/pull/173
7
+
8
+ ## Version 3.5.0
9
+ * Disallow emails starting with a dot https://github.com/micke/valid_email2/pull/170
10
+ * Add option to whitelist domains from MX check https://github.com/micke/valid_email2/pull/167
11
+ * Remove false positives
12
+
13
+ ## Version 3.4.0
14
+ * Disallow consecutive dots https://github.com/micke/valid_email2/pull/163
15
+ * Add andyes.net https://github.com/micke/valid_email2/pull/162
16
+
17
+ ## Version 3.3.1
18
+ * Fix some performance regressions (https://github.com/micke/valid_email2/pull/150)
19
+
1
20
  ## Version 3.3.0
2
21
  * Allow multiple addresses separated by comma (https://github.com/micke/valid_email2/pull/156)
3
22
  * Make prohibited_domain_characters_regex changeable (https://github.com/micke/valid_email2/pull/157)
data/README.md CHANGED
@@ -43,10 +43,14 @@ class User < ActiveRecord::Base
43
43
  end
44
44
  ```
45
45
 
46
- To validate that the domain has a MX record:
46
+ To validate that the domain has an MX record or A record:
47
47
  ```ruby
48
48
  validates :email, 'valid_email_2/email': { mx: true }
49
49
  ```
50
+ To validate strictly that the domain has an MX record:
51
+ ```ruby
52
+ validates :email, 'valid_email_2/email': { strict_mx: true }
53
+ ```
50
54
 
51
55
  To validate that the domain is not a disposable email (checks domain and MX server):
52
56
  ```ruby
@@ -58,11 +62,17 @@ To validate that the domain is not a disposable email (checks domain only, does
58
62
  validates :email, 'valid_email_2/email': { disposable_domain: true }
59
63
  ```
60
64
 
61
- To validate that the domain is not a disposable email or a disposable email but whitelisted (under config/whitelisted_email_domains.yml):
65
+ To validate that the domain is not a disposable email or a disposable email (checks domain and MX server) but whitelisted (under config/whitelisted_email_domains.yml):
62
66
  ```ruby
63
67
  validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
64
68
  ```
65
69
 
70
+ To validate that the domain is not a disposable email or a disposable email (checks domain only, does not check MX server) but whitelisted (under config/whitelisted_email_domains.yml):
71
+
72
+ ```ruby
73
+ validates :email, 'valid_email_2/email': { disposable_domain_with_whitelist: true }
74
+ ```
75
+
66
76
  To validate that the domain is not blacklisted (under config/blacklisted_email_domains.yml):
67
77
  ```ruby
68
78
  validates :email, 'valid_email_2/email': { blacklist: true }
@@ -103,6 +113,7 @@ address = ValidEmail2::Address.new("lisinge@gmail.com")
103
113
  address.valid? => true
104
114
  address.disposable? => false
105
115
  address.valid_mx? => true
116
+ address.valid_strict_mx? => true
106
117
  address.subaddressed? => false
107
118
  ```
108
119
 
@@ -114,6 +125,7 @@ Do so by adding this in your `spec_helper`:
114
125
  ```ruby
115
126
  config.before(:each) do
116
127
  allow_any_instance_of(ValidEmail2::Address).to receive(:valid_mx?).and_return(true)
128
+ allow_any_instance_of(ValidEmail2::Address).to receive(:valid_strict_mx?).and_return(true)
117
129
  end
118
130
  ```
119
131
 
@@ -128,11 +140,11 @@ end
128
140
 
129
141
  ## Requirements
130
142
 
131
- This gem requires Rails 3.2 or higher. It is tested against Rails 3, 4, 5 and 6 using:
132
- * Ruby-2.4
143
+ This gem should work with Rails 3.2 or higher. It is tested against Rails 5 and 6 using:
133
144
  * Ruby-2.5
134
145
  * Ruby-2.6
135
146
  * Ruby-2.7
147
+ * Ruby-3.0
136
148
 
137
149
  ## Upgrading to v3.0.0
138
150
 
@@ -3398,6 +3398,7 @@ androidsapps.co
3398
3398
  androidworld.tw
3399
3399
  andthen.us
3400
3400
  andy1mail.host
3401
+ andyes.net
3401
3402
  andynugraha.net
3402
3403
  andyyxc45.biz
3403
3404
  aneaproducciones.com
@@ -4173,6 +4174,7 @@ avuimkgtbgccejft901.ml
4173
4174
  avuimkgtbgccejft901.tk
4174
4175
  avumail.com
4175
4176
  avvmail.com
4177
+ avxrja.com
4176
4178
  aw.kikwet.com
4177
4179
  awahal0vk1o7gbyzf0.cf
4178
4180
  awahal0vk1o7gbyzf0.ga
@@ -5175,6 +5177,7 @@ bitwhites.top
5175
5177
  bitx.nl
5176
5178
  bitymails.us
5177
5179
  biuro-naprawcze.pl
5180
+ biyac.com
5178
5181
  biz.st
5179
5182
  bizalem.com
5180
5183
  bizalon.com
@@ -8178,6 +8181,7 @@ datauoso.com
8178
8181
  datawurld.com
8179
8182
  datazo.ca
8180
8183
  datchka.ru
8184
+ datenschutz.ru
8181
8185
  datingbio.info
8182
8186
  datingbit.info
8183
8187
  datingcloud.info
@@ -8613,6 +8617,7 @@ dietysuplementy.pl
8613
8617
  dieukydieuophonggiamso7.com
8614
8618
  diffamr.com
8615
8619
  diflucanrxmeds.com
8620
+ digdig.org
8616
8621
  digdown.xyz
8617
8622
  diggmail.club
8618
8623
  digibeat.pl
@@ -9222,6 +9227,7 @@ dsfgdsgmail.com
9222
9227
  dsfgdsgmail.net
9223
9228
  dsfgerqwexx.com
9224
9229
  dsgawerqw.com
9230
+ dsgvo.ru
9225
9231
  dshqughcoin9nazl.cf
9226
9232
  dshqughcoin9nazl.ga
9227
9233
  dshqughcoin9nazl.gq
@@ -10977,6 +10983,7 @@ familylist.ru
10977
10983
  familyright.ru
10978
10984
  familytoday.us
10979
10985
  fammix.com
10986
+ fanclub.pm
10980
10987
  fancycarnavalmasks.com
10981
10988
  fandamtastic.info
10982
10989
  fangoh.com
@@ -11327,6 +11334,7 @@ financehowtolearn.com
11327
11334
  financeideas.org
11328
11335
  financeland.com
11329
11336
  financetutorial.org
11337
+ finckl.com
11330
11338
  find-me-watch.com
11331
11339
  find.cy
11332
11340
  findbesthgh.com
@@ -11356,6 +11364,7 @@ fireflies.edu
11356
11364
  firemail.cc
11357
11365
  firemail.org.ua
11358
11366
  firemail.uz.ua
11367
+ firemailbox.club
11359
11368
  firematchvn.cf
11360
11369
  firematchvn.ga
11361
11370
  firematchvn.gq
@@ -11982,6 +11991,7 @@ fuirio.com
11982
11991
  fujitv.cf
11983
11992
  fujitv.ga
11984
11993
  fujitv.gq
11994
+ fukaru.com
11985
11995
  fukolpza.com.pl
11986
11996
  fuktard.co.in
11987
11997
  fullalts.cf
@@ -12049,6 +12059,7 @@ fuw65d.tk
12049
12059
  fuwa.be
12050
12060
  fuwa.li
12051
12061
  fuwamofu.com
12062
+ fuwari.be
12052
12063
  fux0ringduh.com
12053
12064
  fuzmail.info
12054
12065
  fvhnqf7zbixgtgdimpn.cf
@@ -12788,6 +12799,7 @@ gmailllll.ga
12788
12799
  gmaills.eu
12789
12800
  gmailmail.ga
12790
12801
  gmailmarina.com
12802
+ gmailnator.com
12791
12803
  gmailner.com
12792
12804
  gmailnew.com
12793
12805
  gmailom.co
@@ -12938,6 +12950,7 @@ golivejasmin.com
12938
12950
  gomail.in
12939
12951
  gomail.pgojual.com
12940
12952
  gomailbox.info
12953
+ gomaild.com
12941
12954
  gomaile.com
12942
12955
  gomailstar.xyz
12943
12956
  gomessage.ml
@@ -13224,6 +13237,7 @@ grr.la
13224
13237
  grruprkfj.pl
13225
13238
  grubybenekrayskiego.pl
13226
13239
  grubymail.com
13240
+ grugrug.ru
13227
13241
  grupatworczapik.pl
13228
13242
  gruz-m.ru
13229
13243
  gry-logiczne-i-liczbowe.pl
@@ -13579,6 +13593,7 @@ halkasor.com
13579
13593
  halofarmasi.com
13580
13594
  haltospam.com
13581
13595
  hamakdupajasia.com
13596
+ hamham.uk
13582
13597
  hammerdin.com
13583
13598
  hamsing.com
13584
13599
  hamtwer.biz
@@ -13812,6 +13827,7 @@ hefrent.tk
13812
13827
  hehesou.com
13813
13828
  hehmail.pl
13814
13829
  heihamail.com
13830
+ heisei.be
13815
13831
  helamakbeszesc.com
13816
13832
  hello.nl
13817
13833
  hello123.com
@@ -14162,6 +14178,7 @@ homlee.com
14162
14178
  homlee.mygbiz.com
14163
14179
  honeydresses.com
14164
14180
  honeydresses.net
14181
+ honeys.be
14165
14182
  hongfany.com
14166
14183
  hongpress.com
14167
14184
  honkimailc.info
@@ -14949,6 +14966,7 @@ ilovemyniggers.club
14949
14966
  ilovespam.com
14950
14967
  ilt.ctu.edu.gr
14951
14968
  iltmail.com
14969
+ iludir.com
14952
14970
  ilumail.com
14953
14971
  im-irsyad.tech
14954
14972
  im4ever.com
@@ -16364,6 +16382,7 @@ kadokawa.gq
16364
16382
  kadokawa.ml
16365
16383
  kadokawa.tk
16366
16384
  kadokawa.top
16385
+ kaengu.ru
16367
16386
  kafrem3456ails.com
16368
16387
  kaguya.tk
16369
16388
  kah.pw
@@ -16485,6 +16504,7 @@ kbbxowpdcpvkxmalz.tk
16485
16504
  kbdjvgznhslz.ga
16486
16505
  kbdjvgznhslz.ml
16487
16506
  kbdjvgznhslz.tk
16507
+ kbox.li
16488
16508
  kc-kenes.kz
16489
16509
  kc8pnm1p9.pl
16490
16510
  kchkch.com
@@ -18053,6 +18073,7 @@ louboutinshoessalejp.com
18053
18073
  louboutinshoesstoresjp.com
18054
18074
  louboutinshoesus.com
18055
18075
  louder1.bid
18076
+ loufad.com
18056
18077
  louis-vuitton-onlinestore.com
18057
18078
  louis-vuitton-outlet.com
18058
18079
  louis-vuitton-outletenter.com
@@ -18519,6 +18540,7 @@ magicedhardy.com
18519
18540
  magicmail.com
18520
18541
  magiconly.ru
18521
18542
  magicsubmitter.biz
18543
+ magim.be
18522
18544
  magneticmessagingbobby.com
18523
18545
  magnetik.com.ua
18524
18546
  magnomsolutions.com
@@ -19433,6 +19455,7 @@ maxmail.in
19433
19455
  maxmail.info
19434
19456
  maxpedia.ro
19435
19457
  maxprice.co
19458
+ maxresistance.com
19436
19459
  maxrollspins.co
19437
19460
  maxxdrv.ru
19438
19461
  mayaaaa.cf
@@ -19890,6 +19913,7 @@ miopaaswod.jino.ru
19890
19913
  mior.in
19891
19914
  mipodon.ga
19892
19915
  miraclegarciniareview.com
19916
+ mirai.re
19893
19917
  miraigames.net
19894
19918
  miranda1121.club
19895
19919
  mirbeauty.ru
@@ -20086,6 +20110,7 @@ mohmal.in
20086
20110
  mohmal.tech
20087
20111
  mohsenfb.com
20088
20112
  moijkh.com.uk
20113
+ moimoi.re
20089
20114
  mojastr.pl
20090
20115
  mojblogg.com
20091
20116
  mojewiki.com
@@ -20414,6 +20439,10 @@ mucincanon.com
20414
20439
  mudbox.ml
20415
20440
  muehlacker.tk
20416
20441
  muell.email
20442
+ muell.icu
20443
+ muell.monster
20444
+ muell.ru
20445
+ muell.xyz
20417
20446
  muellemail.com
20418
20447
  muellmail.com
20419
20448
  muellpost.de
@@ -22154,6 +22183,7 @@ ohmail.com
22154
22183
  ohtheprice.com
22155
22184
  ohxmail.com
22156
22185
  ohyesjysuis.fr
22186
+ oida.icu
22157
22187
  oidzc1zgxrktxdwdkxm.cf
22158
22188
  oidzc1zgxrktxdwdkxm.ga
22159
22189
  oidzc1zgxrktxdwdkxm.gq
@@ -22714,6 +22744,7 @@ oweiidfjjif.tk
22714
22744
  owemolexi.swiebodzin.pl
22715
22745
  owfcbxqhv.pl
22716
22746
  owh.ooo
22747
+ owleyes.ch
22717
22748
  owlpic.com
22718
22749
  owlymail.com
22719
22750
  own-tube.com
@@ -24591,6 +24622,7 @@ quintalaescondida.com
24591
24622
  quintania.top
24592
24623
  quitsmokinghelpfulguide.net
24593
24624
  quitsmokingmanyguides.net
24625
+ quossum.com
24594
24626
  ququb.com
24595
24627
  quuradminb.com
24596
24628
  quxppnmrn.pl
@@ -26124,6 +26156,7 @@ scannerchip.com
26124
26156
  scatmail.com
26125
26157
  scay.net
26126
26158
  scbox.one.pl
26159
+ schabernack.ru
26127
26160
  schachrol.com
26128
26161
  schackmail.com
26129
26162
  schafmail.de
@@ -26307,6 +26340,7 @@ segundamanozi.net
26307
26340
  seierra.com
26308
26341
  seishel-nedv.ru
26309
26342
  sejaa.lv
26343
+ sejkt.com
26310
26344
  sekcjajudo.pl
26311
26345
  sekoeuropa.pl
26312
26346
  selectam.ru
@@ -26744,6 +26778,7 @@ sify.com
26744
26778
  sign-up.website
26745
26779
  signaturefencecompany.com
26746
26780
  signings.ru
26781
+ sika3.com
26747
26782
  sikdar.site
26748
26783
  sikis18.org
26749
26784
  sikomo.cf
@@ -27632,6 +27667,7 @@ statusers.com
27632
27667
  statuspage.ga
27633
27668
  statx.ga
27634
27669
  stayfitforever.org
27670
+ stayhome.li
27635
27671
  stealbest.com
27636
27672
  stealthapps.org
27637
27673
  stealthypost.org
@@ -27880,6 +27916,7 @@ sumberkadalnya.com
27880
27916
  sumitra.ga
27881
27917
  sumitra.tk
27882
27918
  summerswimwear.info
27919
+ sumwan.com
27883
27920
  sunbuh.asia
27884
27921
  sunburning.ru
27885
27922
  sundaysuspense.space
@@ -28257,6 +28294,7 @@ tapchicuoihoi.com
28257
28294
  tapetoland.pl
28258
28295
  tapety-download.pl
28259
28296
  taphear.com
28297
+ tapi.re
28260
28298
  tapsitoaktl353t.ga
28261
28299
  tar00ih60tpt2h7.cf
28262
28300
  tar00ih60tpt2h7.ga
@@ -29162,6 +29200,7 @@ tomsshoesoutlet2u.com
29162
29200
  tomthen.org.ua
29163
29201
  tomymailpost.com
29164
29202
  tonermix.ru
29203
+ tonne.to
29165
29204
  tonngokhong.vn
29166
29205
  tonno.cf
29167
29206
  tonno.gq
@@ -29519,6 +29558,7 @@ tridalinbox.info
29519
29558
  triedbook.xyz
29520
29559
  trillianpro.com
29521
29560
  trimsj.com
29561
+ tripaco.com
29522
29562
  triparish.net
29523
29563
  tripolis.com
29524
29564
  tristanabestolaf.com
@@ -30315,6 +30355,7 @@ usamail.com
30315
30355
  usaonline.biz
30316
30356
  usapurse.com
30317
30357
  usareplicawatch.com
30358
+ usbc.be
30318
30359
  usbdirect.ca
30319
30360
  usbgadgetsusage.info
30320
30361
  usbmicrophone.org.uk
@@ -30738,6 +30779,7 @@ viagrawithoutadoctorprescription777.bid
30738
30779
  viajando.net
30739
30780
  viano.com
30740
30781
  viantakte.ru
30782
+ viatokyo.jp
30741
30783
  vibi4f1pc2xjk.cf
30742
30784
  vibi4f1pc2xjk.ga
30743
30785
  vibi4f1pc2xjk.gq
@@ -31026,7 +31068,6 @@ voyagebirmanie.net
31026
31068
  voyancegratuite10min.com
31027
31069
  voyeurseite.info
31028
31070
  vozmivtop.ru
31029
- vp.com
31030
31071
  vp.ycare.de
31031
31072
  vpanel.ru
31032
31073
  vpc608a0.pl
@@ -31064,6 +31105,7 @@ vpstrk.com
31064
31105
  vr5gpowerv.com
31065
31106
  vradportal.com
31066
31107
  vraskrutke.biz
31108
+ vreagles.com
31067
31109
  vreeland.agencja-csk.pl
31068
31110
  vreemail.com
31069
31111
  vremonte24-store.ru
@@ -31423,7 +31465,6 @@ webcontact-france.eu
31423
31465
  webcool.club
31424
31466
  webdesign-guide.info
31425
31467
  webdesign-romania.net
31426
- webdesignspecialist.com.au
31427
31468
  webdesigrsbio.gr
31428
31469
  webdespro.ru
31429
31470
  webdev-pro.ru
@@ -31539,6 +31580,7 @@ welleveningdress.net
31539
31580
  welleveningdresses.com
31540
31581
  welleveningdresses.net
31541
31582
  wellhungup.dynu.net
31583
+ wellick.ru
31542
31584
  wellnessintexas.info
31543
31585
  wellpromdresses.com
31544
31586
  wellpromdresses.net
@@ -31656,6 +31698,7 @@ wherenever.tk
31656
31698
  wheretoget-backlinks.com
31657
31699
  which-code.com
31658
31700
  whiffles.org
31701
+ whipjoy.com
31659
31702
  whiplashh.com
31660
31703
  whiskey.xray.ezbunko.top
31661
31704
  whiskeyalpha.webmailious.top
@@ -32328,6 +32371,7 @@ xdvsagsdg4we.ga
32328
32371
  xe2g.com
32329
32372
  xeames.net
32330
32373
  xeb9xwp7.tk
32374
+ xedmi.com
32331
32375
  xemaps.com
32332
32376
  xemne.com
32333
32377
  xenacareholdings.com
@@ -32378,6 +32422,7 @@ xhkss.net
32378
32422
  xijjfjoo.turystyka.pl
32379
32423
  xilopro.com
32380
32424
  xilor.com
32425
+ ximtyl.com
32381
32426
  xinbo.info
32382
32427
  xinbox.info
32383
32428
  xinfi.com.pl
@@ -32864,6 +32909,8 @@ yeamail.info
32864
32909
  yeastinfectionnomorenow.com
32865
32910
  yedi.org
32866
32911
  yeeeou.org.ua
32912
+ yeezus.ru
32913
+ yehudabx.com
32867
32914
  yejdnp45ie1to.cf
32868
32915
  yejdnp45ie1to.ga
32869
32916
  yejdnp45ie1to.gq
@@ -33101,6 +33148,7 @@ youtube2vimeo.info
33101
33148
  youveo.ch
33102
33149
  youwatchmovie.com
33103
33150
  youzend.net
33151
+ ype68.com
33104
33152
  ypmail.webarnak.fr.eu.org
33105
33153
  yppm0z5sjif.ga
33106
33154
  yppm0z5sjif.gq
@@ -33318,6 +33366,9 @@ zbtxx4iblkgp0qh.ga
33318
33366
  zbtxx4iblkgp0qh.gq
33319
33367
  zbtxx4iblkgp0qh.ml
33320
33368
  zbtxx4iblkgp0qh.tk
33369
+ zcai55.com
33370
+ zcai66.com
33371
+ zcai77.com
33321
33372
  zcash-cloud.com
33322
33373
  zchatz.ga
33323
33374
  zcqrgaogm.pl
@@ -33340,6 +33391,7 @@ zebra.email
33340
33391
  zebua.cf
33341
33392
  zebuaboy.cf
33342
33393
  zebuasadis.ml
33394
+ zefara.com
33343
33395
  zehnminuten.de
33344
33396
  zehnminutenmail.de
33345
33397
  zeinconsulting.info
@@ -33385,6 +33437,7 @@ zetfilmy.pl
33385
33437
  zetia.in
33386
33438
  zetmail.com
33387
33439
  zettransport.pl
33440
+ zevars.com
33388
33441
  zeveyuse.com
33389
33442
  zeveyuse.net
33390
33443
  zexeet9i5l49ocke.cf
data/lib/valid_email2.rb CHANGED
@@ -7,23 +7,35 @@ module ValidEmail2
7
7
  WHITELIST_FILE = "config/whitelisted_email_domains.yml"
8
8
  DISPOSABLE_FILE = File.expand_path('../config/disposable_email_domains.txt', __dir__)
9
9
 
10
- def self.disposable_emails
11
- @disposable_emails ||= File.open(DISPOSABLE_FILE){ |f| f.read }.split("\n")
12
- end
10
+ class << self
11
+ def disposable_emails
12
+ @disposable_emails ||= load_file(DISPOSABLE_FILE)
13
+ end
13
14
 
14
- def self.blacklist
15
- @blacklist ||= if File.exist?(BLACKLIST_FILE)
16
- YAML.load_file(File.expand_path(BLACKLIST_FILE))
17
- else
18
- []
19
- end
20
- end
15
+ def blacklist
16
+ @blacklist ||= load_if_exists(BLACKLIST_FILE)
17
+ end
18
+
19
+ def whitelist
20
+ @whitelist ||= load_if_exists(WHITELIST_FILE)
21
+ end
22
+
23
+ private
24
+
25
+ def load_if_exists(path)
26
+ File.exist?(path) ? load_file(path) : Set.new
27
+ end
21
28
 
22
- def self.whitelist
23
- @whitelist ||= if File.exist?(WHITELIST_FILE)
24
- YAML.load_file(File.expand_path(WHITELIST_FILE))
25
- else
26
- []
27
- end
29
+ def load_file(path)
30
+ # This method MUST return a Set, otherwise the
31
+ # performance will suffer!
32
+ if path.end_with?(".yml")
33
+ Set.new(YAML.load_file(path))
34
+ else
35
+ File.open(path, "r").each_line.each_with_object(Set.new) do |domain, set|
36
+ set << domain.tap(&:chomp!)
37
+ end
38
+ end
39
+ end
28
40
  end
29
41
  end
@@ -32,25 +32,22 @@ module ValidEmail2
32
32
  end
33
33
 
34
34
  def valid?
35
- @valid ||= begin
36
- return false if @parse_error
35
+ return @valid unless @valid.nil?
36
+ return false if @parse_error
37
37
 
38
+ @valid = begin
38
39
  if address.domain && address.address == @raw_address
39
40
  domain = address.domain
40
41
 
41
42
  domain !~ self.class.prohibited_domain_characters_regex &&
42
- # Domain needs to have at least one dot
43
- domain =~ /\./ &&
44
- # Domain may not have two consecutive dots
45
- domain !~ /\.{2,}/ &&
46
- # Domain may not start with a dot
47
- domain !~ /^\./ &&
48
- # Domain may not start with a dash
49
- domain !~ /^-/ &&
50
- # Domain name may not end with a dash
51
- domain !~ /-\./ &&
52
- # Address may not contain a dot directly before @
53
- address.address !~ /\.@/
43
+ domain.include?('.') &&
44
+ !domain.include?('..') &&
45
+ !domain.start_with?('.') &&
46
+ !domain.start_with?('-') &&
47
+ !domain.include?('-.') &&
48
+ !address.local.include?('..') &&
49
+ !address.local.end_with?('.') &&
50
+ !address.local.start_with?('.')
54
51
  else
55
52
  false
56
53
  end
@@ -70,7 +67,7 @@ module ValidEmail2
70
67
  end
71
68
 
72
69
  def disposable_domain?
73
- valid? && domain_is_in?(ValidEmail2.disposable_emails)
70
+ domain_is_in?(ValidEmail2.disposable_emails)
74
71
  end
75
72
 
76
73
  def disposable_mx_server?
@@ -88,6 +85,12 @@ module ValidEmail2
88
85
  def valid_mx?
89
86
  return false unless valid?
90
87
 
88
+ mx_or_a_servers.any?
89
+ end
90
+
91
+ def valid_strict_mx?
92
+ return false unless valid?
93
+
91
94
  mx_servers.any?
92
95
  end
93
96
 
@@ -122,7 +125,12 @@ module ValidEmail2
122
125
 
123
126
  def mx_servers
124
127
  @mx_servers ||= Resolv::DNS.open do |dns|
125
- mx_servers = dns.getresources(address.domain, Resolv::DNS::Resource::IN::MX)
128
+ dns.getresources(address.domain, Resolv::DNS::Resource::IN::MX)
129
+ end
130
+ end
131
+
132
+ def mx_or_a_servers
133
+ @mx_or_a_servers ||= Resolv::DNS.open do |dns|
126
134
  (mx_servers.any? && mx_servers) ||
127
135
  dns.getresources(address.domain, Resolv::DNS::Resource::IN::A)
128
136
  end
@@ -5,7 +5,7 @@ require "active_model/validations"
5
5
  module ValidEmail2
6
6
  class EmailValidator < ActiveModel::EachValidator
7
7
  def default_options
8
- { regex: true, disposable: false, mx: false, disallow_subaddressing: false, multiple: false }
8
+ { regex: true, disposable: false, mx: false, strict_mx: false, disallow_subaddressing: false, multiple: false }
9
9
  end
10
10
 
11
11
  def validate_each(record, attribute, value)
@@ -37,6 +37,10 @@ module ValidEmail2
37
37
  error(record, attribute) && return if addresses.any? { |address| address.disposable? && !address.whitelisted? }
38
38
  end
39
39
 
40
+ if options[:disposable_domain_with_whitelist]
41
+ error(record, attribute) && return if addresses.any? { |address| address.disposable_domain? && !address.whitelisted? }
42
+ end
43
+
40
44
  if options[:blacklist]
41
45
  error(record, attribute) && return if addresses.any?(&:blacklisted?)
42
46
  end
@@ -44,6 +48,10 @@ module ValidEmail2
44
48
  if options[:mx]
45
49
  error(record, attribute) && return unless addresses.all?(&:valid_mx?)
46
50
  end
51
+
52
+ if options[:strict_mx]
53
+ error(record, attribute) && return unless addresses.all?(&:valid_strict_mx?)
54
+ end
47
55
  end
48
56
 
49
57
  def error(record, attribute)
@@ -1,3 +1,3 @@
1
1
  module ValidEmail2
2
- VERSION = "3.3.0"
2
+ VERSION = "3.6.1"
3
3
  end
@@ -8,7 +8,7 @@ require "net/http"
8
8
  whitelisted_emails = %w(
9
9
  onet.pl poczta.onet.pl fastmail.fm hushmail.com
10
10
  hush.ai hush.com hushmail.me naver.com qq.com example.com
11
- yandex.net gmx.com gmx.es
11
+ yandex.net gmx.com gmx.es webdesignspecialist.com.au vp.com
12
12
  )
13
13
 
14
14
  existing_emails = File.open("config/disposable_email_domains.txt") { |f| f.read.split("\n") }
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ describe "Performance testing" do
6
+ let(:disposable_domain) { ValidEmail2.disposable_emails.first }
7
+
8
+ it "has acceptable lookup performance" do
9
+ address = ValidEmail2::Address.new("test@example.com")
10
+
11
+ # preload list and check size
12
+ expect(ValidEmail2.disposable_emails).to be_a(Set)
13
+ expect(ValidEmail2.disposable_emails.count).to be > 30000
14
+
15
+ # check lookup timing
16
+ expect { address.disposable_domain? }.to perform_under(0.0001).sample(10).times
17
+ end
18
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,15 @@
1
1
  $:.unshift File.expand_path("../lib",__FILE__)
2
2
  require "valid_email2"
3
3
 
4
+ # Include and configure benchmark
5
+ require 'rspec-benchmark'
6
+ RSpec.configure do |config|
7
+ config.include RSpec::Benchmark::Matchers
8
+ end
9
+ RSpec::Benchmark.configure do |config|
10
+ config.disable_gc = true
11
+ end
12
+
4
13
  class TestModel
5
14
  include ActiveModel::Validations
6
15
 
@@ -19,6 +19,10 @@ class TestUserMX < TestModel
19
19
  validates :email, 'valid_email_2/email': { mx: true }
20
20
  end
21
21
 
22
+ class TestUserStrictMX < TestModel
23
+ validates :email, 'valid_email_2/email': { strict_mx: true }
24
+ end
25
+
22
26
  class TestUserDisallowDisposable < TestModel
23
27
  validates :email, 'valid_email_2/email': { disposable: true }
24
28
  end
@@ -31,6 +35,10 @@ class TestUserDisallowDisposableWithWhitelist < TestModel
31
35
  validates :email, 'valid_email_2/email': { disposable_with_whitelist: true }
32
36
  end
33
37
 
38
+ class TestUserDisallowDisposableDomainWithWhitelist < TestModel
39
+ validates :email, 'valid_email_2/email': { disposable_domain_with_whitelist: true }
40
+ end
41
+
34
42
  class TestUserDisallowBlacklisted < TestModel
35
43
  validates :email, 'valid_email_2/email': { blacklist: true }
36
44
  end
@@ -87,13 +95,23 @@ describe ValidEmail2 do
87
95
  expect(user.valid?).to be_falsey
88
96
  end
89
97
 
90
- it "is invalid if the domain contains emoticons" do
91
- user = TestUser.new(email: "foo🙈@gmail.com")
92
- expect(user.valid?).to be_falsy
98
+ it "is invalid if the address contains consecutive dots" do
99
+ user = TestUser.new(email: "foo..bar@gmail.com")
100
+ expect(user.valid?).to be_falsey
101
+ end
102
+
103
+ it "is invalid if the address starts with a dot" do
104
+ user = TestUser.new(email: ".foo@bar.com")
105
+ expect(user.valid?).to be_falsey
93
106
  end
94
107
 
95
- it "is invalid if the domain contains .@ consecutively" do
96
- user = TestUser.new(email: "foo.@gmail.com")
108
+ it "is invalid if the local part of the address ends with a dot" do
109
+ user = TestUser.new(email: "foo.@bar.com")
110
+ expect(user.valid?).to be_falsey
111
+ end
112
+
113
+ it "is invalid if the email contains emoticons" do
114
+ user = TestUser.new(email: "foo🙈@gmail.com")
97
115
  expect(user.valid?).to be_falsy
98
116
  end
99
117
 
@@ -170,8 +188,18 @@ describe ValidEmail2 do
170
188
  let(:whitelist_domain) { disposable_domain }
171
189
  let(:whitelist_file_path) { "config/whitelisted_email_domains.yml" }
172
190
 
191
+ # Some of the specs below need to explictly set the whitelist var or it
192
+ # may be cached to an empty set
193
+ def set_whitelist
194
+ ValidEmail2.instance_variable_set(
195
+ :@whitelist,
196
+ ValidEmail2.send(:load_if_exists, ValidEmail2::WHITELIST_FILE)
197
+ )
198
+ end
199
+
173
200
  after do
174
201
  FileUtils.rm(whitelist_file_path, force: true)
202
+ set_whitelist
175
203
  end
176
204
 
177
205
  it "is invalid if the domain is disposable and not in the whitelist" do
@@ -181,9 +209,22 @@ describe ValidEmail2 do
181
209
 
182
210
  it "is valid if the domain is disposable but in the whitelist" do
183
211
  File.open(whitelist_file_path, "w") { |f| f.write [whitelist_domain].to_yaml }
212
+ set_whitelist
184
213
  user = TestUserDisallowDisposableWithWhitelist.new(email: "foo@#{whitelist_domain}")
214
+ expect(user.valid?).to be_truthy
215
+ end
216
+
217
+ it "is invalid if the domain is a disposable_domain and not in the whitelist" do
218
+ user = TestUserDisallowDisposableDomainWithWhitelist.new(email: "foo@#{whitelist_domain}")
185
219
  expect(user.valid?).to be_falsey
186
220
  end
221
+
222
+ it "is valid if the domain is a disposable_domain but in the whitelist" do
223
+ File.open(whitelist_file_path, "w") { |f| f.write [whitelist_domain].to_yaml }
224
+ set_whitelist
225
+ user = TestUserDisallowDisposableDomainWithWhitelist.new(email: "foo@#{whitelist_domain}")
226
+ expect(user.valid?).to be_truthy
227
+ end
187
228
  end
188
229
  end
189
230
 
@@ -216,6 +257,23 @@ describe ValidEmail2 do
216
257
  end
217
258
  end
218
259
 
260
+ describe "with strict mx validation" do
261
+ it "is valid if mx records are found" do
262
+ user = TestUserStrictMX.new(email: "foo@gmail.com")
263
+ expect(user.valid?).to be_truthy
264
+ end
265
+
266
+ it "is invalid if A records are found but no mx records are found" do
267
+ user = TestUserStrictMX.new(email: "foo@ghs.google.com")
268
+ expect(user.valid?).to be_falsey
269
+ end
270
+
271
+ it "is invalid if no mx records are found" do
272
+ user = TestUserStrictMX.new(email: "foo@subdomain.gmail.com")
273
+ expect(user.valid?).to be_falsey
274
+ end
275
+ end
276
+
219
277
  describe "with dotted validation" do
220
278
  it "is valid when address does not contain dots" do
221
279
  user = TestUserDotted.new(email: "johndoe@gmail.com")
data/valid_email2.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 2.0"
24
24
  spec.add_development_dependency "rake", "~> 12.3.3"
25
25
  spec.add_development_dependency "rspec", "~> 3.5.0"
26
+ spec.add_development_dependency "rspec-benchmark", "~> 0.6"
26
27
  spec.add_development_dependency "pry"
27
28
  spec.add_runtime_dependency "mail", "~> 2.5"
28
29
  spec.add_runtime_dependency "activemodel", ">= 3.2"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valid_email2
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micke Lisinge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-07 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-benchmark
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.6'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: pry
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -120,6 +134,7 @@ files:
120
134
  - lib/valid_email2/email_validator.rb
121
135
  - lib/valid_email2/version.rb
122
136
  - pull_mailchecker_emails.rb
137
+ - spec/benchmark_spec.rb
123
138
  - spec/spec_helper.rb
124
139
  - spec/valid_email2_spec.rb
125
140
  - valid_email2.gemspec
@@ -142,11 +157,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
157
  - !ruby/object:Gem::Version
143
158
  version: '0'
144
159
  requirements: []
145
- rubygems_version: 3.1.2
160
+ rubygems_version: 3.2.3
146
161
  signing_key:
147
162
  specification_version: 4
148
163
  summary: ActiveModel validation for email. Including MX lookup and disposable email
149
164
  blacklist
150
165
  test_files:
166
+ - spec/benchmark_spec.rb
151
167
  - spec/spec_helper.rb
152
168
  - spec/valid_email2_spec.rb