Skip to content

Commit

Permalink
feat!: Remove deprecated methods and options
Browse files Browse the repository at this point in the history
  • Loading branch information
micke committed Aug 31, 2024
1 parent fc30094 commit 1a29d27
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 54 deletions.
14 changes: 0 additions & 14 deletions lib/helpers/deprecation_helper.rb

This file was deleted.

23 changes: 2 additions & 21 deletions lib/valid_email2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
require_relative "./helpers/deprecation_helper"

module ValidEmail2

BLACKLIST_FILE = "config/blacklisted_email_domains.yml"
DENY_LIST_FILE = "config/deny_listed_email_domains.yml"
WHITELIST_FILE = "config/whitelisted_email_domains.yml"
ALLOW_LIST_FILE = "config/allow_listed_email_domains.yml"
DISPOSABLE_FILE = File.expand_path('../config/disposable_email_domains.txt', __dir__)

Expand All @@ -19,35 +16,19 @@ def disposable_emails
end

def deny_list
@deny_list ||= load_if_exists(DENY_LIST_FILE) ||
load_deprecated_if_exists(BLACKLIST_FILE) ||
Set.new
@deny_list ||= load_if_exists(DENY_LIST_FILE) || Set.new
end
deprecate_method :blacklist, :deny_list

def allow_list
@allow_list ||= load_if_exists(ALLOW_LIST_FILE) ||
load_deprecated_if_exists(WHITELIST_FILE) ||
Set.new
@allow_list ||= load_if_exists(ALLOW_LIST_FILE) || Set.new
end
deprecate_method :whitelist, :allow_list

private

def load_if_exists(path)
load_file(path) if File.exist?(path)
end

def load_deprecated_if_exists(path)
if File.exist?(path)
warn <<~WARN
Warning: The file `#{path}` used by valid_email2 is deprecated and won't be read in version 6 of valid_email2;
Rename the file to `#{path.gsub("blacklisted", "deny_listed").gsub("whitelisted", "allow_listed")}` instead."
WARN
load_file(path)
end
end

def load_file(path)
# This method MUST return a Set, otherwise the
# performance will suffer!
Expand Down
2 changes: 0 additions & 2 deletions lib/valid_email2/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ def disposable_mx_server?
def allow_listed?
domain_is_in?(ValidEmail2.allow_list)
end
deprecate_method :whitelisted?, :allow_listed?

def deny_listed?
valid? && domain_is_in?(ValidEmail2.deny_list)
end
deprecate_method :blacklisted?, :deny_listed?

def valid_mx?
return false unless valid?
Expand Down
18 changes: 3 additions & 15 deletions lib/valid_email2/email_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,15 @@ def validate_each(record, attribute, value)
error(record, attribute) && return if addresses.any?(&:disposable_domain?)
end

if options[:disposable_with_whitelist]
deprecation_message(:disposable_with_whitelist, :disposable_with_allow_list)
end

if options[:disposable_with_allow_list] || options[:disposable_with_whitelist]
if options[:disposable_with_allow_list]
error(record, attribute) && return if addresses.any? { |address| address.disposable? && !address.allow_listed? }
end

if options[:disposable_domain_with_whitelist]
deprecation_message(:disposable_domain_with_whitelist, :disposable_domain_with_allow_list)
end

if options[:disposable_domain_with_allow_list] || options[:disposable_domain_with_whitelist]
if options[:disposable_domain_with_allow_list]
error(record, attribute) && return if addresses.any? { |address| address.disposable_domain? && !address.allow_listed? }
end

if options[:blacklist]
deprecation_message(:blacklist, :deny_list)
end

if options[:deny_list] || options[:blacklist]
if options[:deny_list]
error(record, attribute) && return if addresses.any?(&:deny_listed?)
end

Expand Down
4 changes: 2 additions & 2 deletions pull_mailchecker_emails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require "json"
require "net/http"

whitelisted_emails = %w[
allow_listed_emails = %w[
onet.pl poczta.onet.pl fastmail.fm hushmail.com
hush.ai hush.com hushmail.me naver.com qq.com example.com
yandex.net gmx.com gmx.es webdesignspecialist.com.au vp.com
Expand All @@ -29,6 +29,6 @@
resp.body.split("\n").flatten
end

result_emails = (existing_emails + remote_emails).map(&:strip).uniq.sort - whitelisted_emails
result_emails = (existing_emails + remote_emails).map(&:strip).uniq.sort - allow_listed_emails

File.write("config/disposable_email_domains.txt", result_emails.join("\n"))

0 comments on commit 1a29d27

Please sign in to comment.