mail_provider 0.1.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.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +8 -0
  7. data/Gemfile.lock +57 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +189 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +12 -0
  12. data/bin/setup +8 -0
  13. data/exe/mail_provider +3 -0
  14. data/lib/mail_provider.rb +27 -0
  15. data/lib/mail_provider/checker.rb +125 -0
  16. data/lib/mail_provider/parser.rb +79 -0
  17. data/lib/mail_provider/source_manager.rb +62 -0
  18. data/lib/mail_provider/trie.rb +72 -0
  19. data/lib/mail_provider/version.rb +5 -0
  20. data/mail_provider.gemspec +45 -0
  21. data/sources.txt +30 -0
  22. data/sources/.keep +0 -0
  23. data/sources/043636d177df6ba4a9696eb533d16eef.txt +33606 -0
  24. data/sources/13ab1c1f07b9ed12a1062a6bca9a47f4.txt +9682 -0
  25. data/sources/19d002b95a99dd4ba2c9af295de9e071.txt +10115 -0
  26. data/sources/19e9c711dc3bee047f9768a526c695a3.txt +4712 -0
  27. data/sources/1ed7857e53682af03df29472e967561c.txt +3782 -0
  28. data/sources/1ffaf80824e9464ec7ee98a486e9b283.txt +362 -0
  29. data/sources/2c1922626bb0cc983ead0c0531c1bee0.txt +8996 -0
  30. data/sources/308df6ebc233c9b9504f8695ea0938ef.txt +2363 -0
  31. data/sources/32c4dab7d1f64090a12b67206df13c63.txt +479 -0
  32. data/sources/4e961ee40142e15ed478f740e2e05282.txt +2690 -0
  33. data/sources/521e388aae7d452633b3991cdb1abaa7.txt +1 -0
  34. data/sources/6293ee4948a9bbe2f5393745ed738efd.txt +21370 -0
  35. data/sources/697e30f7fc05e36c1c5dbf29938e5a7f.txt +8755 -0
  36. data/sources/6b628e4280569161a63a0ed8539c0ce2.txt +3704 -0
  37. data/sources/6ee58e4ec75489f5e9c9a2c7b6ed56e6.txt +909 -0
  38. data/sources/7d8441b6667aaf67f1d27f232f5e43c4.txt +2678 -0
  39. data/sources/84732266f595320cd802cdfab1c895e8.txt +56871 -0
  40. data/sources/8713f85918d232a398b2f7da6b269477.txt +172 -0
  41. data/sources/92e407c80b7c81f86f6392360dc479e9.txt +3782 -0
  42. data/sources/a4b510b096e0982a5d58cccdaea8d596.txt +59122 -0
  43. data/sources/a4d0a6e29ad6a37d02d2b937c4d75463.txt +550 -0
  44. data/sources/b4e996388c8724ddbe44ef5428ef7e07.txt +3111 -0
  45. data/sources/bad7ffe3d51bf569a6391469b4f8b8a4.txt +4731 -0
  46. data/sources/bbabdd56126bff708cc6ac547d2d82a1.txt +7939 -0
  47. data/sources/d8aee4766bf26e7c23b40b8190804551.txt +350 -0
  48. data/sources/db83ce35bc49f1758fdbe945b064edc4.txt +934 -0
  49. data/sources/dcdb35ac9e518de66b95857d7939071a.txt +72815 -0
  50. data/sources/disposable.dump +0 -0
  51. data/sources/e6a7f3c654acd6026bce04f69fcde954.txt +4208 -0
  52. data/sources/f61e90130c5c4fb5feb4ebd49dd8c4c0.txt +844 -0
  53. data/sources/fddf00cb67a0d40e2e4b7ad9526620be.txt +225 -0
  54. data/sources/free.dump +0 -0
  55. metadata +218 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 65153d0d8c51a101d9bd30db8dd53452204352aa911d6659742aba98d0aaa215
