emails: mark all invalid emails as undeliverable.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require_relative "../../config/environment"
|
require_relative "base"
|
||||||
|
|
||||||
def fix(email, regex, replacement)
|
def fix(email, regex, replacement)
|
||||||
email.update!(address: email.address.gsub(regex, replacement))
|
email.update!(address: email.address.gsub(regex, replacement))
|
||||||
@@ -10,7 +10,7 @@ rescue StandardError => e
|
|||||||
email.reload.update_attribute(:is_deliverable, false)
|
email.reload.update_attribute(:is_deliverable, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
EmailAddress.transaction do
|
with_confirmation do
|
||||||
# `foo@gmail.com `
|
# `foo@gmail.com `
|
||||||
EmailAddress.where("address ~ '[[:space:]]'").find_each do |email|
|
EmailAddress.where("address ~ '[[:space:]]'").find_each do |email|
|
||||||
fix(email, /[[:space:]]/, "")
|
fix(email, /[[:space:]]/, "")
|
||||||
@@ -76,16 +76,24 @@ EmailAddress.transaction do
|
|||||||
fix(email, /@g[^m]ail\.com$/, "@gmail.com")
|
fix(email, /@g[^m]ail\.com$/, "@gmail.com")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# foo@gamil.com
|
||||||
|
EmailAddress.where("address ~ '@gamil\\.com$'").find_each do |email|
|
||||||
|
fix(email, /@gamil\.com$/, "@gmail.com")
|
||||||
|
end
|
||||||
|
|
||||||
# foo@gmai;.com
|
# foo@gmai;.com
|
||||||
EmailAddress.where("address ~ '@gmai[^l]\\.com$'").find_each do |email|
|
EmailAddress.where("address ~ '@gmai[^l]\\.com$'").find_each do |email|
|
||||||
fix(email, /@gmai[^l]\.com$/, "@gmail.com")
|
fix(email, /@gmai[^l]\.com$/, "@gmail.com")
|
||||||
end
|
end
|
||||||
|
|
||||||
# foo@gmail@com
|
# foo@gmail@com
|
||||||
EmailAddress.where("address ~ 'gmail[^.]com$'").find_each do |email|
|
EmailAddress.where("address ~ '@gmail[^.]com$'").find_each do |email|
|
||||||
fix(email, /gmail[^.]com$/, "@gmail.com")
|
fix(email, /@gmail[^.]com$/, "@gmail.com")
|
||||||
end
|
end
|
||||||
|
|
||||||
print "Commit? (yes/no): "
|
# Mark all other invalid emails as undeliverable.
|
||||||
raise "abort" unless STDIN.readline.chomp == "yes"
|
EmailAddress.where(is_deliverable: true).where("address !~ '^[a-zA-Z0-9._%+-]+@([a-zA-Z0-9][a-zA-Z0-9-]{0,61}\\.)+[a-zA-Z]{2,}$'").find_each do |email|
|
||||||
|
email.update_attribute(:is_deliverable, false)
|
||||||
|
puts ({ address: email.address, is_deliverable: false }).to_json
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user