Sha256: 886cf712ac474a4cc0e6a3e3a40c5a66a4474bd72ffb9b9a678b7b61b61c1556

Contents?: true

Size: 1.53 KB

Versions: 349

Compression:

Stored size: 1.53 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative "helpers"
require "resolv"

output_path = "#{__dir__}/../data/disposable_domains_without_mx.txt"
File.unlink(output_path) if File.file?(output_path)

domains = normalize_list(File.read("#{__dir__}/../data/disposable_domains.txt").lines)

def has_mx?(domain, remaining_retries = 3)
  Resolv::DNS.open do |dns|
    dns.timeouts = 1
    resources = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
    return resources.any?
  end
rescue ResolvTimeout
  return has_mx?(domain, remaining_retries - 1) if remaining_retries.positive?

  # No MX, after 3 timed out attempts.
  false
end

started = Time.now.to_i

total = domains.size
how_many = 150
processed = 0
domains_without_mx = []

puts "=> Breaking disposable domains into separate lists"

domains.each_slice(how_many) do |slice|
  threads = slice.map do |domain|
    Thread.new do
      domains_without_mx << domain unless has_mx?(domain)
    end
  end

  threads.each(&:join)

  processed += slice.size
  now = Time.now.to_i

  File.open(output_path, "a") do |file|
    file << domains_without_mx.join("\n")
    file << "\n" if domains_without_mx.any?
  end

  domains_without_mx = []
  print "\r   Elapsed: #{now - started}s (#{processed} out of #{total} - #{((processed.to_f / total) * 100).round(2)}%)"
end

domains_without_mx = normalize_list(File.read(output_path).lines)
domains_with_mx = domains - domains_without_mx

File.open("#{__dir__}/../data/disposable_domains_with_mx.txt", "w") do |file|
  file << domains_with_mx.join("\n")
end

Version data entries

349 entries across 349 versions & 1 rubygems

Version Path
email_data-1732408289.0.0 bin/filter-disposable-domains-without-mx
email_data-1731803456.0.0 bin/filter-disposable-domains-without-mx
email_data-1731198561.0.0 bin/filter-disposable-domains-without-mx
email_data-1730593788.0.0 bin/filter-disposable-domains-without-mx
email_data-1729988998.0.0 bin/filter-disposable-domains-without-mx
email_data-1729384188.0.0 bin/filter-disposable-domains-without-mx
email_data-1728779363.0.0 bin/filter-disposable-domains-without-mx
email_data-1727569771.0.0 bin/filter-disposable-domains-without-mx
email_data-1726964969.0.0 bin/filter-disposable-domains-without-mx
email_data-1726360142.0.0 bin/filter-disposable-domains-without-mx
email_data-1725755331.0.0 bin/filter-disposable-domains-without-mx
email_data-1725150571.0.0 bin/filter-disposable-domains-without-mx
email_data-1724545699.0.0 bin/filter-disposable-domains-without-mx
email_data-1723940909.0.0 bin/filter-disposable-domains-without-mx
email_data-1723336353.0.0 bin/filter-disposable-domains-without-mx
email_data-1722731292.0.0 bin/filter-disposable-domains-without-mx
email_data-1722126507.0.0 bin/filter-disposable-domains-without-mx
email_data-1721521719.0.0 bin/filter-disposable-domains-without-mx
email_data-1720916916.0.0 bin/filter-disposable-domains-without-mx
email_data-1720312106.0.0 bin/filter-disposable-domains-without-mx