4
+ data.tar.gz: 85d3cddf27da2dff07306c73fd1e91e2ee1a938260e0cf501244b0411dc6955e
5
+ SHA512:
6
+ metadata.gz: 3f090082e9cd85a945c7faa6101645a1015aae1f8431e54bc29ec1f05d5196e33c94b65c4616f285fffc3dbd00074024d444d49cbbb599b149e76a5204cd4052
7
+ data.tar.gz: 519846a9830c2ab308c73fcff621771749d57c58c66818f5832b07f7eb6ee66a09edba363d6f83206943c135ff71340eba8cda8e579be4ee37392e9ed24b3469
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at me@nikhgupta.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in mail_provider.gemspec
8
+ gemspec
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mail_provider (0.1.0)
5
+ faraday
6
+ hamster
7
+ public_suffix
8
+ simpleidn
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ coderay (1.1.2)
14
+ concurrent-ruby (1.1.6)
15
+ diff-lcs (1.3)
16
+ faraday (1.0.0)
17
+ multipart-post (>= 1.2, < 3)
18
+ hamster (3.0.0)
19
+ concurrent-ruby (~> 1.0)
20
+ method_source (1.0.0)
21
+ multipart-post (2.1.1)
22
+ pry (0.13.0)
23
+ coderay (~> 1.1)
24
+ method_source (~> 1.0)
25
+ public_suffix (4.0.3)
26
+ rake (13.0.1)
27
+ rspec (3.9.0)
28
+ rspec-core (~> 3.9.0)
29
+ rspec-expectations (~> 3.9.0)
30
+ rspec-mocks (~> 3.9.0)
31
+ rspec-core (3.9.1)
32
+ rspec-support (~> 3.9.1)
33
+ rspec-expectations (3.9.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.9.0)
36
+ rspec-mocks (3.9.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.9.0)
39
+ rspec-support (3.9.2)
40
+ simpleidn (0.1.1)
41
+ unf (~> 0.1.4)
42
+ unf (0.1.4)
43
+ unf_ext
44
+ unf_ext (0.0.7.6)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ bundler (~> 1.17)
51
+ mail_provider!
52
+ pry
53
+ rake (>= 12.3.3)
54
+ rspec (~> 3.0)
55
+
56
+ BUNDLED WITH
57
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 nikhgupta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,189 @@
1
+ # MailProvider
2
+
3
+ Smartly check whether a given email/domain belongs to a free or disposable
4
+ mail provider.
5
+
6
+ There are hundreds of lists available in Github repositories or Gists that
7
+ list various free and disposable email providers. This gem downloads a bunch
8
+ of these scripts (pre-configured URLs) and parses them to count votes against
9
+ each domain in the list. We, then, create a Trie structure to efficiently
10
+ query this data with a given domain or email. For each query, you get back a
11
+ number specifying how many sources are claiming that the domain is a free or
12
+ disposable email provider.
13
+
14
+ **This gem was written in a couple of hours, and the intention has been to
15
+ get this working first for a project I am working on. This gem still needs
16
+ refactoring to make the code more readable, tests, etc. PRs welcome :)**
17
+
18
+ ## Features
19
+
20
+ - IDN/Punycode compatibility
21
+ - should be thread-safe - immutable Trie structure.
22
+ - really fast! Uses efficient Patricia Trie structure.
23
+ - checks all parts of subdomain for checking an entry
24
+ - provide your own sources for disposable/free domains list
25
+ - 74000+ disposable domains, 9000+ free domains pre-configured
26
+ - check email/domain for free or disposable email provider status
27
+
28
+ ## Installation
29
+
30
+ Add this line to your application's Gemfile:
31
+
32
+ ```ruby
33
+ gem 'mail_provider'
34
+ ```
35
+
36
+ And then execute:
37
+
38
+ ```bash
39
+ bundle
40
+ ```
41
+
42
+ Or install it yourself as:
43
+
44
+ ```bash
45
+ gem install mail_provider
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ In simple terms, you can do:
51
+
52
+ ```ruby
53
+ # Re-download and update list of domains from sources
54
+ lib = MailProvider.new(refresh: true)
55
+
56
+ # Re-use cached/parsed list from the CSV in data-directory
57
+ lib = MailProvider.new(refresh: false)
58
+
59
+ # check an email for status
60
+ lib.check 'example@c.nut.emailfake.nut.cc'
61
+ # => {:ascii=>"c.nut.emailfake.nut.cc",
62
+ # :found=>3,
63
+ # :unicode=>"c.nut.emailfake.nut.cc",
64
+ # :domain=>"nut.cc",
65
+ # :tld=>"cc",
66
+ # :match=>:entry,
67
+ # :summarize=>false,
68
+ # :free=>1,
69
+ # :disposable=>3,
70
+ # :score=>-0.0625,
71
+ # :data=>{"c.nut.emailfake.nut.cc"=>{:free=>1, :disposable=>3},
72
+ # "emailfake.nut.cc"=>{:free=>0, :disposable=>6},
73
+ # "nut.cc"=>{:free=>1, :disposable=>10}},
74
+
75
+ lib.check "финские-вейдерсы-2019.рф"
76
+ # => {:ascii=>"xn----2019-iofqgcb4aasj1c8cik0c5k.xn--p1ai",
77
+ # :found=>1,
78
+ # :unicode=>"финские-вейдерсы-2019.рф",
79
+ # :domain=>"финские-вейдерсы-2019.рф",
80
+ # :tld=>"рф",
81
+ # :data=>{"xn----2019-iofqgcb4aasj1c8cik0c5k.xn--p1ai"=>{:free=>0, :disposable=>1}},
82
+ # :match=>:entry,
83
+ # :score=>-0.0625,
84
+ # :free=>0,
85
+ # :disposable=>1}
86
+
87
+ # check an email for status while summing up scores for each step in domain
88
+ lib.check 'c.nut.emailfake.nut.cc', summarize: true
89
+ # => {:ascii=>"c.nut.emailfake.nut.cc",
90
+ # :found=>3,
91
+ # :unicode=>"c.nut.emailfake.nut.cc",
92
+ # :domain=>"nut.cc",
93
+ # :tld=>"cc",
94
+ # :match=>:entry,
95
+ # :summarize=>true,
96
+ # :free=>2,
97
+ # :disposable=>19,
98
+ # :score=>-0.9375,
99
+ # :data=>{"c.nut.emailfake.nut.cc"=>{:free=>1, :disposable=>3},
100
+ # "emailfake.nut.cc"=>{:free=>0, :disposable=>6},
101
+ # "nut.cc"=>{:free=>1, :disposable=>10}},
102
+
103
+ # check a domain for status
104
+ lib.check 'gmail.com'
105
+ # => {:ascii=>"gmail.com", :summarize=>false, :checked=>1, :found=>true, :unicode=>"gmail.com",
106
+ # :score=>1.0,:free=>8, :disposable=>0, :data=>{"gmail.com"=>{:free=>8, :disposable=>0}}}
107
+
108
+ lib.check 'nick@codewithsense.com'
109
+ # => {:ascii=>"codewithsense.com", :found=>0, :unicode=>"codewithsense.com",
110
+ # :domain=>"codewithsense.com", :tld=>"com", :data=>{}, :match=>nil,
111
+ # :summarize=>false, :score=>nil}
112
+ ```
113
+
114
+ ## Explaination
115
+
116
+ In the above examples, `free` is the number of sources claiming that the
117
+ given domain/email is from a free email provider, `disposable` is the number
118
+ of sources claiming that the given domain/email is from a disposable email
119
+ provider.
120
+
121
+ `checked` is the number of domain parts checked for this email/domain for
122
+ entries present with us. For example, for domain `subsub.sub.root.co.in`, we
123
+ check the following strings in our records (giving us a total of 3):
124
+
125
+ - subsub.sub.root.co.in
126
+ - sub.root.co.in
127
+ - root.co.in
128
+
129
+ If `summarize` is `true`, counts for each domain parts are added starting
130
+ from root domain.
131
+
132
+ `score` is the percent of sources claiming the string to be a free provider
133
+ minus the percent of sources claiming the string to be a disposable provider.
134
+ This value is `nil` if the string is not found in our entries, otherwise a
135
+ value between `-1` and `1`.
136
+
137
+ ## Custom sources
138
+
139
+ The above uses pre-configured list of sources. To use your own list of
140
+ sources, provide a file with one (url) line per source.
141
+
142
+ We check the lists for inclusion of `gmail.com` and `mailinator.com` and
143
+ other similar domains to decide what kind of emails they list. To improve
144
+ efficiency, only provide sources that list EITHER free OR disposable emails,
145
+ and not both.
146
+
147
+ Afterwards, you can do:
148
+
149
+ ```ruby
150
+ MailProvider.new(sources: "<path-to-file>", refresh: true)
151
+ ```
152
+
153
+ The gem saves the download and parsed list as a CSV in the gem's directory.
154
+ You can, optionally, provide a directory to save the parsed list in.
155
+
156
+ ```ruby
157
+ MailProvider.new(data_directory: "<path-to-directory>")
158
+ ```
159
+
160
+ ## Development
161
+
162
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
163
+ run `rake spec` to run the tests. You can also run `bin/console` for an
164
+ interactive prompt that will allow you to experiment.
165
+
166
+ To install this gem onto your local machine, run `bundle exec rake install`.
167
+ To release a new version, update the version number in `version.rb`, and then
168
+ run `bundle exec rake release`, which will create a git tag for the version,
169
+ push git commits and tags, and push the `.gem` file to
170
+ [rubygems.org](https://rubygems.org).
171
+
172
+ ## Contributing
173
+
174
+ Bug reports and pull requests are welcome on GitHub at
175
+ https://github.com/nikhgupta/mail_provider. This project is intended to be a
176
+ safe, welcoming space for collaboration, and contributors are expected to
177
+ adhere to the [Contributor Covenant](http://contributor-covenant.org) code of
178
+ conduct.
179
+
180
+ ## License
181
+
182
+ The gem is available as open source under the terms of the
183
+ [MIT License](https://opensource.org/licenses/MIT).
184
+
185
+ ## Code of Conduct
186
+
187
+ Everyone interacting in the MailProvider project’s codebases, issue trackers,
188
+ chat rooms and mailing lists is expected to follow the
189
+ [code of conduct](https://github.com/nikhgupta/mail_provider/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'pry'
6
+ require 'mail_provider'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "mail_provider"
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailProvider
4
+ ROOT_DIR = File.dirname(File.dirname(__FILE__))
5
+
6
+ class Error < StandardError; end
7
+ class TrieLoadError < StandardError; end
8
+ end
9
+
10
+ require 'faraday'
11
+ require 'simpleidn'
12
+ require 'digest/md5'
13
+ require 'hamster/trie'
14
+ require 'public_suffix'
15
+
16
+ require 'mail_provider/version'
17
+ require 'mail_provider/trie'
18
+ require 'mail_provider/parser'
19
+ require 'mail_provider/source_manager'
20
+ require 'mail_provider/checker'
21
+
22
+ module MailProvider
23
+ def self.new(refresh: false, sources: nil, data_directory: nil)
24
+ checker = MailProvider::Checker.new sources, data_directory
25
+ checker.setup refresh: refresh
26
+ end
27
+ end