Sha256: 3bebf1614726dcf655b8afe48fed378a5a20bde434993246ce60e927abfc9f83

Contents?: true

Size: 709 Bytes

Versions: 8

Compression:

Stored size: 709 Bytes

Contents

require 'mail'

class FakeEmailService

  def initialize
    fake_domains_file = File.expand_path('../../config/fake_domains.list', __FILE__)
    @fake_domains = File.readlines(fake_domains_file).map {|fd| fd.strip.downcase }
  end

  def is_fake_email?(email)
    return false if email.blank?

    email_address = Mail::Address.new(email)

    domain = email_address.domain.strip.downcase
    domain_parts = domain.split('.')

    second_level_domain = Array(domain_parts[-2..-1]).join('.')
    third_level_domain = Array(domain_parts[-3..-1]).join('.')

    domains = [domain, second_level_domain, third_level_domain].compact

    @fake_domains.any? {|fake_domain| domains.include?(fake_domain) }
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fake_email_validator-1.0.11 lib/fake_email_service.rb
fake_email_validator-1.0.10 lib/fake_email_service.rb
fake_email_validator-1.0.9 lib/fake_email_service.rb
fake_email_validator-1.0.8 lib/fake_email_service.rb
fake_email_validator-1.0.7 lib/fake_email_service.rb
fake_email_validator-1.0.6 lib/fake_email_service.rb
fake_email_validator-1.0.5 lib/fake_email_service.rb
fake_email_validator-1.0.4 lib/fake_email_service.rb